Exemplo n.º 1
0
    def test_player_buys_property(self):
        buy_property_phase = BuyProperty()
        bsmt_phase = BSMT()
        phases = {
            'BuyProperty': buy_property_phase,
            'BSMT': bsmt_phase,
        }
        board = Board()
        agent = Agent()
        agent.buy_property = MagicMock(return_value=True)
        current_position = board.property_at(1)
        current_position.cost = 100
        player_1 = Player(1, amount=20, position=current_position, agent=agent)
        player_2 = Player(2)
        players = [player_1, player_2]
        game_state = GameState(players, board)
        game_phase = buy_property_phase
        context = Context(phases, game_state, game_phase)
        bsmt_phase.apply = self.fake_bsmt_cycle(100)

        new_context, next_action = context.apply()

        self.assertTrue(new_context.phase is bsmt_phase)
        self.assertTrue(
            new_context.state.current_player.position.owned_by is player_1)
        self.assertEqual(new_context.state.current_player.amount, 20)
        self.assertEqual(new_context.state.current_player._debt['bank'], 0)
Exemplo n.º 2
0
    def test_apply_player_bankrupt(self):
        bsmt_phase = BSMT()
        pay_rent_phase = PayRent()
        turn_end_phase = TurnEnd()
        phases = {
            'BSMT': bsmt_phase,
            'PayRent': pay_rent_phase,
            'TurnEnd': turn_end_phase,
        }
        board = Board()
        player_1 = Player(1, position=board.property_at(0))
        player_2 = Player(2, amount=10, position=board.property_at(1))
        mediterranean_avenue = board.property_at(1)
        mediterranean_avenue.own(player_1)
        rent = 100
        mediterranean_avenue.rent = MagicMock(return_value=rent)
        players = [player_1, player_2]
        game_state = GameState(players, board)
        game_state.next_player()
        game_phase = pay_rent_phase
        context = Context(phases, game_state, game_phase)
        bsmt_phase.apply = self.fake_bsmt_cycle(rent - 20)

        new_context, next_action = context.apply()

        self.assertTrue(new_context.phase is turn_end_phase)
        self.assertEqual(new_context.state.current_player.amount, 90)