diff --git a/icfp2015.cabal b/icfp2015.cabal index a53f617..8ea266c 100644 --- a/icfp2015.cabal +++ b/icfp2015.cabal @@ -60,7 +60,7 @@ executable icfp2015 other-extensions: OverloadedStrings, DeriveGeneric, DeriveDataTypeable -- 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. hs-source-dirs: src diff --git a/src/Main0.hs b/src/Main0.hs index fa005ff..52e1751 100644 --- a/src/Main0.hs +++ b/src/Main0.hs @@ -23,13 +23,22 @@ main = do args <- getArgs file <- return ((optFile opt) !! 0) str <- BS.readFile file (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) putStrLn . encodeJSON $ (packAll id seeds commands) + writeFile (file ++ ".output") (scoredata id (fst $ unzip gmseed) points) + packAll :: Int -> [Int] -> [[Command]] -> [JSONSer] packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik0" y) seeds commandStrings where 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 + diff --git a/src/Strategy0.hs b/src/Strategy0.hs index 9b4280e..3dc05a0 100644 --- a/src/Strategy0.hs +++ b/src/Strategy0.hs @@ -5,21 +5,26 @@ import VM seswlist = cycle [MoveSE, MoveSW] -strat0 :: Game -> [Command] -strat0 game = take nsteps seswlist +strat0 :: Game -> ([Command],Int) +strat0 game = (take nsteps seswlist, score) where - nsteps = stepr game + (nsteps, score) = stepr game -stepr :: Game -> Int +stepr :: Game -> (Int,Int) stepr game = if notes == Ended - then 1 - else 1 + (stepl new_game) + then (1,score) + else (1 + (fst new_step), snd new_step) where (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 - then 1 - else 1 + (stepr new_game) + then (1,score) + else (1 + (fst new_step), snd new_step) where - (new_game,notes) = step game MoveSW + (new_game,notes) = step game MoveSW + score = points new_game + new_step = (stepr new_game) +