Exemple #1
0
def test_remove_card_elimination():
    player = coup.PlayerState(cards=[Role.DUKE],
                              coins=0,
                              agent=None,
                              name=None)
    assert coup.removeCard(player, Role.DUKE) == None

    player = coup.PlayerState(cards=[Role.CAPTAIN, Role.CONTESSA],
                              coins=0,
                              agent=None,
                              name=None)
    assert coup.removeCard(coup.removeCard(player, Role.CAPTAIN),
                           Role.CONTESSA) == None
Exemple #2
0
def test_get_player_view():
    game = coup.GameState(players=[
        coup.PlayerState(cards=[Role.CAPTAIN], coins=0, agent=None,
                         name='0th'),
        coup.PlayerState(cards=[Role.ASSASSIN, Role.CAPTAIN],
                         coins=9,
                         agent=None,
                         name='1st'),
        coup.PlayerState(cards=[Role.DUKE, Role.DUKE],
                         coins=5,
                         agent=None,
                         name='2nd')
    ],
                          deck=[])
    view0 = coup.PlayerView(selfstate=game.players[0],
                            opponents=[
                                coup.PlayerState(cards=2,
                                                 coins=9,
                                                 agent=None,
                                                 name='1st'),
                                coup.PlayerState(cards=2,
                                                 coins=5,
                                                 agent=None,
                                                 name='2nd')
                            ])
    assert coup.getPlayerView(game, 0) == view0

    view1 = coup.PlayerView(selfstate=game.players[1],
                            opponents=[
                                coup.PlayerState(cards=2,
                                                 coins=5,
                                                 agent=None,
                                                 name='2nd'),
                                coup.PlayerState(cards=1,
                                                 coins=0,
                                                 agent=None,
                                                 name='0th')
                            ])
    assert coup.getPlayerView(game, 1) == view1

    view2 = coup.PlayerView(selfstate=game.players[2],
                            opponents=[
                                coup.PlayerState(cards=1,
                                                 coins=0,
                                                 agent=None,
                                                 name='0th'),
                                coup.PlayerState(cards=2,
                                                 coins=9,
                                                 agent=None,
                                                 name='1st')
                            ])
    assert coup.getPlayerView(game, 2) == view2
Exemple #3
0
def test_remove_missing_card():
    # This is the edge case of incorrect input, where the function can remove either card.
    player = coup.PlayerState(cards=[Role.CAPTAIN, Role.CONTESSA],
                              coins=0,
                              agent=None,
                              name=None)
    options = [
        player._replace(cards=[Role.CAPTAIN]),
        player._replace(cards=[Role.CONTESSA])
    ]
    assert coup.removeCard(player, Role.ASSASSIN) in options

    player = coup.PlayerState(cards=[Role.DUKE],
                              coins=0,
                              agent=None,
                              name=None)
    assert coup.removeCard(player, Role.AMBASSADOR) == None
Exemple #4
0
def test_remove_card_with_replacement():
    player = coup.PlayerState(cards=[Role.DUKE],
                              coins=0,
                              agent=None,
                              name=None)
    postPlayer = player._replace(cards=[Role.ASSASSIN])
    assert coup.removeCard(player, Role.DUKE,
                           replacement=Role.ASSASSIN) == postPlayer
Exemple #5
0
def test_remove_card():
    player = coup.PlayerState(cards=[Role.CAPTAIN, Role.CONTESSA],
                              coins=0,
                              agent=None,
                              name=None)

    postPlayer = player._replace(cards=[Role.CONTESSA])
    assert postPlayer == coup.removeCard(player, Role.CAPTAIN)

    postPlayer = player._replace(cards=[Role.CAPTAIN])
    assert postPlayer == coup.removeCard(player, Role.CONTESSA)
Exemple #6
0
def test_eligible_captain_actions():
    player = coup.PlayerState(cards=[Role.CAPTAIN],
                              coins=0,
                              agent=None,
                              name=None)
    correct_actions = {Action.INCOME, Action.FOREIGN_AID, Action.STEAL}
    assert coup.findEligibleActions(player) == correct_actions

    player = player._replace(coins=7)
    assert coup.findEligibleActions(player) == correct_actions | {Action.COUP}

    player = player._replace(coins=10)
    assert coup.findEligibleActions(player) == {Action.COUP}
Exemple #7
0
def test_eligible_ambassador_actions():
    player = coup.PlayerState(cards=[Role.AMBASSADOR],
                              coins=0,
                              agent=None,
                              name=None)
    correct_actions = {Action.INCOME, Action.FOREIGN_AID, Action.EXCHANGE}
    assert coup.findEligibleActions(player) == correct_actions

    player = player._replace(coins=7)
    assert coup.findEligibleActions(player) == correct_actions | {Action.COUP}

    player = player._replace(coins=10)
    assert coup.findEligibleActions(player) == {Action.COUP}
Exemple #8
0
def test_eligible_assassin_actions():
    player = coup.PlayerState(cards=[Role.ASSASSIN],
                              coins=0,
                              agent=None,
                              name=None)
    correct_actions = {Action.INCOME, Action.FOREIGN_AID}
    assert coup.findEligibleActions(player) == correct_actions

    player = player._replace(coins=3)
    assert coup.findEligibleActions(player) == correct_actions | {
        Action.ASSASSINATE
    }

    player = player._replace(coins=7)
    assert coup.findEligibleActions(player) == correct_actions | {
        Action.ASSASSINATE, Action.COUP
    }

    player = player._replace(coins=10)
    assert coup.findEligibleActions(player) == {Action.COUP}
Exemple #9
0
def test_can_afford_action(coins, action, expected):
    player = coup.PlayerState(cards=None, coins=coins, agent=None, name=None)
    assert coup.canAffordAction(player, action) == expected
Exemple #10
0

class MockAgent(BaseAgent):
    def selectReaction(self, playerView, actionInfo):
        return False

    def selectKilledCard(self, playerView):
        return playerView.selfstate.cards[-1]

    def selectExchangeCards(self, playerView, cards):
        return cards[:-2]


game = coup.GameState(players=[
    coup.PlayerState(cards=[Role.CAPTAIN],
                     coins=0,
                     agent=MockAgent(),
                     name='0th'),
    coup.PlayerState(cards=[Role.ASSASSIN, Role.CAPTAIN],
                     coins=9,
                     agent=MockAgent(),
                     name='1st'),
    coup.PlayerState(cards=[Role.DUKE, Role.AMBASSADOR],
                     coins=5,
                     agent=MockAgent(),
                     name='2nd')
],
                      deck=[Role.DUKE, Role.CONTESSA])


def test_apply_income():
    new0th = game.players[0]._replace(coins=1)