def play(self):
     sys.stdout.write('Iterating')
     startDeck = CardCounts({Copper.Copper():7, Estate.Estate():3})
     for chrm in self.chromosomes:
         sys.stdout.write('.')
         sys.stdout.flush()
         if chrm.gamesPlayed == self.times_to_play:
             continue
         who_to_play = filter((lambda x: x.gamesPlayed < self.times_to_play), self.chromosomes)
         tourn = random.sample(who_to_play, 2) 
         tourn.insert(0, chrm)
         gameType = random.choice(self.games)
         players = []
         for player in tourn:
             players.append(GUMDRP(gameType[1], *player.genes))
         gs = GameState.setup(gameType[0], startDeck, players)
         numPlayers = len(gs.players);
         numDepleted = 0
         numMoves = 0
         while (gs.stacks[Province.Province()] != 0) and numDepleted < 3 and not self.suboptimalDeck(gs, gameType[1]) and numMoves < 80:
             curPlayer = gs.players[gs.turn]
             gs.abcs[gs.turn] = {'actions':1, 'buys':1, 'coins':0}
             gs = curPlayer.playActionPhase(gs)
             bought = gs.stacks.copy()
             gs = curPlayer.playBuyPhase(gs)
             gs = curPlayer.playDiscardPhase(gs)
             gs.turn = (gs.turn + 1) % numPlayers
             numDepleted = len(filter(lambda c: gs.stacks[c] == 0, gs.stacks))
             numMoves += 1
         cards_left = [((gameType[1] - gs.pcards[i].allCards()).count, i) for i in xrange(numPlayers)]
         cards_left.sort()
         for people in cards_left:
             tourn[people[1]].incr(people[0])
     print ''
Example #2
0
def evalDeck(player,
             stacks,
             deck,
             trials=5,
             coinsPerBuy=8,
             aquireFilter=lambda c: True):
    totalBuyingPower = 0
    totalAquiredValue = 0
    state = GameState.setup(stacks.copy(), deck.copy(), [player])
    #print str(deck)
    for t in xrange(trials):
        #state = GameState.setup(deck.copy(), deck.copy(), [player])
        state.abcs[0] = {'actions': 1, 'buys': 1, 'coins': 0}
        #print str(state.pcards[0].hand)
        aquired = state.stacks.copy()
        state = state.players[0].playActionPhase(state)
        aquired -= state.stacks
        totalAquiredValue += sum(
            [c.cost * n for c, n in aquired.items() if aquireFilter(c)])
        totalCoins = state.abcs[0]['coins'] + sum(
            [c.coins * n for c, n in state.pcards[0].hand.items()])
        totalBuyingPower += min(state.abcs[0]['buys'] * coinsPerBuy,
                                totalCoins)
        state = state.players[0].playDiscardPhase(state)
        #print totalBuyingPower, '~\tbuys:', state.abcs[0]['buys'], '\tcoins:', totalCoins, '\taquired:', str(aquired), '\n'
    return (totalBuyingPower, totalAquiredValue)
Example #3
0
def evalDeck(player, stacks, deck, trials = 5, coinsPerBuy=8, aquireFilter = lambda c:True):
    totalBuyingPower = 0
    totalAquiredValue = 0
    state = GameState.setup(stacks.copy(), deck.copy(), [player])
    #print str(deck)
    for t in xrange(trials):
        #state = GameState.setup(deck.copy(), deck.copy(), [player])
        state.abcs[0] = {'actions':1, 'buys':1, 'coins':0}
        #print str(state.pcards[0].hand)
        aquired = state.stacks.copy()
        state = state.players[0].playActionPhase(state)
        aquired -= state.stacks
        totalAquiredValue += sum([c.cost*n for c,n in aquired.items() if aquireFilter(c)])
        totalCoins = state.abcs[0]['coins'] + sum([c.coins*n for c,n in state.pcards[0].hand.items()])
        totalBuyingPower += min(state.abcs[0]['buys']*coinsPerBuy, totalCoins)
        state = state.players[0].playDiscardPhase(state)
        #print totalBuyingPower, '~\tbuys:', state.abcs[0]['buys'], '\tcoins:', totalCoins, '\taquired:', str(aquired), '\n'
    return (totalBuyingPower, totalAquiredValue)
 def play(self):
     sys.stdout.write('Iterating')
     startDeck = CardCounts({Copper.Copper(): 7, Estate.Estate(): 3})
     for chrm in self.chromosomes:
         sys.stdout.write('.')
         sys.stdout.flush()
         if chrm.gamesPlayed == self.times_to_play:
             continue
         who_to_play = filter(
             (lambda x: x.gamesPlayed < self.times_to_play),
             self.chromosomes)
         tourn = random.sample(who_to_play, 2)
         tourn.insert(0, chrm)
         gameType = random.choice(self.games)
         players = []
         for player in tourn:
             players.append(GUMDRP(gameType[1], *player.genes))
         gs = GameState.setup(gameType[0], startDeck, players)
         numPlayers = len(gs.players)
         numDepleted = 0
         numMoves = 0
         while (gs.stacks[Province.Province()] !=
                0) and numDepleted < 3 and not self.suboptimalDeck(
                    gs, gameType[1]) and numMoves < 80:
             curPlayer = gs.players[gs.turn]
             gs.abcs[gs.turn] = {'actions': 1, 'buys': 1, 'coins': 0}
             gs = curPlayer.playActionPhase(gs)
             bought = gs.stacks.copy()
             gs = curPlayer.playBuyPhase(gs)
             gs = curPlayer.playDiscardPhase(gs)
             gs.turn = (gs.turn + 1) % numPlayers
             numDepleted = len(
                 filter(lambda c: gs.stacks[c] == 0, gs.stacks))
             numMoves += 1
         cards_left = [((gameType[1] - gs.pcards[i].allCards()).count, i)
                       for i in xrange(numPlayers)]
         cards_left.sort()
         for people in cards_left:
             tourn[people[1]].incr(people[0])
     print ''