Browse Source

sistemate flag e pphrases

vm
Andrea Bellandi 9 years ago
parent
commit
56f3f25099
6 changed files with 19 additions and 22 deletions
  1. +1
    -1
      icfp2015.cabal
  2. +1
    -1
      src/Datatypes/Game.hs
  3. +12
    -15
      src/Main.hs
  4. +3
    -3
      src/Opt.hs
  5. +1
    -1
      src/Strategy0.hs
  6. +1
    -1
      src/StrategyManager.hs

+ 1
- 1
icfp2015.cabal View File

@ -60,7 +60,7 @@ executable icfp2015
other-extensions: OverloadedStrings, DeriveGeneric, DeriveDataTypeable
-- Other library packages from which modules are imported.
build-depends: base >=4.6 && <4.9, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.9, bytestring >=0.10 && <0.11, aeson >=0.8 && <0.9, pqueue >=1.3 && <1.4, clock, random, deepseq >= 1.3 && <1.4
build-depends: base >=4.6 && <4.9, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, QuickCheck >=2.7 && <2.9, bytestring >=0.10 && <0.11, aeson, pqueue >=1.3 && <1.4, clock, random, deepseq >= 1.3 && <1.4
-- Directories containing source files.
hs-source-dirs: src


+ 1
- 1
src/Datatypes/Game.hs View File

@ -1,4 +1,4 @@
module Datatypes.Game (Game(..), Command(..), isCompleted, new, notifyCommand, powerCounterToScore, powerPhrasesAsCommands, commandsToString) where -- FIXME exports
module Datatypes.Game (Game(..), Command(..), isCompleted, new, notifyCommand, powerCounterToScore, powerPhrasesAsCommands, commandsToString,stringToCommands) where -- FIXME exports
import Data.Hashable (hash)
import qualified Data.List as List


+ 12
- 15
src/Main.hs View File

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


+ 3
- 3
src/Opt.hs View File

@ -14,7 +14,7 @@ data Flag = File String
data Options = Options { optFile :: [String],
optTime :: Maybe Int,
optMem :: Maybe Int,
optPowerPhrase :: Maybe String,
optPowerPhrase :: [String],
optSeedNumber :: Int,
optCores :: Int,
optLog :: Bool
@ -24,7 +24,7 @@ data Options = Options { optFile :: [String],
startOptions = Options { optFile = [],
optTime = Nothing,
optMem = Nothing,
optPowerPhrase = Nothing,
optPowerPhrase = [],
optSeedNumber = 0,
optCores = 1,
optLog = True
@ -48,7 +48,7 @@ options = [ Option "f" ["filename"]
"Memory Limit in MB"
, Option "p" ["phrasepower"]
(ReqArg
(\arg opt -> return opt { optPowerPhrase = Just arg })
(\arg opt -> return opt { optPowerPhrase = (arg:(optPowerPhrase opt)) })
"POWERPHRASE")
"Power Phrase"
, Option "n" ["seednumber"]


+ 1
- 1
src/Strategy0.hs View File

@ -24,7 +24,7 @@ instance Strategy Strategy0 where
advance = strategy0advance
getbest = strategy0getbest
strategy0initst :: Game -> StdGen -> Maybe [Command] -> Strategy0
strategy0initst :: Game -> StdGen -> [[Command]] -> Strategy0
strategy0initst game _ _ = (Strategy0 (firstQueue, firstList)) where
firstQueue = PQ.singleton (fullScore game, -(length $ Game.units game), snd . Unit.pivot . head . Game.units $ game) game
firstList = []


+ 1
- 1
src/StrategyManager.hs View File

@ -23,7 +23,7 @@ initWrapper :: Strategy a => a -> StrategyWrapper
initWrapper = MkStrategyWrapper
class Strategy a where
initst :: Game -> StdGen -> Maybe [Command] -> a
initst :: Game -> StdGen -> [[Command]] -> a
advance :: a -> Either a ([Command], Int)
getbest :: a -> ([Command], Int)


Loading…
Cancel
Save