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_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_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_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_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_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 bid_hotel_demolitions(self, player, highest_bid, props_to_demolish_on, state): bid = player.cash / 2 prop_to_demolish_on = props_to_demolish_on[0] hotel_demolition = GameStateChange.demolish(prop, state) house_builds = [GameStateChange.build(prop, state) ] * NUM_HOUSES_BEFORE_HOTEL return GroupOfChanges([hotel_demolition] + house_builds)
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 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 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 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_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 bid_hotel_builds(self, player, highest_bid, props_to_build_on, state): bid = player.cash / 2 prop_to_build_on = props_to_build_on[0] hotel_build = GameStateChange.build(prop, state) return GroupOfChanges([hotel_build])
def bid_hotel_demolitions(self, player, highest_bid, props_to_demolish_on, state): bid = player.cash / 2 prop_to_demolish_on = props_to_demolish_on[0] hotel_demolition = GameStateChange.demolish(prop, state) house_builds = [GameStateChange.build(prop, state)] * NUM_HOUSES_BEFORE_HOTEL return GroupOfChanges([hotel_demolition] + house_builds)