def setup(agent_1, agent_2): dice = utils.Dice() roll_mock = Mock() roll_mock.side_effect = cycle([(1, 2), (2, 2)]) dice.roll = roll_mock dice_roll_phase = DiceRoll(dice) square_effect_phase = SquareEffect() bsmt_phase = BSMT() buy_property_phase = BuyProperty() pay_rent_phase = PayRent() auction_phase = Auction() phases = { 'DiceRoll': dice_roll_phase, 'SquareEffect': square_effect_phase, 'BSMT': bsmt_phase, 'BuyProperty': buy_property_phase, 'PayRent': pay_rent_phase, 'Auction': auction_phase, } board = Board() player_1 = Player(1, position=board.property_at(0), agent=agent_1) player_2 = Player(2, position=board.property_at(0), agent=agent_2) players = [player_1, player_2] game_state = GameState(players, board) start_phase = dice_roll_phase context = Context(phases, game_state, start_phase) return context
def test_apply(self): dice = utils.Dice() dice.roll = MagicMock(return_value=(1, 2)) dice_roll_phase = DiceRoll(dice) square_effect_phase = SquareEffect() phases = { 'DiceRoll': dice_roll_phase, 'SquareEffect': square_effect_phase, } board = Board() player_1 = Player(1, position=board.property_at(0)) player_2 = Player(2, position=board.property_at(0)) players = [player_1, player_2] game_state = GameState(players, board) game_phase = dice_roll_phase context = Context(phases, game_state, game_phase) new_context, next_action = context.apply() self.assertTrue(new_context.phase is square_effect_phase) self.assertTrue( new_context.state.current_player.position is board.property_at(3))
def test_unowned_property(self): dice_roll_phase = DiceRoll() square_effect_phase = SquareEffect() buy_property_phase = BuyProperty() pay_rent_phase = PayRent() phases = { 'DiceRoll': dice_roll_phase, 'SquareEffect': square_effect_phase, 'BuyProperty': buy_property_phase, 'PayRent': pay_rent_phase, } board = Board() player_1 = Player(1, position=board.property_at(1)) player_2 = Player(2, position=board.property_at(1)) players = [player_1, player_2] game_state = GameState(players) game_phase = square_effect_phase context = Context(phases, game_state, game_phase) new_context, next_action = context.apply() self.assertTrue(isinstance(new_context.phase, BuyProperty))
def context_factory(agent_1, agent_2, dice_rolls): dice = utils.Dice() roll_mock = Mock() roll_mock.side_effect = iter(dice_rolls) dice.roll = roll_mock dice_roll_phase = DiceRoll(dice) square_effect_phase = SquareEffect() bsmt_phase = BSMT() buy_property_phase = BuyProperty() pay_rent_phase = PayRent() auction_phase = Auction() turn_end_phase = TurnEnd() mortgage_property_phase = MortgageProperty() special_property_phase = SpecialProperty() phases = { 'DiceRoll': dice_roll_phase, 'SquareEffect': square_effect_phase, 'BSMT': bsmt_phase, 'BuyProperty': buy_property_phase, 'MortgageProperty': mortgage_property_phase, 'PayRent': pay_rent_phase, 'Auction': auction_phase, 'SpecialProperty': special_property_phase, 'TurnEnd': turn_end_phase, } board = Board() player_1 = Player(1, amount=1500, position=board.property_at(0), agent=agent_1) player_2 = Player(2, amount=1500, position=board.property_at(0), agent=agent_2) players = [player_1, player_2] game_state = GameState(players, board) start_phase = dice_roll_phase context = Context(phases, game_state, start_phase) return context
def test_change_player_on_regular_roll(self): turn_end_phase = TurnEnd() dice_roll_phase = DiceRoll() phases = { 'DiceRoll': dice_roll_phase, 'TurnEnd': turn_end_phase, } board = Board() regular_roll = ((1, 2), (2, 3)) player_1 = Player(1, position=board.property_at(1), previous_rolls=regular_roll) player_2 = Player(2, position=board.property_at(0)) players = [player_1, player_2] game_state = GameState(players, board) game_phase = turn_end_phase context = Context(phases, game_state, game_phase) new_context, next_action = context.apply() self.assertTrue(new_context.phase is dice_roll_phase) self.assertTrue(new_context.state.current_player is player_2)