def get_game_state( self, player: Player.Player, cards_to_draw: int = 0, ) -> Tuple[ List[List[float]], List[int], List[List[float]], List[int], List[List[float]], List[float], ]: opponent_states: List[List[float]] = [] for opponent in players_around(self.players, player, inclusive=False): opponent_states.append( [ float(len(opponent.deck)) / 40, float(len(opponent.discard)) / 40, float(len(opponent.hand)) / 5, float(opponent.calcpoints()) / 30, float(opponent.our_turn), ] ) hand_state: List[List[float]] = [] hand_one_hot: List[int] = [] for card in player.hand: hand_state.append(self.get_card_features(card.name, player)) hand_one_hot.append(Card.CardIndexMap[card.name]) kingdom_state: List[List[float]] = [] kingdom_one_hot: List[int] = [] for card_name in self.supply: kingdom_state.append(self.get_card_features(card_name, player)) kingdom_one_hot.append(Card.CardIndexMap[card_name]) game_state = [ float(player.actions), float(player.buys), float(self.turns) / 20, float(cards_to_draw) / 5, float(player.purse) / 8, float(player.our_turn), float(len(player.deck)) / 40, float(len(player.discard)) / 40, float(len(player.hand)) / 5, float(player.calcpoints()) / 30, ] return ( hand_state, hand_one_hot, kingdom_state, kingdom_one_hot, opponent_states, game_state, )
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: for player in players_around(game.players, this_player, inclusive=False): player.draw() return 0
def ongain( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ): for player in players_around(game.players, this_player, inclusive=False): if len(game.supply["Curse"]) > 0: player.discard.append(game.supply["Curse"].pop())
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: for player in players_around(game.players, this_player, inclusive=False): if len(game.supply["Curse"]) > 0: if not mock: for c in player.hand: if c.react(player, game, network, mock): break else: player.discard.append(game.supply["Curse"].pop()) return 0
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: for player in players_around(game.players, this_player, inclusive=False): has_moat = False if len(player.hand) > 3: for c in player.hand: if c.react(player, game, network, mock) or mock: has_moat = True break else: player.show(lead="\n\n") while len(player.hand) > 3: dis_card = player.choose_discard( player.name + ", choose a card from your hand to discard: ", game, network, mock=mock, ) print("Discard " + dis_card) if dis_card: c = getcard(dis_card, game.supply, player.hand, "your hand") if c: player.hand.remove(c) c.ondiscard(player, game, network, mock) player.discard.append(c) else: raise ValueError() if (not mock) and (len(player.hand) > 3) and (not has_moat): raise ValueError() return 0
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: for player in players_around(game.players, this_player, inclusive=True): for c in player.hand: if c.react(player, game, network, mock) or mock: break else: player.draw(player.hold) if len(player.hold) != 1: continue else: this_player.hprint("The first card in the deck of " + player.name + " is " + player.hold[0].name) if this_player.yesnoinput( this_player.name + ", do you want " + player.name + " to discard this?", game, network, ", discard", ", keep", applyto=player, callbacks={ True: Spy.yes_callback, False: Spy.no_callback }, mock=mock, ): Spy.yes_callback(player, game, network, mock) else: Spy.no_callback(player, game, network, mock) return 0
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: if len(game.supply["Silver"]) > 0: this_player.deck.insert(0, game.supply["Silver"].pop()) for player in players_around(game.players, this_player, inclusive=False): for c in player.hand: if c.react(player, game, network, mock) or mock: break else: if "victory" in catinlist(player.hand): putback = player.choose_discard( player.name + ", which victory card" + " do you want to put on top of your deck?\n--> ", game, network, constraint="victory", ondeck=True, mock=mock, ) c = getcard(putback, game.supply, player.hand, "your hand", ["victory"]) if c: player.hand.remove(c) player.deck.insert(0, c) else: raise ValueError() else: player.show(lead="\n\n") return 0
def play( self, this_player: Player.Player, game: Game.Game, network: DominionNetwork, mock: bool, ) -> int: if not mock: for player in players_around(game.players, this_player, inclusive=False): has_reaction = False for c in player.hand: if c.react(player, game, network, mock) or mock: has_reaction = True if not has_reaction: for i in range(2): player.draw(player.hold) coin_idx = [] for idx, card in enumerate(player.hold): if "coin" in card.categories: coin_idx.append(idx) else: player.hold.remove(card) player.discard.append(card) # TODO: Make this a model decision if len(coin_idx) == 2: if this_player.yesnoinput( "Would you like to trash the other card?", game, network, mock=mock, ): c = player.hold[coin_idx[0]] player.hold.remove(c) player.discard.append(c) else: c = player.hold[coin_idx[1]] player.hold.remove(c) player.discard.append(c) this_player.hold.append(player.hold.pop()) if this_player.yesnoinput( "Do you want to steal it?", game, network, ", it's mine!", ", leave it in the trash.", callbacks={ True: Thief.yes_callback, False: Thief.no_callback }, mock=mock, ): Thief.yes_callback(this_player, game, network, mock) else: Thief.no_callback(this_player, game, network, mock) player.discard = player.discard + player.hold player.hold = [] return 0
def get_card_features(self, card_name: str, player: Player.Player,) -> List[float]: card = Card.CardNameMap[card_name] cost = float(card.cost) / 8 vpoints = float(card.get_points(player)) / 6 is_victory = float("victory" in card.categories) is_action = float("action" in card.categories) is_coin = float("coin" in card.categories) is_attack = float("attack" in card.categories) is_reaction = float("reaction" in card.categories) is_duration = float("duration" in card.categories) supply_left = float(len(self.supply[card_name])) / 10 player_deck_count = float(Game.count_cards_in_pile(card_name, player.deck)) / 10 player_discard_count = ( float(Game.count_cards_in_pile(card_name, player.discard)) / 10 ) opponent_discards = [0.0, 0.0, 0.0] opponent_decks = [0.0, 0.0, 0.0] for idx, opponent in enumerate( players_around(self.players, player, inclusive=False) ): opponent_discards[idx] = ( float(Game.count_cards_in_pile(card_name, opponent.discard)) / 10 ) opponent_decks[idx] = ( float(Game.count_cards_in_pile(card_name, opponent.stack())) / 10 ) player_hand_count = float(Game.count_cards_in_pile(card_name, player.hand)) / 10 trash_count = float(Game.count_cards_in_pile(card_name, self.trash)) / 10 return [ cost, vpoints, is_victory, is_action, is_coin, is_attack, is_reaction, is_duration, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, supply_left, player_deck_count, player_discard_count, player_hand_count, opponent_discards[0], opponent_discards[1], opponent_discards[2], opponent_decks[0], opponent_decks[1], opponent_decks[2], trash_count, ]