You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

9 years ago
  1. {-# LANGUAGE DeriveGeneric #-}
  2. module Main where
  3. import GHC.Generics
  4. import Data.Aeson
  5. import Data.Aeson.Types
  6. import System.Environment
  7. import qualified Data.ByteString.Lazy.Char8 as BS
  8. import System.IO
  9. import Datatypes
  10. import Opt
  11. import JSONDeser
  12. import Strategy1
  13. import VM (cmdToString)
  14. import Datatypes.Game (Command(..))
  15. data JSONSer = JSONSer { problemId :: Int,
  16. seed :: Int,
  17. tag :: String,
  18. solution :: String
  19. } deriving (Show, Generic)
  20. instance FromJSON JSONSer
  21. instance ToJSON JSONSer
  22. main :: IO ()
  23. main = do args <- getArgs
  24. opt <- parseArgs args
  25. file <- return ((optFile opt) !! 0)
  26. str <- BS.readFile file
  27. (id, gmseed) <- return (readInput str)
  28. commandspoints <- return (map (\(seed,game) -> strat1 game) gmseed)
  29. (commands,points) <- return $ unzip commandspoints
  30. seeds <- return ((map (\(seed, _) -> seed)) gmseed)
  31. writeFile ("scores") (scoredata id (fst $ unzip gmseed) points)
  32. BS.putStrLn $ encode $ (packAll id seeds commands)
  33. packAll :: Int -> [Int] -> [[Command]] -> [JSONSer]
  34. packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik1" y) seeds commandStrings
  35. where
  36. commandStrings = map cmdToString commandLists
  37. scoredata :: Int -> [Int] -> [Int] -> String
  38. scoredata id seeds points = pretty
  39. where
  40. pretty = foldl (\x (a,b,c) -> (show a) ++ " " ++ (show b) ++ " " ++ (show c) ++ "\n" ++ x) "" zipdata
  41. zipdata = zip3 ids seeds points
  42. ids = replicate (length seeds) id