Browse Source

Add new Strategy1

adaptedStrategy0
Zolfa 10 years ago
parent
commit
3731059584
2 changed files with 75 additions and 0 deletions
  1. +45
    -0
      src/Main1.hs
  2. +30
    -0
      src/Strategy1.hs

+ 45
- 0
src/Main1.hs View File

@ -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

+ 30
- 0
src/Strategy1.hs View File

@ -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)

Loading…
Cancel
Save