Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
End of lines added and using 'is not' instead of 'not is'
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonfmir committed Sep 4, 2017
1 parent d7bf19b commit b5762fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
3 changes: 2 additions & 1 deletion aimmo-game/simulation/avatar/avatar_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ def move(self, move_direction, world_map):
self.NE_horizon += move_direction
self.NW_horizon += move_direction
self.SE_horizon += move_direction
self.SW_horizon += move_direction
self.SW_horizon += move_direction

17 changes: 7 additions & 10 deletions aimmo-game/simulation/world_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def clear_updates(self):
}

# Player updates.

def create_player(self, player_data):
# Player data: {id, x, y, rotation, health, score, appearance?}
self.players["create"].append(player_data)
Expand All @@ -66,7 +65,6 @@ def update_player(self, player_update):
self.players["update"].append(player_update)

# Map features updates.

def create_map_feature(self, map_feature, map_feature_data):
self.map_features[map_feature]["create"].append(map_feature_data)

Expand All @@ -75,7 +73,6 @@ def delete_map_feature(self, map_feature, map_feature_id):

# Refresh the world state. Basically gather information from the avatar manager
# and the world map and organise it.

def refresh(self):
def player_dict(avatar):
return {
Expand Down Expand Up @@ -109,10 +106,10 @@ def map_feature_dict(map_feature):
avatar_view.reveal_all_cells(game_state.world_map)
avatar_view.is_empty = False

# Creation
# Creation.
for cell in avatar_view.cells_to_reveal:
# There is an avatar.
if not cell.avatar is None:
if cell.avatar is not None:
self.create_player(player_dict(cell.avatar))
# Cell is an obstacle.
if not cell.habitable:
Expand All @@ -121,17 +118,17 @@ def map_feature_dict(map_feature):
if cell.generates_score:
self.create_map_feature(MapFeature.SCORE_POINT.value, map_feature_dict(cell))

# Updates
# Updates.
for cell in avatar_view.cells_in_view:
if not cell.add_to_scene is None:
if cell.add_to_scene is not None:
self.create_map_feature(cell.add_to_scene.value, map_feature_dict(cell))
if not cell.remove_from_scene is None:
if cell.remove_from_scene is not None:
self.delete_map_feature(cell.remove_from_scene.value, map_feature_dict(cell))

# Deletion
# Deletion.
for cell in avatar_view.cells_to_clear:
# There is an avatar.
if not cell.avatar is None:
if cell.avatar is not None:
self.delete_player(player_dict(cell.avatar))
# Cell is an obstacle.
if not cell.habitable:
Expand Down
9 changes: 1 addition & 8 deletions aimmo-game/tests/test_simulation/avatar/test_avatar_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ def get_cell(self, location):


class TestAvatarView(TestCase):
def setUp(self):
pass

# Test 'location_in_view'

def test_knows_when_a_location_is_inside_the_view(self):
avatar_view = AvatarView(Location(0, 0), 2)
self.assertTrue(avatar_view.location_in_view(Location(0, 0)))
Expand All @@ -53,7 +49,6 @@ def test_knows_when_a_location_is_outside_the_view(self):
self.assertFalse(avatar_view.location_in_view(Location(-4, -4)))

# Test 'cells_in_rectangle'

def test_returns_one_cell_when_world_map_is_empty(self):
mock_world_map = MockWorldMap(0, 0, 0, 0)
cells_in_rectangle = AvatarView.cells_in_rectangle(Location(-3, 4), Location(5, -6), mock_world_map)
Expand All @@ -80,15 +75,13 @@ def test_returns_correct_number_of_cells_when_the_rectangle_is_partially_inisde_
self.assertEqual(len(cells_in_rectagle), 1)

# Test 'reveal_all_cells'

def test_reveals_all_cells(self):
mock_world_map = MockWorldMap(-25, -30, 30, 40)
avatar_view = AvatarView(Location(-4, -8), 2)
avatar_view.reveal_all_cells(mock_world_map)
self.assertEqual(len(avatar_view.cells_to_reveal), 16)

# Test 'move'

def test_correct_number_of_cells_to_clear_reveal_and_in_view(self):
mock_world_map = MockWorldMap(-10, -10, 10, 10)
avatar_view = AvatarView(Location(0, 0), 2)
Expand Down Expand Up @@ -122,4 +115,4 @@ def test_chain_of_moves(self):
avatar_view.move(SOUTH, mock_world_map)
avatar_view.move(WEST, mock_world_map)
avatar_view.move(NORTH, mock_world_map)
self.assertEqual(avatar_view.cells_in_view, initial_cells_in_view)
self.assertEqual(avatar_view.cells_in_view, initial_cells_in_view)

0 comments on commit b5762fe

Please sign in to comment.