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.

44 lines
1.5 KiB

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