def test_demolish_house(self): state = GameState(1) # Set up a player to own a property with 1 house player = state.players[0] park_place = state.squares[INDEX[PARK_PLACE]] boardwalk = state.squares[INDEX[BOARDWALK]] state.apply(GroupOfChanges([ GameStateChange.buy_property(park_place, player, state.bank)])) state.apply(GroupOfChanges([ GameStateChange.buy_property(boardwalk, player, state.bank)])) state.apply(GroupOfChanges([ GameStateChange.build(boardwalk, state)])) # Test applying the changes by comparing differences in their string # encodings. Ensure that no additional changes were made to the state. str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.demolish(boardwalk, state)])) str_after = str(state) expected_diff = [ ('Cash: 550', 'Cash: 650'), # player cash ('Cash: 950', 'Cash: 850'), # bank cash ('Num houses: 1', 'Num houses: 0'), ('Houses remaining: 31', 'Houses remaining: 32') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='House demolition was not applied correctly')
def test_buy_property_from_something(self): state = GameState(1) player = state.players[0] # Set up player with some properties (two of the three greens) changes = [] for prop_name in [PACIFIC_AVENUE, PENNSYLVANIA_AVENUE]: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Test buying North Carolina Avenue str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.buy_property(state.squares[INDEX[NORTH_CAROLINA_AVENUE]], player, state.bank) ])) str_after = str(state) expected_diff = [ # Player 1 stats ('Cash: 880', 'Cash: 580'), ('Pacific Avenue, Pennsylvania Avenue, ', 'Pacific Avenue, Pennsylvania Avenue, North Carolina Avenue, '), ('6: 2', '6: 3'), # Bank stats ('Cash: 620', 'Cash: 920'), ('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, North Carolina Avenue, Short Line Railroad, Park Place, Boardwalk, ', 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, Short Line Railroad, Park Place, Boardwalk, '), ('6: 1', '6: 0') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='North Carolina Avenue was not purchased properly')
def test_demolish_house(self): state = GameState(1) # Set up a player to own a property with 1 house player = state.players[0] park_place = state.squares[INDEX[PARK_PLACE]] boardwalk = state.squares[INDEX[BOARDWALK]] state.apply( GroupOfChanges( [GameStateChange.buy_property(park_place, player, state.bank)])) state.apply( GroupOfChanges( [GameStateChange.buy_property(boardwalk, player, state.bank)])) state.apply(GroupOfChanges([GameStateChange.build(boardwalk, state)])) # Test applying the changes by comparing differences in their string # encodings. Ensure that no additional changes were made to the state. str_before = str(state) state.apply( GroupOfChanges([GameStateChange.demolish(boardwalk, state)])) str_after = str(state) expected_diff = [ ('Cash: 550', 'Cash: 650'), # player cash ('Cash: 950', 'Cash: 850'), # bank cash ('Num houses: 1', 'Num houses: 0'), ('Houses remaining: 31', 'Houses remaining: 32') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='House demolition was not applied correctly')
def test_transfer_property(self): state = GameState(2) player1 = state.players[0] player2 = state.players[1] # Set up player1 to have the purples, player2 to have the railroads purples = [MEDITERRANEAN_AVENUE, BALTIC_AVENUE] changes = [] for prop_name in purples: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player1, state.bank)) state.apply(GroupOfChanges(changes)) railroads = [ READING_RAILROAD, PENNSYLVANIA_RAILROAD, B_AND_O_RAILROAD, SHORT_LINE_RAILROAD ] changes = [] for prop_name in railroads: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player2, state.bank)) state.apply(GroupOfChanges(changes)) # Transfer property str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.transfer_property( player1, player2, state.squares[INDEX[BALTIC_AVENUE]]) ])) str_after = str(state) expected_diff = [ # Player 1 stats ('Mediterranean Avenue, Baltic Avenue, ', 'Mediterranean Avenue, ' ), ('0: 2', '0: 1'), # Player 2 properties ('Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Short Line Railroad, ', 'Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Short Line Railroad, Baltic Avenue, ' ), ('0: 0', '0: 1') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Baltic Avenue was not transferred properly')
def test_buy_property_from_nothing(self): state = GameState(1) player = state.players[0] # Test buying Pacific Avenue str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.buy_property( state.squares[INDEX[PACIFIC_AVENUE]], player, state.bank) ])) str_after = str(state) expected_diff = [ # Player 1 stats ('Cash: 1500', 'Cash: 1200'), ('', 'Pacific Avenue, '), ('6: 0', '6: 1'), # Bank stats ('Cash: 0', 'Cash: 300'), ('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, Short Line Railroad, Park Place, Boardwalk, ', 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, North Carolina Avenue, Pennsylvania Avenue, Short Line Railroad, Park Place, Boardwalk, ' ), ('6: 3', '6: 2') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Pacific Avenue was not purchased properly')
def test_mortgage(self): state = GameState(1) player = state.players[0] # Set up player to own a railroad state.apply( GroupOfChanges([ GameStateChange.buy_property( state.squares[INDEX[PENNSYLVANIA_RAILROAD]], player, state.bank) ])) # Test mortgage str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.mortgage( state.squares[INDEX[PENNSYLVANIA_RAILROAD]], state) ])) str_after = str(state) expected_diff = [ # Player cash ('Cash: 1300', 'Cash: 1400'), # Bank cash ('Cash: 200', 'Cash: 100'), # Pennsylvania Railroad stats ('Mortgaged: False', 'Mortgaged: True') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Pennsylvania Railroad was not mortgaged properly')
def test_build_house(self): state = GameState(1) # Set up a player to own oranges with no houses player = state.players[0] oranges = [ST_JAMES_PLACE, TENNESSEE_AVENUE, NEW_YORK_AVENUE] changes = [] for prop_name in oranges: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Test house build str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[NEW_YORK_AVENUE]], state) ])) str_after = str(state) expected_diff = [ ('Cash: 940', 'Cash: 840'), # player cash ('Cash: 560', 'Cash: 660'), # bank cash ('Num houses: 0', 'Num houses: 1'), # new york avenue ('Houses remaining: 32', 'Houses remaining: 31') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='House build was not applied properly')
def test_build_house(self): state = GameState(1) # Set up a player to own oranges with no houses player = state.players[0] oranges = [ST_JAMES_PLACE, TENNESSEE_AVENUE, NEW_YORK_AVENUE] changes = [] for prop_name in oranges: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Test house build str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[NEW_YORK_AVENUE]], state) ])) str_after = str(state) expected_diff = [ ('Cash: 940', 'Cash: 840'), # player cash ('Cash: 560', 'Cash: 660'), # bank cash ('Num houses: 0', 'Num houses: 1'), # new york avenue ('Houses remaining: 32', 'Houses remaining: 31') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='House build was not applied properly')
def test_unmortgage(self): state = GameState(1) player = state.players[0] # Set up player to own a mortgaged utility state.apply(GroupOfChanges([ GameStateChange.buy_property(state.squares[INDEX[ELECTRIC_COMPANY]], player, state.bank, mortgaged=True) ])) # Test unmortgage str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.unmortgage(state.squares[INDEX[ELECTRIC_COMPANY]], state) ])) str_after = str(state) expected_diff = [ # Player cash ('Cash: 1425', 'Cash: 1342'), # Bank cash ('Cash: 75', 'Cash: 158'), # Electric Company stats ('Mortgaged: True', 'Mortgaged: False') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Electric Company was not unmortgaged properly')
def test_mortgage(self): state = GameState(1) player = state.players[0] # Set up player to own a railroad state.apply(GroupOfChanges([ GameStateChange.buy_property(state.squares[INDEX[PENNSYLVANIA_RAILROAD]], player, state.bank) ])) # Test mortgage str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.mortgage(state.squares[INDEX[PENNSYLVANIA_RAILROAD]], state) ])) str_after = str(state) expected_diff = [ # Player cash ('Cash: 1300', 'Cash: 1400'), # Bank cash ('Cash: 200', 'Cash: 100'), # Pennsylvania Railroad stats ('Mortgaged: False', 'Mortgaged: True') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Pennsylvania Railroad was not mortgaged properly')
def test_buy_property_mortgaged(self): state = GameState(1) player = state.players[0] # Test buying Pennsylvania Avenue mortgaged str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.buy_property(state.squares[INDEX[PENNSYLVANIA_AVENUE]], player, state.bank, mortgaged=True) ])) str_after = str(state) expected_diff = [ # Player stats ('Cash: 1500', 'Cash: 1340'), ('', 'Pennsylvania Avenue, '), ('6: 0', '6: 1'), # Bank stats ('Cash: 0', 'Cash: 160'), ('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, Short Line Railroad, Park Place, Boardwalk, ', 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, Short Line Railroad, Park Place, Boardwalk, '), ('6: 3', '6: 2'), # Pennsylvania Avenue stats ('Mortgaged: False', 'Mortgaged: True') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Pennsylvania Avenue was not mortgaged properly')
def setup_eliminator_player(self, state): player = state.players[1] yellows = [ATLANTIC_AVENUE, VENTNOR_AVENUE, MARVIN_GARDENS] railroads = [READING_RAILROAD, PENNSYLVANIA_RAILROAD, B_AND_O_RAILROAD] changes = [] # Add to player's initial $1500 to bring him to $3000 cash changes.append(GameStateChange.transfer_money(state.bank, player, 1500)) # Give player properties for prop_name in yellows + railroads: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Build to 3 house level on yellows for count in range(0, 3): for prop_name in yellows: state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ]))
def buy_or_deny(self, player, prop, state): if player.cash >= prop.price: return GroupOfChanges(changes=[ GameStateChange.buy_property(prop, player, state.bank) ]) else: return GroupOfChanges()
def setup_eliminated_player(self, state): player = state.players[0] light_blues = [ORIENTAL_AVENUE, VERMONT_AVENUE, CONNECTICUT_AVENUE] # Give player properties changes = [] for prop_name in light_blues: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Build to 3 house level on light blues for count in range(0, 3): for prop_name in light_blues: state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Give player some other properties mortgaged changes = [] other_props = [STATES_AVENUE, SHORT_LINE_RAILROAD] for prop_name in other_props: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank, mortgaged=True)) state.apply(GroupOfChanges(changes)) # Give player a Jail Free card changes = [] deck = state.decks[CHANCE_CARD] while deck.peek() != LMBDA_GET_OUT_OF_JAIL_FREE: deck.draw() changes.append(GameStateChange.draw_card( deck, player)) # draw Jail Free card state.apply(GroupOfChanges(changes))
def test_transfer_property(self): state = GameState(2) player1 = state.players[0] player2 = state.players[1] # Set up player1 to have the purples, player2 to have the railroads purples = [MEDITERRANEAN_AVENUE, BALTIC_AVENUE] changes = [] for prop_name in purples: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player1, state.bank)) state.apply(GroupOfChanges(changes)) railroads = [READING_RAILROAD, PENNSYLVANIA_RAILROAD, B_AND_O_RAILROAD, SHORT_LINE_RAILROAD] changes = [] for prop_name in railroads: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player2, state.bank)) state.apply(GroupOfChanges(changes)) # Transfer property str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.transfer_property(player1, player2, state.squares[INDEX[BALTIC_AVENUE]]) ])) str_after = str(state) expected_diff = [ # Player 1 stats ('Mediterranean Avenue, Baltic Avenue, ', 'Mediterranean Avenue, '), ('0: 2', '0: 1'), # Player 2 properties ('Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Short Line Railroad, ', 'Reading Railroad, Pennsylvania Railroad, B. & O. Railroad, Short Line Railroad, Baltic Avenue, '), ('0: 0', '0: 1') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Baltic Avenue was not transferred properly')
def test_buy_property_from_something(self): state = GameState(1) player = state.players[0] # Set up player with some properties (two of the three greens) changes = [] for prop_name in [PACIFIC_AVENUE, PENNSYLVANIA_AVENUE]: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Test buying North Carolina Avenue str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.buy_property( state.squares[INDEX[NORTH_CAROLINA_AVENUE]], player, state.bank) ])) str_after = str(state) expected_diff = [ # Player 1 stats ('Cash: 880', 'Cash: 580'), ('Pacific Avenue, Pennsylvania Avenue, ', 'Pacific Avenue, Pennsylvania Avenue, North Carolina Avenue, '), ('6: 2', '6: 3'), # Bank stats ('Cash: 620', 'Cash: 920'), ('Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, North Carolina Avenue, Short Line Railroad, Park Place, Boardwalk, ', 'Mediterranean Avenue, Baltic Avenue, Reading Railroad, Oriental Avenue, Vermont Avenue, Connecticut Avenue, St. Charles Place, Electric Company, States Avenue, 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, Short Line Railroad, Park Place, Boardwalk, ' ), ('6: 1', '6: 0') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='North Carolina Avenue was not purchased properly')
def setup_eliminated_player(self, state): player = state.players[0] light_blues = [ORIENTAL_AVENUE, VERMONT_AVENUE, CONNECTICUT_AVENUE] # Give player properties changes = [] for prop_name in light_blues: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Build to 3 house level on light blues for count in range(0, 3): for prop_name in light_blues: state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Give player some other properties mortgaged changes = [] other_props = [STATES_AVENUE, SHORT_LINE_RAILROAD] for prop_name in other_props: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank, mortgaged=True)) state.apply(GroupOfChanges(changes)) # Give player a Jail Free card changes = [] deck = state.decks[CHANCE_CARD] while deck.peek() != LMBDA_GET_OUT_OF_JAIL_FREE: deck.draw() changes.append(GameStateChange.draw_card(deck, player)) # draw Jail Free card state.apply(GroupOfChanges(changes))
def test_build_hotel(self): state = GameState(1) # Set up a player to own reds with 4 houses each player = state.players[0] reds = [KENTUCKY_AVENUE, INDIANA_AVENUE, ILLINOIS_AVENUE] state.apply( GroupOfChanges([ GameStateChange.transfer_money( state.bank, player, 1130) # needs $1130 more to buy everything ])) changes = [] for prop_name in reds: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) for count in range(0, 4): for prop_name in reds: state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Test hotel build str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[INDIANA_AVENUE]], state) ])) str_after = str(state) expected_diff = [('Cash: 150', 'Cash: 0'), ('Cash: 1350', 'Cash: 1500'), ('Num houses: 4', 'Num houses: 5'), ('Houses remaining: 20', 'Houses remaining: 24'), ('Hotels remaining: 12', 'Hotels remaining: 11')] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Hotel build was not applied properly')
def test_demolish_hotel(self): state = GameState(1) # Set up a player to own a property group with hotels on all properties player = state.players[0] state.apply( GroupOfChanges([ GameStateChange.transfer_money(state.bank, player, 440) ])) # Needs 440 more to buy everything pinks = [ST_CHARLES_PLACE, STATES_AVENUE, VIRGINIA_AVENUE] changes = [] for prop_name in pinks: changes.append( GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) for i in range(0, 5): for prop_name in pinks: state.apply( GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Test demolition str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.demolish( state.squares[INDEX[ST_CHARLES_PLACE]], state) ])) str_after = str(state) expected_diff = [ ('Cash: 0', 'Cash: 50'), # player cash ('Cash: 1500', 'Cash: 1450'), # bank cash ('Num houses: 5', 'Num houses: 4'), # st charles place ('Houses remaining: 32', 'Houses remaining: 28'), ('Hotels remaining: 9', 'Hotels remaining: 10') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Hotel demolition was not applied correctly')
def test_build_hotel(self): state = GameState(1) # Set up a player to own reds with 4 houses each player = state.players[0] reds = [KENTUCKY_AVENUE, INDIANA_AVENUE, ILLINOIS_AVENUE] state.apply(GroupOfChanges([ GameStateChange.transfer_money(state.bank, player, 1130) # needs $1130 more to buy everything ])) changes = [] for prop_name in reds: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) for count in range(0, 4): for prop_name in reds: state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Test hotel build str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[INDIANA_AVENUE]], state) ])) str_after = str(state) expected_diff = [ ('Cash: 150', 'Cash: 0'), ('Cash: 1350', 'Cash: 1500'), ('Num houses: 4', 'Num houses: 5'), ('Houses remaining: 20', 'Houses remaining: 24'), ('Hotels remaining: 12', 'Hotels remaining: 11') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Hotel build was not applied properly')
def setup_eliminator_player(self, state): player = state.players[1] yellows = [ATLANTIC_AVENUE, VENTNOR_AVENUE, MARVIN_GARDENS] railroads = [READING_RAILROAD, PENNSYLVANIA_RAILROAD, B_AND_O_RAILROAD] changes = [] # Add to player's initial $1500 to bring him to $3000 cash changes.append(GameStateChange.transfer_money(state.bank, player, 1500)) # Give player properties for prop_name in yellows + railroads: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) # Build to 3 house level on yellows for count in range(0, 3): for prop_name in yellows: state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ]))
def test_unmortgage(self): state = GameState(1) player = state.players[0] # Set up player to own a mortgaged utility state.apply( GroupOfChanges([ GameStateChange.buy_property( state.squares[INDEX[ELECTRIC_COMPANY]], player, state.bank, mortgaged=True) ])) # Test unmortgage str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.unmortgage( state.squares[INDEX[ELECTRIC_COMPANY]], state) ])) str_after = str(state) expected_diff = [ # Player cash ('Cash: 1425', 'Cash: 1342'), # Bank cash ('Cash: 75', 'Cash: 158'), # Electric Company stats ('Mortgaged: True', 'Mortgaged: False') ] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Electric Company was not unmortgaged properly')
def test_demolish_hotel(self): state = GameState(1) # Set up a player to own a property group with hotels on all properties player = state.players[0] state.apply(GroupOfChanges([ GameStateChange.transfer_money(state.bank, player, 440)])) # Needs 440 more to buy everything pinks = [ST_CHARLES_PLACE, STATES_AVENUE, VIRGINIA_AVENUE] changes = [] for prop_name in pinks: changes.append(GameStateChange.buy_property(state.squares[INDEX[prop_name]], player, state.bank)) state.apply(GroupOfChanges(changes)) for i in range(0, 5): for prop_name in pinks: state.apply(GroupOfChanges([ GameStateChange.build(state.squares[INDEX[prop_name]], state) ])) # Test demolition str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.demolish(state.squares[INDEX[ST_CHARLES_PLACE]], state) ])) str_after = str(state) expected_diff = [ ('Cash: 0', 'Cash: 50'), # player cash ('Cash: 1500', 'Cash: 1450'), # bank cash ('Num houses: 5', 'Num houses: 4'), # st charles place ('Houses remaining: 32', 'Houses remaining: 28'), ('Hotels remaining: 9', 'Hotels remaining: 10') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Hotel demolition was not applied correctly')
def buy_or_deny(self, player, prop, state): if player.cash >= prop.price: return GroupOfChanges(changes=[GameStateChange.buy_property(prop, player, state.bank)]) else: return GroupOfChanges()