diff --git a/calculateAndSubmit b/calculateAndSubmit index 303c0e3..888c3c0 100755 --- a/calculateAndSubmit +++ b/calculateAndSubmit @@ -3,7 +3,7 @@ if [ $# -lt 1 ]; then echo "missing json filename" exit 1 fi -OUTPUT=`vm/Main0.hs -f $1` +OUTPUT=`vm/Main0 -f $1` if [ $? -eq 0 ]; then read -p "Are you sure? [y/n]" -n 1 -r echo diff --git a/src/Main0.hs b/src/Main0.hs index 44d8a58..8a60b66 100644 --- a/src/Main0.hs +++ b/src/Main0.hs @@ -27,7 +27,7 @@ main = do args <- getArgs putStrLn . encodeJSON $ (packAll id seeds commands) packAll :: Int -> [Int] -> [[Command]] -> [JSONSer] -packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "cazziammolla" y) seeds commandStrings +packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik0" y) seeds commandStrings where commandStrings = map cmdToString commandLists diff --git a/src/PowerPhrases.hs b/src/PowerPhrases.hs index 667a63c..b74d319 100644 --- a/src/PowerPhrases.hs +++ b/src/PowerPhrases.hs @@ -1,7 +1,7 @@ module PowerPhrases where import Data.Maybe -import VM (Command(..)) +import Datatypes charToCommand :: Char -> Maybe Command diff --git a/vm/GeneralStrategies.hs b/vm/GeneralStrategies.hs new file mode 100644 index 0000000..594d3bd --- /dev/null +++ b/vm/GeneralStrategies.hs @@ -0,0 +1,19 @@ +module GeneralStrategies where + +import Data.Maybe +import Datatypes +import PowerPhrases +import VM + +executePhrase :: String -> Game -> [(Game, Notes)] +executePhrase str game = foldl cmdprop [(game,OK)] commands + where + commands = mapMaybe charToCommand str + cmdprop (x:xs) cmd = (fst (step (fst x) cmd), notesfilter (snd (step (fst x) cmd)) (snd x)):x:xs + +notesfilter :: Notes -> Notes -> Notes +notesfilter a b = if b == ErrorZero + then ErrorZero + else if a == Ended + then Ended + else OK diff --git a/vm/ReadString.hs b/vm/ReadString.hs new file mode 100644 index 0000000..70bf1fc --- /dev/null +++ b/vm/ReadString.hs @@ -0,0 +1,35 @@ +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 Strategy0 + + + +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) + commands <- return (map (\(seed,game) -> strat0 game) gmseed) + seeds <- return ((map (\(seed, _) -> seed)) gmseed) + putStrLn . encodeJSON $ (packAll id seeds commands) + +packAll :: Int -> [Int] -> [[Command]] -> [JSONSer] +packAll id seeds commandLists = zipWith (\x y -> JSONSer id x "lilik0" y) seeds commandStrings + where + commandStrings = map cmdToString commandLists + +