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)
def test_player_declines_buying_property(self): buy_property_phase = BuyProperty() bsmt_phase = BSMT() auction_phase = Auction() phases = { 'BuyProperty': buy_property_phase, 'BSMT': bsmt_phase, 'Auction': auction_phase, } board = Board() agent = Agent() agent.buy_property = MagicMock(return_value=False) player_1 = Player(1, amount=900, position=board.property_at(1), agent=agent) player_2 = Player(2, position=board.property_at(0)) players = [player_1, player_2] game_state = GameState(players, board) game_phase = buy_property_phase context = Context(phases, game_state, game_phase) new_context, next_action = context.apply() self.assertTrue(new_context.phase is auction_phase) self.assertEqual(new_context.state.current_player.amount, 900)
def demo(): # Agent 1 always buys, Agent 2 does not buy properties agent_1 = Agent() agent_1.buy_property = MagicMock(return_value=False) agent_1.auction_property = MagicMock(return_value=0) agent_1.bsmt_decision = MagicMock(return_value=(None, None)) agent_2 = Agent() agent_2.buy_property = MagicMock(return_value=False) agent_2.auction_property = MagicMock(return_value=10) agent_2.bsmt_decision = MagicMock(return_value=(None, None)) context = setup(agent_1, agent_2) print(context.phase) # print(context.state) # will be changed to terminal state based event looping num_moves = 10 action = None for _ in range(5): context, action = context.apply(action) print(context.phase) print(context.state) result = adapter.game_state.parse(context) print(result)