Browse Source

no cazziammolla

adaptedStrategy0
Andrea Bellandi 9 years ago
parent
commit
fb5c21dee9
5 changed files with 57 additions and 3 deletions
  1. +1
    -1
      calculateAndSubmit
  2. +1
    -1
      src/Main0.hs
  3. +1
    -1
      src/PowerPhrases.hs
  4. +19
    -0
      vm/GeneralStrategies.hs
  5. +35
    -0
      vm/ReadString.hs

+ 1
- 1
calculateAndSubmit View File

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


+ 1
- 1
src/Main0.hs View File

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


+ 1
- 1
src/PowerPhrases.hs View File

@ -1,7 +1,7 @@
module PowerPhrases where
import Data.Maybe
import VM (Command(..))
import Datatypes
charToCommand :: Char -> Maybe Command


+ 19
- 0
vm/GeneralStrategies.hs View File

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

+ 35
- 0
vm/ReadString.hs View File

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

Loading…
Cancel
Save