Exemplo n.º 1
0
  def tunePerfConstants(klass):
    # Keep going until we've spent 60s doing monte-carlo simulations.
    # Then, based on that, set constants so that each run takes 1s.
    perfConstants = klass(0.4, 10, 100)
    ai = MatthewgAI(perfConstants = perfConstants)
    gameState = GameState()
    ai.cardsUnseen = {Cards.MILEAGE_100: 20}
    gameState.playerNumber = 0
    gameState.teams = [Team(number = 0), Team(number = 1)]
    gameState.us = gameState.teams[0]
    gameState.opponents = [gameState.teams[1]]
    for i in xrange(len(gameState.teams)) :
      gameState.teams[i].playerNumbers = [i]

    ai.gameStarted(gameState)
    ai.gameState = gameState
    timeToStop = time.time() + 60
    iterationsCompleted = 0
    while time.time() < timeToStop:
      ai.resetTurnCache()
      ai.monteCarloMileageSimulation()
      iterationsCompleted += 1
    perfConstants.monteCarloIterations = max(int(iterationsCompleted / 60), 50)
    perfConstants.savePerfConstants()
    return perfConstants
Exemplo n.º 2
0
    def tunePerfConstants(klass):
        # Keep going until we've spent 60s doing monte-carlo simulations.
        # Then, based on that, set constants so that each run takes 1s.
        perfConstants = klass(0.4, 10, 100)
        ai = MatthewgAI(perfConstants=perfConstants)
        gameState = GameState()
        ai.cardsUnseen = {Cards.MILEAGE_100: 20}
        gameState.playerNumber = 0
        gameState.teams = [Team(number=0), Team(number=1)]
        gameState.us = gameState.teams[0]
        gameState.opponents = [gameState.teams[1]]
        for i in xrange(len(gameState.teams)):
            gameState.teams[i].playerNumbers = [i]

        ai.gameStarted(gameState)
        ai.gameState = gameState
        timeToStop = time.time() + 60
        iterationsCompleted = 0
        while time.time() < timeToStop:
            ai.resetTurnCache()
            ai.monteCarloMileageSimulation()
            iterationsCompleted += 1
        perfConstants.monteCarloIterations = max(int(iterationsCompleted / 60),
                                                 50)
        perfConstants.savePerfConstants()
        return perfConstants
Exemplo n.º 3
0
 def makeState(self, player):
     state = GameState()
     state.debug = self.debug
     # Pass copies, not the original objects, so the canonical ones can't
     # "accidentally" get modified by the AIs
     state.hand = copy(player.hand)
     state.discardPile = copy(self.discardPile)
     state.teams = deepcopy(self.teams)
     state.us = copy(self.teams[player.teamNumber])
     state.opponents = deepcopy(self.teams)
     del state.opponents[(player.teamNumber)]
     # Passed by value, doesn't need copying
     state.target = self.target
     state.cardsLeft = self.deck.cardsLeft()
     state.playerCount = len(self.players)
     state.playerNumber = player.number
     return state
Exemplo n.º 4
0
 def makeState(self, player):
   state = GameState()
   state.debug = self.debug
   # Pass copies, not the original objects, so the canonical ones can't
   # "accidentally" get modified by the AIs
   state.hand = copy(player.hand)
   state.discardPile = copy(self.discardPile)
   state.teams = deepcopy(self.teams)
   state.us = copy(self.teams[player.teamNumber])
   state.opponents = deepcopy(self.teams)
   del state.opponents[(player.teamNumber)]
   # Passed by value, doesn't need copying
   state.target = self.target
   state.cardsLeft = self.deck.cardsLeft()
   state.playerCount = len(self.players)
   state.playerNumber = player.number
   return state