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.

50 lines
1.6 KiB

  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 (Command, cmdToString)
  14. data JSONSer = JSONSer { problemId :: Int,
  15. seed :: Int,
  16. tag :: String,
  17. solution :: String
  18. } deriving (Show, Generic)
  19. instance FromJSON JSONSer
  20. instance ToJSON JSONSer
  21. main :: IO ()
  22. main = do args <- getArgs
  23. opt <- parseArgs args
  24. file <- return ((optFile opt) !! 0)
  25. str <- BS.readFile file
  26. (id, gmseed) <- return (readInput str)
  27. commandspoints <- return (map (\(seed,game) -> strat1 game) gmseed)
  28. (commands,points) <- return $ unzip commandspoints
  29. seeds <- return ((map (\(seed, _) -> seed)) gmseed)
  30. writeFile ("scores") (scoredata id (fst $ unzip gmseed) points)
  31. BS.putStrLn $ encode $ (packAll id seeds commands)
  32. packAll :: Int -> [Int] -> [[Command]] -> [JSONSer]
  33. packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik1" y) seeds commandStrings
  34. where
  35. commandStrings = map cmdToString commandLists
  36. scoredata :: Int -> [Int] -> [Int] -> String
  37. scoredata id seeds points = pretty
  38. where
  39. pretty = foldl (\x (a,b,c) -> (show a) ++ " " ++ (show b) ++ " " ++ (show c) ++ "\n" ++ x) "" zipdata
  40. zipdata = zip3 ids seeds points
  41. ids = replicate (length seeds) id