Exemplo n.º 1
0
	def test_eliminate_to_player(self):
		state = GameState(2)
		player_eliminated = state.players[0]
		player_eliminator = state.players[1]

		# Set up players to have some clout
		self.setup_eliminated_player(state)
		self.setup_eliminator_player(state)

		# Move player_eliminated to a square where he would likely lose to the
		# other player (e.g. Marvin Gardens)
		state.apply(GroupOfChanges([
			GameStateChange.change_position(player_eliminated, INDEX[MARVIN_GARDENS],
				state.bank, state.squares)
		]))

		# Eliminate player_eliminated to player_eliminator, and test that
		# player_eliminated's belongings are properly transferred to the
		# player_eliminator and that no other changes are made to the state.
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.eliminate(player_eliminated, player_eliminator, state)]))
		str_after = str(state)
		expected_diff = [
			# Eliminated player stats
			('Position: %d' % INDEX[MARVIN_GARDENS], 'Position: -1'),
			('Cash: 560', 'Cash: 0'),
			('Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, ', ''),
			('1: 3', '1: 0'),
			('2: 1', '2: 0'),
			('100: 1', '100: 0'),
			('Jail free count: 1', 'Jail free count: 0'),
			('Is in game: True', 'Is in game: False'),

			# Eliminator player stats
			('Cash: 250', 'Cash: 1035'),
			('Atlantic Avenue, Ventnor Avenue, Marvin Gardens, Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, ',
			 'Atlantic Avenue, Ventnor Avenue, Marvin Gardens, Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, '),
			('1: 0', '1: 3'),
			('2: 0', '2: 1'),
			('100: 3', '100: 4'),
			('Jail free count: 0', 'Jail free count: 1'),

			# Property stats
			('Num houses: 3', 'Num houses: 0'),      # Oriental Avenue
			('Num houses: 3', 'Num houses: 0'),      # Vermont Avenue
			('Num houses: 3', 'Num houses: 0'),      # Connecticut Avenue

			# Housing stats
			('Houses remaining: 14', 'Houses remaining: 23')  # 9 houses from light blues
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Player was not eliminated properly. The following changes were made to the GameState:')
Exemplo n.º 2
0
	def test_eliminate_to_bank(self):
		state = GameState(1)
		player = state.players[0]

		# Set up player to have some clout
		self.setup_eliminated_player(state)

		# Move player to a square where he would likely lose to the bank (e.g.
		# Luxury Tax)
		state.apply(GroupOfChanges([
			GameStateChange.change_position(player, INDEX[LUXURY_TAX], state.bank,
			state.squares)
		]))

		# Eliminate the player to the bank, and test that the player's belongings
		# are properly transferred to the bank and that no other changes are
		# made to the state.
		str_before = str(state)
		state.apply(GroupOfChanges([
			GameStateChange.eliminate(player, state.bank, state)]))
		str_after = str(state)
		expected_diff = [
			# Player stats
			('Position: %d' % INDEX[LUXURY_TAX], 'Position: -1'),
			('Cash: 560', 'Cash: 0'),
			('Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, ', ''),
			('1: 3', '1: 0'),
			('2: 1', '2: 0'),
			('100: 1', '100: 0'),
			('Jail free count: 1', 'Jail free count: 0'),
			('Is in game: True', 'Is in game: False'),

			# Bank stats
			('Cash: 940', 'Cash: 1725'),
			('Mediterranean Avenue, Baltic Avenue, Reading Railroad, St. Charles Place, Electric Company, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Pennsylvania Avenue, Park Place, Boardwalk, ',
			 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, St. Charles Place, Electric Company, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Pennsylvania Avenue, Park Place, Boardwalk, Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, '),
			('1: 0', '1: 3'),
			('2: 2', '2: 3'),
			('100: 3', '100: 4'),

			# Property stats
			('Num houses: 3', 'Num houses: 0'),      # Oriental Avenue
			('Num houses: 3', 'Num houses: 0'),      # Vermont Avenue
			('Num houses: 3', 'Num houses: 0'),      # Connecticut Avenue
			('Mortgaged: True', 'Mortgaged: False'), # States Avenue
			('Mortgaged: True', 'Mortgaged: False'), # Short Line Railroad

			# Housing stats
			('Houses remaining: 23', 'Houses remaining: 32')  # 9 houses from light blues
		]
		self.assertDiffGameStates(str_before, str_after, expected_diff,
			msg='Player was not eliminated properly. The following changes were made to the GameState:')
    def pay(self, player_from, player_to, amount, state):
        transfer_money = GameStateChange.transfer_money(
            player_from, player_to, amount)
        changes = []

        # Try paying all cash first
        if player_from.cash >= amount:
            changes.append(transfer_money)
            return GroupOfChanges(changes=changes)

        # Mortgage properties until the difference is paid off
        difference = amount - player_from.cash
        i = 0
        while difference > 0 and i < len(player_from.props):
            prop = player_from.props[i]
            i += 1
            if not prop.mortgaged and DefaultDecisionMaker._can_mortgage_property(
                    prop, state):
                mortgage = GameStateChange.mortgage(prop, player_from,
                                                    state.bank)
                changes.append(mortgage)
                difference -= mortgage.change_in_cash[player_from]

        if difference <= 0:
            changes.append(transfer_money)
            return GroupOfChanges(changes=changes)

        # Mortgaging was not enough. Demolish until the difference is paid off
        i = 0
        while difference > 0 and i < len(player_from.props):
            prop = player_from.props[i]
            i += 1
            if prop.num_houses > 0:
                demolition = DefaultDecisionMaker._demolish_from_property_group(
                    prop, state)
                if demolition != None:
                    changes.append(demolition)
                    difference -= demolition.change_in_cash[player_from]

        if difference <= 0:
            changes.append(transfer_money)
            return GroupOfChanges(changes=changes)

        # Player cannot pay it off, so he loses
        return GroupOfChanges(
            changes=[GameStateChange.eliminate(player_from, player_to, state)])
	def pay(self, player_from, player_to, amount, state):
		transfer_money = GameStateChange.transfer_money(player_from, player_to, amount)
		changes = []

		# Try paying all cash first
		if player_from.cash >= amount:
			changes.append(transfer_money)
			return GroupOfChanges(changes=changes)

		# Mortgage properties until the difference is paid off
		difference = amount - player_from.cash
		i = 0
		while difference > 0 and i < len(player_from.props):
			prop = player_from.props[i]
			i += 1
			if not prop.mortgaged and DefaultDecisionMaker._can_mortgage_property(prop, state):
				mortgage = GameStateChange.mortgage(prop, player_from, state.bank)
				changes.append(mortgage)
				difference -= mortgage.change_in_cash[player_from]

		if difference <= 0:
			changes.append(transfer_money)
			return GroupOfChanges(changes=changes)

		# Mortgaging was not enough. Demolish until the difference is paid off
		i = 0
		while difference > 0 and i < len(player_from.props):
			prop = player_from.props[i]
			i += 1
			if prop.num_houses > 0:
				demolition = DefaultDecisionMaker._demolish_from_property_group(prop, state)
				if demolition != None:
					changes.append(demolition)
					difference -= demolition.change_in_cash[player_from]

		if difference <= 0:
			changes.append(transfer_money)
			return GroupOfChanges(changes=changes)

		# Player cannot pay it off, so he loses
		return GroupOfChanges(changes=[GameStateChange.eliminate(player_from, player_to, state)])
Exemplo n.º 5
0
    def test_eliminate_to_player(self):
        state = GameState(2)
        player_eliminated = state.players[0]
        player_eliminator = state.players[1]

        # Set up players to have some clout
        self.setup_eliminated_player(state)
        self.setup_eliminator_player(state)

        # Move player_eliminated to a square where he would likely lose to the
        # other player (e.g. Marvin Gardens)
        state.apply(
            GroupOfChanges([
                GameStateChange.change_position(player_eliminated,
                                                INDEX[MARVIN_GARDENS],
                                                state.bank, state.squares)
            ]))

        # Eliminate player_eliminated to player_eliminator, and test that
        # player_eliminated's belongings are properly transferred to the
        # player_eliminator and that no other changes are made to the state.
        str_before = str(state)
        state.apply(
            GroupOfChanges([
                GameStateChange.eliminate(player_eliminated, player_eliminator,
                                          state)
            ]))
        str_after = str(state)
        expected_diff = [
            # Eliminated player stats
            ('Position: %d' % INDEX[MARVIN_GARDENS], 'Position: -1'),
            ('Cash: 560', 'Cash: 0'),
            ('Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, ',
             ''),
            ('1: 3', '1: 0'),
            ('2: 1', '2: 0'),
            ('100: 1', '100: 0'),
            ('Jail free count: 1', 'Jail free count: 0'),
            ('Is in game: True', 'Is in game: False'),

            # Eliminator player stats
            ('Cash: 250', 'Cash: 1035'),
            ('Atlantic Avenue, Ventnor Avenue, Marvin Gardens, Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, ',
             'Atlantic Avenue, Ventnor Avenue, Marvin Gardens, Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, '
             ),
            ('1: 0', '1: 3'),
            ('2: 0', '2: 1'),
            ('100: 3', '100: 4'),
            ('Jail free count: 0', 'Jail free count: 1'),

            # Property stats
            ('Num houses: 3', 'Num houses: 0'),  # Oriental Avenue
            ('Num houses: 3', 'Num houses: 0'),  # Vermont Avenue
            ('Num houses: 3', 'Num houses: 0'),  # Connecticut Avenue

            # Housing stats
            ('Houses remaining: 14', 'Houses remaining: 23'
             )  # 9 houses from light blues
        ]
        self.assertDiffGameStates(
            str_before,
            str_after,
            expected_diff,
            msg=
            'Player was not eliminated properly. The following changes were made to the GameState:'
        )
Exemplo n.º 6
0
    def test_eliminate_to_bank(self):
        state = GameState(1)
        player = state.players[0]

        # Set up player to have some clout
        self.setup_eliminated_player(state)

        # Move player to a square where he would likely lose to the bank (e.g.
        # Luxury Tax)
        state.apply(
            GroupOfChanges([
                GameStateChange.change_position(player, INDEX[LUXURY_TAX],
                                                state.bank, state.squares)
            ]))

        # Eliminate the player to the bank, and test that the player's belongings
        # are properly transferred to the bank and that no other changes are
        # made to the state.
        str_before = str(state)
        state.apply(
            GroupOfChanges(
                [GameStateChange.eliminate(player, state.bank, state)]))
        str_after = str(state)
        expected_diff = [
            # Player stats
            ('Position: %d' % INDEX[LUXURY_TAX], 'Position: -1'),
            ('Cash: 560', 'Cash: 0'),
            ('Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, ',
             ''),
            ('1: 3', '1: 0'),
            ('2: 1', '2: 0'),
            ('100: 1', '100: 0'),
            ('Jail free count: 1', 'Jail free count: 0'),
            ('Is in game: True', 'Is in game: False'),

            # Bank stats
            ('Cash: 940', 'Cash: 1725'),
            ('Mediterranean Avenue, Baltic Avenue, Reading Railroad, St. Charles Place, Electric Company, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Pennsylvania Avenue, Park Place, Boardwalk, ',
             'Mediterranean Avenue, Baltic Avenue, Reading Railroad, St. Charles Place, Electric Company, Virginia Avenue, Pennsylvania Railroad, St. James Place, Tennessee Avenue, New York Avenue, Kentucky Avenue, Indiana Avenue, Illinois Avenue, B. & O. Railroad, Atlantic Avenue, Ventnor Avenue, Water Works, Marvin Gardens, Pacific Avenue, North Carolina Avenue, Pennsylvania Avenue, Park Place, Boardwalk, Oriental Avenue, Vermont Avenue, Connecticut Avenue, States Avenue, Short Line Railroad, '
             ),
            ('1: 0', '1: 3'),
            ('2: 2', '2: 3'),
            ('100: 3', '100: 4'),

            # Property stats
            ('Num houses: 3', 'Num houses: 0'),  # Oriental Avenue
            ('Num houses: 3', 'Num houses: 0'),  # Vermont Avenue
            ('Num houses: 3', 'Num houses: 0'),  # Connecticut Avenue
            ('Mortgaged: True', 'Mortgaged: False'),  # States Avenue
            ('Mortgaged: True', 'Mortgaged: False'),  # Short Line Railroad

            # Housing stats
            ('Houses remaining: 23', 'Houses remaining: 32'
             )  # 9 houses from light blues
        ]
        self.assertDiffGameStates(
            str_before,
            str_after,
            expected_diff,
            msg=
            'Player was not eliminated properly. The following changes were made to the GameState:'
        )