{-# LANGUAGE DeriveGeneric #-} module Main where import GHC.Generics import Data.Aeson import Data.Aeson.Types import System.Environment import qualified Data.ByteString.Lazy.Char8 as BS import System.IO import Datatypes import Opt import JSONDeser import Strategy2 import VM (Command, cmdToString) data JSONSer = JSONSer { problemId :: Int, seed :: Int, tag :: String, solution :: String } deriving (Show, Generic) instance FromJSON JSONSer instance ToJSON JSONSer main :: IO () main = do args <- getArgs opt <- parseArgs args file <- return ((optFile opt) !! 0) str <- BS.readFile file (id, gmseed) <- return (readInput str) commandspoints <- return (map (\(seed,game) -> strat2 game) gmseed) (commands,points) <- return $ unzip commandspoints seeds <- return ((map (\(seed, _) -> seed)) gmseed) writeFile ("scores") (scoredata id (fst $ unzip gmseed) points) BS.putStrLn $ encode $ (packAll id seeds commands) packAll :: Int -> [Int] -> [[Command]] -> [JSONSer] packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik1" 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