def test_merchant(self) -> None:
        self.game.new_game()

        p_state: PlayerState = self.game.state.player_states[0]

        # Inject cards into hand
        merchant = Merchant()
        first_silver = Silver()
        second_silver = Silver()
        self.game.state.inject(0, merchant)
        self.game.state.inject(0, first_silver)
        self.game.state.inject(0, second_silver)
        self.game.state.inject(0, Estate())
        self.game.state.inject(0, Estate())

        self.game.state.advance_next_decision()

        # Action Phase Decision -- Play Merchant
        r = DecisionResponse([merchant])
        self.game.state.process_decision(r)
        self.game.state.advance_next_decision()

        # Treasure Phase Decision -- Play All Treasures
        r = DecisionResponse([first_silver])
        self.game.state.process_decision(r)
        self.game.state.advance_next_decision()

        r = DecisionResponse([second_silver])
        self.game.state.process_decision(r)
        self.game.state.advance_next_decision()

        self.assertEqual(p_state.coins, 5)
예제 #2
0
    def test_add_children(self) -> None:
        children = [Estate(), Duchy(), Province()]
        self.root.add_unique_children(children)

        self.assertEquals(self.root.children[0].parent, self.root)
        self.assertEquals(self.root.children[1].parent, self.root)
        self.assertEquals(self.root.children[2].parent, self.root)

        self.root.add_unique_children(children)
        self.assertEquals(len(self.root.children), len(children))
예제 #3
0
    def __init__(self, game_config: GameConfig, pid: int) -> None:
        self._actions = 1
        self._buys = 1
        self._coins = 0
        self._turns = 0
        self._deck = []
        self._discard = []
        self.hand = []
        self._island = []
        self._play_area = []
        self._pid = pid

        split = game_config.starting_splits[pid]
        rng = np.random.default_rng()

        if split == StartingSplit.StartingRandomSplit:
            self._deck = [Copper() for i in range(7)] + [Estate() for i in range(3)]
            np.random.shuffle(self._deck)
        else:
            if split == StartingSplit.Starting34Split:
                if rng.integers(0, 2) == 1:
                    bottom_coppers = 3
                else:
                    bottom_coppers = 4
            elif split == StartingSplit.Starting25Split:
                if rng.integers(0, 2) == 1:
                    bottom_coppers = 2
                else:
                    bottom_coppers = 5
            elif split == StartingSplit.UniformRandomSplit:
                sample = rng.random()
                if sample < 1 / 4:
                    bottom_coppers = 2
                elif sample < 1 / 2:
                    bottom_coppers = 3
                elif sample < 3 / 4:
                    bottom_coppers = 4
                else:
                    bottom_coppers = 5
            else:
                raise ValueError('Invalid starting split.')
            self._deck = [Copper() for i in range(bottom_coppers)] + [Estate() for i in range(3)] + [Copper() for i in range(7 - bottom_coppers)]
예제 #4
0
    def test_remove_first_card(self):
        card = Colony()

        cards = []

        self.assertIsNone(remove_first_card(card, cards))

        cards = [card]

        self.assertEqual(remove_first_card(card, cards), card)

        cards = [Estate(), card, Province(), Colony()]

        self.assertEqual(remove_first_card(card, cards), card)
    def test_bandit_attack_discard_only(self) -> None:
        self.game.new_game()
        p_state: PlayerState = self.game.state.player_states[1]
        deck = p_state._deck
        not_treasure = Estate()
        not_valuable = Copper()
        deck[-1] = not_treasure
        deck[-2] = not_valuable

        effect = BanditEffect()

        effect.play_action(self.game.state)
        self.game.state.advance_next_decision()
        self.assertEquals(self.game.state.trash, [])
        self.assertEquals(p_state._discard, [not_treasure, not_valuable])
예제 #6
0
    def test_uct_filter(self):
        choices = [
            Copper(),
            Silver(),
            Gold(),
            Curse(),
            Estate(),
            Duchy(),
            Province(),
            Chapel(),
            Witch()
        ]
        filtered_choices = list(
            filter(
                lambda x: not isinstance(x, Curse) and not isinstance(
                    x, Copper) and not issubclass(type(x), VictoryCard),
                choices))

        self.assertEqual(len(filtered_choices), 4)
예제 #7
0
    def test_get_child(self) -> None:
        children = [Estate(), Duchy(), Province()]
        self.root.add_unique_children(children)

        self.assertIsNotNone(self.root.get_child_node(Estate()))
        self.assertIsNone(self.root.get_child_node(Colony()))
 def setUp(self) -> None:
     self.choices = [Estate(), Silver(), Gold(), Merchant(), Festival(), Smithy()]