From 3731059584c3154ea333bc98f96beab9fbdae3a1 Mon Sep 17 00:00:00 2001 From: zolfa Date: Sat, 8 Aug 2015 21:50:07 +0200 Subject: [PATCH] Add new Strategy1 --- src/Main1.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/Strategy1.hs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/Main1.hs create mode 100644 src/Strategy1.hs diff --git a/src/Main1.hs b/src/Main1.hs new file mode 100644 index 0000000..34232af --- /dev/null +++ b/src/Main1.hs @@ -0,0 +1,45 @@ +{-# 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 + diff --git a/src/Strategy1.hs b/src/Strategy1.hs new file mode 100644 index 0000000..73f5498 --- /dev/null +++ b/src/Strategy1.hs @@ -0,0 +1,30 @@ +module Strategy1 where + +import Datatypes +import VM + + +strat1 :: Game -> ([Command],(Int,Notes)) +strat1 game = if new_notes == GameOver + then (new_command : [], (score new_game, new_notes)) + else (new_command : (fst $ strat1 new_game), snd $ strat1 new_game) + where + (new_game_se,notes_se) = step game MoveSE + (new_game_sw,notes_sw) = step game MoveSW + se = (new_game_se,notes_se,MoveSE) + sw = (new_game_sw,notes_sw,MoveSW) + (new_game,new_notes,new_command) = case (notes_sw,notes_se) of + (GameOver,GameOver) -> se + (_,GameOver) -> sw + (GameOver,_) -> se + (Lock i,OK) -> if i > 0 + then sw + else se + (OK,Lock i) -> if i > 0 + then se + else sw + (OK,OK) -> sw + (Lock i,Lock j) -> if i > j + then sw + else se + otherwise -> (game,GameOver,MoveE)