def test_get_rent_by_name_railroads(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        railroad_1 = Properties.get_property_by_name('Reading Railroad')
        railroad_2 = Properties.get_property_by_name('Pennsylvania Railroad')
        railroad_3 = Properties.get_property_by_name('B. & O. Railroad')
        railroad_4 = Properties.get_property_by_name('Short Line')

        self.assertEqual(Properties.get_rent(property_name='Reading Railroad'), 0,
                         'Bank owns property, rent should be 0')

        # Note: DO NOT JUST MANUALLY CHANGE OWNER IN ANY OTHER INSTANCE BESIDES TESTING!
        railroad_1.property_owner = 'Car'
        self.assertEqual(Properties.get_rent(property_name='Reading Railroad'), 25,
                         'One railroad owned, rent should be 25')

        railroad_2.property_owner = 'Car'
        self.assertEqual(Properties.get_rent(property_name='Reading Railroad'), 50,
                         'Two railroads owned, rent should be 50')

        railroad_3.property_owner = 'Car'
        self.assertEqual(Properties.get_rent(property_name='Reading Railroad'), 100,
                         'Three railroads owned, rent should be 100')

        railroad_4.property_owner = 'Car'
        self.assertEqual(Properties.get_rent(property_name='Reading Railroad'), 200,
                         'Three railroads owned, rent should be 200')
    def test_get_rent_by_name_color_properties(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        boardwalk = Properties.get_property_by_name('Boardwalk')
        park_place = Properties.get_property_by_name('Park Place')

        self.assertEqual(Properties.get_rent(property_name='Boardwalk'), 0, 'Bank owns property, rent should be 0')

        # Note: DO NOT JUST MANUALLY CHANGE OWNER IN ANY OTHER INSTANCE BESIDES TESTING!
        boardwalk.property_owner = 'Battleship'
        self.assertEqual(Properties.get_rent(property_name='Boardwalk'), 50,
                         'Boardwalk is owned, rent should be 50')

        park_place.property_owner = 'Battleship'
        self.assertEqual(Properties.get_rent(property_name='Boardwalk'), 100,
                         'All properties of same color are owned, rent should be 100')

        boardwalk.num_houses = 1

        self.assertEqual(Properties.get_rent(property_name='Boardwalk'), 200,
                         'Boardwalk rent with 1 house should be 200')

        self.assertEqual(Properties.get_rent(property_name='Park Place'), 70,
                         'Park Place rent should be 70 which is doubled still')
    def test_get_property_by_name(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        prop = Properties.get_property_by_name('Boardwalk')
        self.assertEqual(prop.name, 'Boardwalk', 'Property name should be Boardwalk')
        self.assertIsInstance(prop, TileProperty, 'Should be TileProperty class')
    def test_get_rent_by_name_utilities(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        utility_1 = Properties.get_property_by_name('Electric Company')
        utility_2 = Properties.get_property_by_name('Water Works')

        self.assertEqual(Properties.get_rent(property_name='Electric Company', dice_roll=12), 0,
                         'Bank owns property, rent should be 0')

        # Note: DO NOT JUST MANUALLY CHANGE OWNER IN ANY OTHER INSTANCE BESIDES TESTING!
        utility_1.property_owner = 'Iron'
        self.assertEqual(Properties.get_rent(property_name='Electric Company', dice_roll=12), 48,
                         'Dice roll 12, one utility owned, 12 * 4 = 48')

        utility_2.property_owner = 'Iron'
        self.assertEqual(Properties.get_rent(property_name='Electric Company', dice_roll=12), 120,
                         'Dice roll 12, two utilities owned, 12 * 10 = 120')
Exemple #5
0
    def test_property_repair(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        # Resetting game pieces
        Player._game_pieces = [
            'battleship', 'dog', 'iron', 'shoe', 'thimble', 'top hat',
            'wheelbarrow'
        ]
        self.player = Player()

        # Some shopping money
        self.player.action(Actions.RECEIVE_MONEY, 100000)

        self.player.action(Actions.BUY_PROPERTY, 'Boardwalk')
        self.player.action(Actions.BUY_PROPERTY, 'Park Place')

        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.player.action(Actions.BUY_HOUSE, 'Park Place')
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.player.action(Actions.BUY_HOUSE, 'Park Place')
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.player.action(Actions.BUY_HOUSE, 'Park Place')
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.player.action(Actions.BUY_HOUSE, 'Park Place')
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')

        self.assertEqual(
            Properties.get_property_by_name('Boardwalk').num_houses, 5,
            'Boardwalk should be hotel status')

        self.assertEqual(
            Properties.get_property_by_name('Park Place').num_houses, 4,
            'Park Place should have 4 houses')

        # Chance:  4 houses = 25 per house = 100, 1 hotel = 100, total = $200
        # CC: 4 houses = 40 per house = 160, 1 hotel = 115, total = $275
        repair_amount = self.player.action(Actions.PROPERTY_REPAIR, 'Chance')
        self.assertEqual(repair_amount, 200, 'Chance repairs should be 200')

        repair_amount = self.player.action(Actions.PROPERTY_REPAIR,
                                           'Community Chest')
        self.assertEqual(repair_amount, 275,
                         'Community Chest repairs should be 275')
Exemple #6
0
    def test_pay_money(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        # Resetting game pieces
        Player._game_pieces = [
            'battleship', 'dog', 'iron', 'shoe', 'thimble', 'top hat',
            'wheelbarrow'
        ]
        self.player = Player()

        self.player.action(Actions.BUY_PROPERTY, 'Boardwalk')
        self.player.action(Actions.BUY_PROPERTY, 'Park Place')

        # Should have 750 at this point
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.assertEqual(
            self.player.cash, 550,
            'Started at 750, bought a house for 200, should be 550 cash')
        self.assertEqual(
            Properties.get_property_by_name('Boardwalk').num_houses, 1,
            'Num houses should be 1')

        # Paying 1 dollar more than we have in cash. Will have to sell house.
        self.player.action(Actions.PAY_MONEY, 551)
        self.assertEqual(self.player.cash, 99,
                         'Had 1300, sell house for 100, left with 99')
        self.assertEqual(
            Properties.get_property_by_name('Boardwalk').num_houses, 0,
            'Num houses should be 0')

        # cash = 99
        # mortgage Park Place = 350 / 2 = 175
        # mortgage Boardwalk = 400 / 2 = 200
        # total = $474
        money = self.player.action(Actions.PAY_MONEY, 1000)
        self.assertEqual(
            money, 474,
            'Player did not have enough money. The function returned amount of cash on hand'
        )
Exemple #7
0
    def test_buy_properties(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        # Resetting game pieces
        Player._game_pieces = [
            'battleship', 'dog', 'iron', 'shoe', 'thimble', 'top hat',
            'wheelbarrow'
        ]
        self.player = Player()

        self.player.action(Actions.BUY_PROPERTY, 'Boardwalk')
        self.assertEqual(self.player.cash, 1100,
                         'Bought Boardwalk, should have 1100 leftover')

        boardwalk = Properties.get_property_by_name('Boardwalk')
        self.assertEqual(boardwalk.property_owner, self.player.game_piece,
                         'New owner should be player')
Exemple #8
0
    def _buy_property(self, property_name):
        logging.info(
            f'{self.game_piece} is attempting to buy the property {property_name}.'
        )
        property_to_buy = Properties.get_property_by_name(property_name)
        current_owner = property_to_buy.property_owner

        if self.cash > property_to_buy.property_value and current_owner == 'Bank':
            self.cash -= property_to_buy.property_value
            property_to_buy.update_property_owner(self.game_piece)

            logging.info(
                f'{self.game_piece} bought property {property_name} '
                f'for ${property_to_buy.property_value}, has ${self.cash} left.'
            )
            return True

        logging.info(
            f'{self.game_piece} did not buy property {property_name}, has ${self.cash} left.'
        )
        return False
Exemple #9
0
    def test_buy_houses(self):
        # Resetting property instance
        Properties.properties = _init_properties()

        # Resetting game pieces
        Player._game_pieces = [
            'battleship', 'dog', 'iron', 'shoe', 'thimble', 'top hat',
            'wheelbarrow'
        ]
        self.player = Player()

        self.player.action(Actions.BUY_PROPERTY, 'Boardwalk')
        self.player.action(Actions.BUY_PROPERTY, 'Park Place')

        # Should have 750 cash at this point
        self.player.action(Actions.BUY_HOUSE, 'Boardwalk')
        self.assertEqual(
            Properties.get_property_by_name('Boardwalk').num_houses, 1,
            'Got a house on Boardwalk')
        self.assertEqual(self.player.cash, 550,
                         'Had 750, house cost 200, should now have 550')
Exemple #10
0
    def _buy_house(self, property_name):
        logging.info(
            f'{self.game_piece} is attempting to buy a house on {property_name}.'
        )
        properties_owned = Properties.get_properties_by_owner(
            self.game_piece, TileType.PROPERTY)

        if properties_owned:
            if property_name not in [p.name for p in properties_owned]:
                e = 'Property' + property_name + ' not owned by player.'
                logging.error(e)
                raise Exception(e)

        # Get the property to put a house on.
        prop = Properties.get_property_by_name(property_name)

        # Make sure we're dealing with the right type of property first...
        if prop.tile_type != TileType.PROPERTY:
            return 0

        # See if player can afford to buy a house.
        if self.cash < prop.cost_per_house:
            logging.warning(
                f'{self.game_piece} could not afford a house on {property_name}. '
                f'Still has {prop.num_houses} houses.')
            return prop.num_houses

        # Verifying player owns all the properties of that color before buying houses.
        properties_owned_in_same_color = Properties.get_properties_by_owner(
            owner_name=self.game_piece,
            tile_type=prop.tile_type,
            color=prop.color)

        prop_colors = Properties.get_properties_by_color(prop.color)

        if len(properties_owned_in_same_color) != len(prop_colors):
            logging.warning(
                f'{self.game_piece} does not own all properties of the same color '
                f'and cannot purchase a house. Still has {prop.num_houses} houses.'
            )
            return prop.num_houses

        # We also need to verify we don't own too many houses on one property.
        min_houses_in_same_color = min(
            [p.num_houses for p in properties_owned_in_same_color])
        if prop.num_houses > min_houses_in_same_color:
            logging.warning(
                f'{self.game_piece} cannot put a house on this property '
                f'before putting houses on the other properties first.')
            return prop.num_houses

        # If we made it this far, we are eligible to purchase a house on this property.
        # prop.add_house() will make sure we don't add more than 5 properties.
        house_count = prop.add_house()
        if house_count != -1:
            self.cash -= prop.cost_per_house
            logging.info(
                f'{self.game_piece} added a house to'
                f' property {property_name} and now has {prop.num_houses} '
                f'houses for {prop.cost_per_house}, has ${self.cash} left.')
        else:
            logging.warning(
                f'{self.game_piece} tried adding a house but already has too many.'
            )
        return prop.num_houses