示例#1
0
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
示例#2
0
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
示例#3
0
def env_init():
    global gStartPosition, p1, supplyCards, supplyAmounts, totalDeckLists
    p1 = player_format.playerStats(1, 1, 0, 3)  # Easy 3 vp for starting
    totalDeckLists = list()
    supplyCards = card_format.kingdomCards()
    supplyAmounts = card_format.kingdomCardValues(supplyCards)
    cards = card_format.startingCards()
    hand, deck, discard, play = firstHand(cards)
    totalDeck = card_format.allDeckCards(hand, deck, discard, play)
    playAreas = [hand, deck, discard, play]
    possibleBuys = list()
    gStartPosition = [totalDeck, playAreas, possibleBuys]
    return
示例#4
0
def botPlay(hand, deck, discard, play, p1):
    ''' Where the bot walks through each phase of the turn '''
    turn = 0
    for turn in range(maxTurns):
        totalDeck = card_format.allDeckCards(hand, deck, discard, play)
        for phase in phases:
            if phase == "action": hand, deck, discard, play, totalDeck, p1 = actionPhase(hand, deck, discard, play, totalDeck, p1)
            elif phase == "buy": hand, deck, discard, play, totalDeck, p1 = buyPhase(hand, deck, discard, play, totalDeck, p1)
            # if gSAPPrevious != None:
            #     # skip providing values the first turn
            #     updateValues(totalDeck)
            elif phase == "cleanup": hand, deck, discard, play, totalDeck, p1 = cleanupPhase(hand, deck, discard, play, totalDeck, p1)
            else: print("OH NO")

        if supplyAmounts["province"] != 8:
            break
    return turn