def buyPhase(hand, deck, discard, play, totalDeck, p1): ''' The buy phase for a regular dominion turn''' global supplyCards, supplyAmounts tmpHand = list() handcopy = card_format.transformCards(hand.copy()) while len(hand) > 0: card = hand.pop(-1) if card.isTreasure(): p1.changeCoins(card.getCoins()) play.append(card) else: tmpHand.append(card) hand = tmpHand possibleBuys = list() for card in supplyCards: if card.getCost() <= p1.getCoins() and supplyAmounts[card.getName()] > 0: possibleBuys.append(card.getName()) possibleBuys.append("none") # gotta add that it may be better to buy nothing buys = bestBuy(handcopy, possibleBuys, p1.getBuys()) if buys != "none": supplyAmounts[buys] -= 1 discard = card_format.newCard(discard, buys) totalDeck = card_format.allDeckCards(hand, deck, discard, play) if gSAPPrevious != None: # skip providing values the first turn updateValues(handcopy) return hand, deck, discard, play, totalDeck, p1
def env_step(action): """ Arguments --------- action : int the action taken by the agent in the current state Returns ------- result : dict dictionary with keys {reward, state, isTerminal} containing the results of the action taken """ global gCurrentState, gTerminalPosition global p1 global totalDeckLists reward = -1.0 isTerminal = False totalDeck = gCurrentState[0] hand, deck, discard, play = gCurrentState[1] possibleBuys = gCurrentState[2] for buy in action: if buy == "province": reward = 1 isTerminal = True if buy != "none": supplyAmounts[buy] -= 1 discard = card_format.newCard(discard, buy) totalDeck = card_format.allDeckCards(hand, deck, discard, play) hand, deck, discard, play, totalDeck, p1 = cleanupPhase( hand, deck, discard, play, totalDeck, p1) hand, deck, discard, play, totalDeck, p1 = actionPhase( hand, deck, discard, play, totalDeck, p1) hand, deck, discard, play, totalDeck, p1, buys = buyPhase( hand, deck, discard, play, totalDeck, p1) # for phase in phases: # if phase == "action": hand, deck, discard, play, totalDeck, p1 = actionPhase(hand, deck, discard, play, totalDeck, p1) # elif phase == "buy": buys = buyPhase(hand, deck, discard, play, totalDeck, p1) # elif phase == "cleanup": hand, deck, discard, play, totalDeck, p1 = cleanupPhase(hand, deck, discard, play, totalDeck, p1) # else: print("OH NO") gCurrentState = [totalDeck, [hand, deck, discard, play], buys] totalDeckLists.append(totalDeck) result = { "reward": reward, "state": gCurrentState, "isTerminal": isTerminal } return result