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.

45 lines
1.5 KiB

  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 Strategy1
  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) -> strat1 game) gmseed)
  24. (commands,pointslastnotes) <- return $ unzip commandspoints
  25. seeds <- return ((map (\(seed, _) -> seed)) gmseed)
  26. putStrLn . encodeJSON $ (packAll id seeds commands)
  27. print pointslastnotes
  28. -- writeFile ("scores") (scoredata id (fst $ unzip gmseed) points)
  29. packAll :: Int -> [Int] -> [[Command]] -> [JSONSer]
  30. packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik1" y) seeds commandStrings
  31. where
  32. commandStrings = map cmdToString commandLists
  33. scoredata :: Int -> [Int] -> [Int] -> String
  34. scoredata id seeds points = pretty
  35. where
  36. pretty = foldl (\x (a,b,c) -> (show a) ++ " " ++ (show b) ++ " " ++ (show c) ++ "\n" ++ x) "" zipdata
  37. zipdata = zip3 ids seeds points
  38. ids = replicate (length seeds) id