Browse Source

working path on ReadString

adaptedStrategy0
Andrea Bellandi 9 years ago
parent
commit
14ea77dbf7
2 changed files with 13 additions and 15 deletions
  1. +2
    -3
      src/ReadString.hs
  2. +11
    -12
      src/SinglePasses.hs

+ 2
- 3
src/ReadString.hs View File

@ -25,15 +25,14 @@ main = do args <- getArgs
seedn <- return $ optSeedNumber opt
(id, seedgame) <- return $ readInput file
(seed,game) <- return $ unzip seedgame
commintermediate <- return $ propagateCommand (game !! seedn) phrase
outputs <- return $ passes commintermediate
outputs <- return $ passes $ propagateCommand (game !! seedn) phrase
BS.putStrLn $ encode outputs
propagateCommand :: DT.Game -> String -> [(DT.Game, VM.Notes)]
propagateCommand game str = (game,VM.OK):(propagateCommand0 game str)
where
propagateCommand0 game0 [] = []
propagateCommand0 game0 (c:cs) = res1:(propagateCommand game1 cs)
propagateCommand0 game0 (c:cs) = res1:(propagateCommand0 game1 cs)
where
res1@(game1,note1) = VM.step game0 (fromJust $ charToCommand c)


+ 11
- 12
src/SinglePasses.hs View File

@ -37,32 +37,31 @@ passes gamesnotes = map generateoutput (gameswithtouched gamesnotes)
generateoutput ((game,note),touched) = Output { width = DT.width $ DT.board game,
height = DT.height $ DT.board game,
filled = filledcells game,
touched = touchedcells touched,
touched = extractcell touched,
unit = unitcells game,
score = DT.score game
}
filledcells gm = extractcell $ DT.filled $ DT.board gm
filledcells gm = extractcell $ DT.filled $ DT.board gm
unitcells gm = if null $ DT.units gm
then []
else extractunit $ head $ DT.units gm
touchedcells tc = extractcell tc
gameswithtouched :: [(DT.Game,VM.Notes)] -> [((DT.Game,VM.Notes),Set DT.Cell)]
gameswithtouched [] = []
gameswithtouched (x:[]) = [(x,Data.Set.empty)]
gameswithtouched (x:xs) = (x,touched):lastels
gameswithtouched els = gameswithtouched0 els Data.Set.empty
gameswithtouched0 :: [(DT.Game,VM.Notes)] -> Set DT.Cell -> [((DT.Game,VM.Notes),Set DT.Cell)]
gameswithtouched0 [] acc = []
gameswithtouched0 (x:[]) acc = [(x,acc)]
gameswithtouched0 (x:xs) acc = (x,touched):lastels
where
touched1 = snd $ head lastels
touched2 = if null $ DT.units $ fst $ fst $ head lastels
then Data.Set.empty
else DT.members $ head $ DT.units $ fst $ fst $ head lastels
touched = difference (difference (union touched1 touched2) cells) units
touched = (difference (difference acc cells) units)
cells = DT.filled $ DT.board $ fst x
units = if null $ DT.units $ fst x
then Data.Set.empty
else DT.members $ head $ DT.units $ fst x
touchedcells tc = extractcell touched
lastels = gameswithtouched xs
lastels = gameswithtouched0 xs (union touched units)
extractunit :: DT.Unit -> [Cell]
extractunit unit = extractcell $ DT.members unit


Loading…
Cancel
Save