|
|
@ -13,15 +13,14 @@ import System.Random |
|
|
|
import System.Clock |
|
|
|
import GHC.Generics |
|
|
|
import Data.Aeson |
|
|
|
import Data.Maybe |
|
|
|
|
|
|
|
import StrategyManager |
|
|
|
import Strategy0 |
|
|
|
import Datatypes.Game(Game,Command,commandsToString) |
|
|
|
import VM |
|
|
|
import Datatypes.Game(Game,Command,commandsToString,stringToCommands) |
|
|
|
--import VM |
|
|
|
import Opt |
|
|
|
import JSONDeser(readInput) |
|
|
|
import PowerPhrases |
|
|
|
|
|
|
|
|
|
|
|
strategyTag :: String |
|
|
|
strategyTag = "lilik0" |
|
|
@ -52,7 +51,7 @@ type Id = Int |
|
|
|
type Seed = Int |
|
|
|
|
|
|
|
|
|
|
|
strategies :: Game -> StdGen -> Maybe [Command] -> GameComputation |
|
|
|
strategies :: Game -> StdGen -> [[Command]] -> GameComputation |
|
|
|
strategies g sgen cmd = [MkStrategyWrapper (initst g sgen cmd :: Strategy0)] |
|
|
|
|
|
|
|
-- = [MkStrategyWrapper (initst g sgen cmd :: NullStrategy1), |
|
|
@ -70,10 +69,10 @@ main = do initTime <- secTime |
|
|
|
let files = optFile opt |
|
|
|
let maxTime = optTime opt |
|
|
|
let maxMem = optMem opt |
|
|
|
let powerPhrase = optPowerPhrase opt |
|
|
|
let powerPhrases = optPowerPhrase opt |
|
|
|
let logFile = optLog opt |
|
|
|
rng <- getStdGen |
|
|
|
initialData <- createComputationsFromFiles files rng powerPhrase |
|
|
|
initialData <- createComputationsFromFiles files rng powerPhrases |
|
|
|
let (_, _,gameComputations) = unzip3 initialData |
|
|
|
commandResults <- iterateGame gameComputations (timeStruct maxTime initTime) maxMem |
|
|
|
let stringResults = map (\(cmds,score,algoIdx) -> (commandsToString cmds,score,algoIdx)) commandResults |
|
|
@ -89,19 +88,17 @@ main = do initTime <- secTime |
|
|
|
jsonBuilder (idx, seed, _) (strCmds, _, _) = (JSONSer idx seed strategyTag strCmds) |
|
|
|
logFileBuilder (idx, seed, _) (_ ,score , algoIdx) = (idx, seed, score, algoIdx) |
|
|
|
|
|
|
|
createComputationsFromFiles :: [String] -> StdGen -> Maybe String -> IO [(Id,Seed,GameComputation)] |
|
|
|
createComputationsFromFiles fileNames randomGen powerPhrase = do inputs <- readFiles fileNames |
|
|
|
let igames = map readInput inputs |
|
|
|
let cstruct = compstruct igames |
|
|
|
return (gcstruct cstruct) |
|
|
|
createComputationsFromFiles :: [String] -> StdGen -> [String] -> IO [(Id,Seed,GameComputation)] |
|
|
|
createComputationsFromFiles fileNames randomGen powerPhrases = do inputs <- readFiles fileNames |
|
|
|
let igames = map readInput inputs |
|
|
|
let cstruct = compstruct igames |
|
|
|
return (gcstruct cstruct) |
|
|
|
where |
|
|
|
compstruct ig = concat (map genf ig) |
|
|
|
genf (i,g) = zipWith (\x (y,z) -> (x,y,z)) (replicate (length g) i) g |
|
|
|
gcstruct cst = map (\(x,y,z) -> (x,y,j z)) cst |
|
|
|
where |
|
|
|
j game = strategies game randomGen (powerCommands powerPhrase) |
|
|
|
powerCommands Nothing = Nothing |
|
|
|
powerCommands (Just a) = Just (mapMaybe charToCommand a) |
|
|
|
j game = strategies game randomGen (map stringToCommands powerPhrases) |
|
|
|
|
|
|
|
readFiles :: [String] -> IO [BS.ByteString] |
|
|
|
readFiles [] = return [] |
|
|
|