Browse Source

main aggiornato con loutput del cimbi <3

adaptedStrategy0
Andrea Bellandi 9 years ago
parent
commit
d0498e413b
3 changed files with 27 additions and 13 deletions
  1. +1
    -1
      icfp2015.cabal
  2. +11
    -2
      src/Main0.hs
  3. +15
    -10
      src/Strategy0.hs

+ 1
- 1
icfp2015.cabal View File

@ -60,7 +60,7 @@ executable icfp2015
other-extensions: OverloadedStrings, DeriveGeneric, DeriveDataTypeable other-extensions: OverloadedStrings, DeriveGeneric, DeriveDataTypeable
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base >=4.7 && <4.8, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.8, bytestring >=0.10 && <0.11, aeson >=0.8 && <0.9, json >=0.9 && <0.10
build-depends: base >=4.6 && <4.9, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.9, bytestring >=0.10 && <0.11, aeson >=0.8 && <0.9, json >=0.9 && <0.10
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: src hs-source-dirs: src


+ 11
- 2
src/Main0.hs View File

@ -23,13 +23,22 @@ main = do args <- getArgs
file <- return ((optFile opt) !! 0) file <- return ((optFile opt) !! 0)
str <- BS.readFile file str <- BS.readFile file
(id, gmseed) <- return (readInput str) (id, gmseed) <- return (readInput str)
commands <- return (map (\(seed,game) -> strat0 game) gmseed)
commandspoints <- return (map (\(seed,game) -> strat0 game) gmseed)
(commands,points) <- return $ unzip commandspoints
seeds <- return ((map (\(seed, _) -> seed)) gmseed) seeds <- return ((map (\(seed, _) -> seed)) gmseed)
putStrLn . encodeJSON $ (packAll id seeds commands) putStrLn . encodeJSON $ (packAll id seeds commands)
writeFile (file ++ ".output") (scoredata id (fst $ unzip gmseed) points)
packAll :: Int -> [Int] -> [[Command]] -> [JSONSer] packAll :: Int -> [Int] -> [[Command]] -> [JSONSer]
packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik0" y) seeds commandStrings packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik0" y) seeds commandStrings
where where
commandStrings = map cmdToString commandLists commandStrings = map cmdToString commandLists
scoredata :: Int -> [Int] -> [Int] -> String
scoredata id seeds points = pretty
where
pretty = foldl (\x (a,b,c) -> (show a) ++ " " ++ (show b) ++ " " ++ (show c) ++ "\n" ++ x) "" zipdata
zipdata = zip3 ids seeds points
ids = replicate (length seeds) id

+ 15
- 10
src/Strategy0.hs View File

@ -5,21 +5,26 @@ import VM
seswlist = cycle [MoveSE, MoveSW] seswlist = cycle [MoveSE, MoveSW]
strat0 :: Game -> [Command]
strat0 game = take nsteps seswlist
strat0 :: Game -> ([Command],Int)
strat0 game = (take nsteps seswlist, score)
where where
nsteps = stepr game
(nsteps, score) = stepr game
stepr :: Game -> Int
stepr :: Game -> (Int,Int)
stepr game = if notes == Ended stepr game = if notes == Ended
then 1
else 1 + (stepl new_game)
then (1,score)
else (1 + (fst new_step), snd new_step)
where where
(new_game,notes) = step game MoveSE (new_game,notes) = step game MoveSE
score = points new_game
new_step = (stepl new_game)
stepl :: Game -> Int
stepl :: Game -> (Int,Int)
stepl game = if notes == Ended stepl game = if notes == Ended
then 1
else 1 + (stepr new_game)
then (1,score)
else (1 + (fst new_step), snd new_step)
where where
(new_game,notes) = step game MoveSW
(new_game,notes) = step game MoveSW
score = points new_game
new_step = (stepr new_game)

Loading…
Cancel
Save