def test_change_position_from_middle(self): state = GameState(1) player = state.players[0] # Set up player's initial position at Community Chest 2 state.apply( GroupOfChanges([ GameStateChange.change_position(player, INDEX[COMMUNITY_CHEST_2], state.bank, state.squares) ])) # Test player changing position to Water Works str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.change_position(player, INDEX[WATER_WORKS], state.bank, state.squares) ])) str_after = str(state) expected_diff = [('Position: %d' % INDEX[COMMUNITY_CHEST_2], 'Position: %d' % INDEX[WATER_WORKS])] self.assertDiffGameStates( str_before, str_after, expected_diff, msg= 'Player was not moved from Community Chest 2 to Water Works properly' )
def test_change_position_landing_on_go(self): state = GameState(1) player = state.players[0] # Set up player's initial position at Short Line Railroad state.apply( GroupOfChanges([ GameStateChange.change_position(player, INDEX[SHORT_LINE_RAILROAD], state.bank, state.squares) ])) # Test player changing position to Go str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.change_position(player, INDEX[GO], state.bank, state.squares) ])) str_after = str(state) expected_diff = [ # Player stats ('Position: %d' % INDEX[SHORT_LINE_RAILROAD], 'Position: %d' % INDEX[GO]), ('Cash: 1500', 'Cash: 1700'), # Bank stats ('Cash: 0', 'Cash: -200') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Player did not pass Go properly')
def test_change_position_landing_on_go(self): state = GameState(1) player = state.players[0] # Set up player's initial position at Short Line Railroad state.apply(GroupOfChanges([ GameStateChange.change_position(player, INDEX[SHORT_LINE_RAILROAD], state.bank, state.squares) ])) # Test player changing position to Go str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.change_position(player, INDEX[GO], state.bank, state.squares) ])) str_after = str(state) expected_diff = [ # Player stats ('Position: %d' % INDEX[SHORT_LINE_RAILROAD], 'Position: %d' % INDEX[GO]), ('Cash: 1500', 'Cash: 1700'), # Bank stats ('Cash: 0', 'Cash: -200') ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Player did not pass Go properly')
def _take_turn(self, player, roll): position = (player.position + roll) % NUM_SQUARES self._state.apply(GroupOfChanges([GameStateChange.change_position(player, position, self._state.bank, self._state.squares)])) self._state.apply(self._state.squares[position].landed(player, roll, self._state)) self._notify_all() self._wait()
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:')
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 _advance_to_square( player, square_index, roll, state): # TODO: Account for GO money when passing GO # Apply the player's new position now so they are aware of their position state.apply( Card._group_from_single_change( GameStateChange.change_position(player, square_index, state.bank, state.squares))) square = state.squares[square_index] if isinstance(square, NonColorProperty): return square.landed(player, roll, state, from_card=True) else: return square.landed(player, roll, state)
def _take_turn(self, player, roll): position = (player.position + roll) % NUM_SQUARES self._state.apply( GroupOfChanges([ GameStateChange.change_position(player, position, self._state.bank, self._state.squares) ])) self._state.apply(self._state.squares[position].landed( player, roll, self._state)) self._notify_all() self._wait()
def test_change_position_from_middle(self): state = GameState(1) player = state.players[0] # Set up player's initial position at Community Chest 2 state.apply(GroupOfChanges([ GameStateChange.change_position(player, INDEX[COMMUNITY_CHEST_2], state.bank, state.squares) ])) # Test player changing position to Water Works str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.change_position(player, INDEX[WATER_WORKS], state.bank, state.squares) ])) str_after = str(state) expected_diff = [ ('Position: %d' % INDEX[COMMUNITY_CHEST_2], 'Position: %d' % INDEX[WATER_WORKS]) ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Player was not moved from Community Chest 2 to Water Works properly')
def test_change_position_from_start(self): state = GameState(1) player = state.players[0] # Test player changing position from initial position (Go) to first # Chance square chance1 = INDEX[CHANCE_1] str_before = str(state) state.apply(GroupOfChanges([ GameStateChange.change_position(player, chance1, state.bank, state.squares) ])) str_after = str(state) expected_diff = [ ('Position: 0', 'Position: %d' % chance1) ] self.assertDiffGameStates(str_before, str_after, expected_diff, msg='Player was not moved to first Chance square properly')
def test_change_position_from_start(self): state = GameState(1) player = state.players[0] # Test player changing position from initial position (Go) to first # Chance square chance1 = INDEX[CHANCE_1] str_before = str(state) state.apply( GroupOfChanges([ GameStateChange.change_position(player, chance1, state.bank, state.squares) ])) str_after = str(state) expected_diff = [('Position: 0', 'Position: %d' % chance1)] self.assertDiffGameStates( str_before, str_after, expected_diff, msg='Player was not moved to first Chance square properly')
def _go_back_three_spaces(player, state): change_position = GameStateChange.change_position( player, player.position - 3, state.bank, state.squares) return GroupOfChanges([change_position])
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:' )
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:' )