{-# LANGUAGE DeriveDataTypeable #-} module Main where import System.Environment import qualified Data.ByteString.Lazy as BS import System.IO import Text.JSON.Generic import Datatypes import Opt import JSONDeser import Strategy1 import VM (Command, cmdToString) data JSONSer = JSONSer { problemId :: Int, seed :: Int, tag :: String, solution :: String } deriving (Show, Data, Typeable) 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) -> strat1 game) gmseed) (commands,pointslastnotes) <- return $ unzip commandspoints seeds <- return ((map (\(seed, _) -> seed)) gmseed) putStrLn . encodeJSON $ (packAll id seeds commands) print pointslastnotes -- writeFile ("scores") (scoredata id (fst $ unzip gmseed) points) 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