Repository: ocadotechnology/aimmo

Issue:
Fog_of_war: Partial fog distance passed around but never used
We pass a variable `partial_fog_distance` multiple times until it reaches the function `should_partially_fog` inside `fog_of_war.py` however we never use it. 

We should implement this at some stage. 


Discussion:

Resolving patch:
diff --git a/aimmo-game/simulation/avatar/fog_of_war.py b/aimmo-game/simulation/avatar/fog_of_war.py
deleted file mode 100644
--- a/aimmo-game/simulation/avatar/fog_of_war.py
+++ /dev/null
@@ -1,48 +0,0 @@
-import copy
-
-from simulation.geography.location import Location
-from simulation.world_map import WorldMap
-
-
-def apply_fog_of_war(world_map, avatar_wrapper):
-    """
-    Takes a world state and an avatar and returns a personalised view of the world.
-    :param world_map: the state of the game
-    :param avatar_wrapper: the application's view of the avatar
-    :return: a world state tailored to the given avatar
-    """
-
-    location = avatar_wrapper.location
-    no_fog_distance = avatar_wrapper.fog_of_war_modifier + world_map.get_no_fog_distance()
-    partial_fog_distance = avatar_wrapper.fog_of_war_modifier + world_map.get_partial_fog_distance()
-
-    lower_x = max(location.x - partial_fog_distance, world_map.min_x())
-    lower_y = max(location.y - partial_fog_distance, world_map.min_y())
-    upper_x = min(location.x + partial_fog_distance, world_map.max_x())
-    upper_y = min(location.y + partial_fog_distance, world_map.max_y())
-
-    grid = {}
-    for x in range(lower_x, upper_x + 1):
-        for y in range(lower_y, upper_y + 1):
-            cell_location = Location(x, y)
-            if world_map.is_on_map(cell_location):
-                x_dist = abs(cell_location.x - location.x)
-                y_dist = abs(cell_location.y - location.y)
-                if should_partially_fog(no_fog_distance, partial_fog_distance, x_dist, y_dist):
-                    grid[location] = partially_fog_cell(world_map.get_cell(cell_location))
-                else:
-                    grid[location] = world_map.get_cell(cell_location)
-    return WorldMap(grid, world_map.settings)
-
-
-def should_partially_fog(no_fog_distance, partial_fog_distance, x_dist, y_dist):
-    return x_dist > no_fog_distance or y_dist > no_fog_distance
-
-
-def partially_fog_cell(cell):
-    partially_fogged_cell = copy.deepcopy(cell)
-    partially_fogged_cell.habitable = True
-    partially_fogged_cell.avatar = None
-    partially_fogged_cell.pickup = None
-    partially_fogged_cell.partially_fogged = True
-    return partially_fogged_cell
diff --git a/aimmo-game/simulation/geography/cell.py b/aimmo-game/simulation/geography/cell.py
--- a/aimmo-game/simulation/geography/cell.py
+++ b/aimmo-game/simulation/geography/cell.py
@@ -6,13 +6,12 @@ class Cell(object):
     Any position on the world grid.
     """
 
-    def __init__(self, location, habitable=True, generates_score=False, partially_fogged=False):
+    def __init__(self, location, habitable=True, generates_score=False):
         self.location = location
         self.habitable = habitable
         self.generates_score = generates_score
         self.avatar = None
         self.pickup = None
-        self.partially_fogged = partially_fogged
         self.actions = []
 
         # Used to update the map features in the current view of the user (score points on pickups).
@@ -20,8 +19,8 @@ def __init__(self, location, habitable=True, generates_score=False, partially_fo
         self.add_to_scene = None
 
     def __repr__(self):
-        return 'Cell({} h={} s={} a={} p={} f{})'.format(
-            self.location, self.habitable, self.generates_score, self.avatar, self.pickup, self.partially_fogged)
+        return 'Cell({} h={} s={} a={} p={}'.format(
+            self.location, self.habitable, self.generates_score, self.avatar, self.pickup)
 
     def __eq__(self, other):
         return self.location == other.location
@@ -41,18 +40,10 @@ def is_occupied(self):
         return self.avatar is not None
 
     def serialise(self):
-        if self.partially_fogged:
-            return {
-                'generates_score': self.generates_score,
-                'location': self.location.serialise(),
-                'partially_fogged': self.partially_fogged
-            }
-        else:
-            return {
-                'avatar': self.avatar.serialise() if self.avatar else None,
-                'generates_score': self.generates_score,
-                'habitable': self.habitable,
-                'location': self.location.serialise(),
-                'pickup': self.pickup.serialise() if self.pickup else None,
-                'partially_fogged': self.partially_fogged
-            }
+        return {
+            'avatar': self.avatar.serialise() if self.avatar else None,
+            'generates_score': self.generates_score,
+            'habitable': self.habitable,
+            'location': self.location.serialise(),
+            'pickup': self.pickup.serialise() if self.pickup else None,
+        }
diff --git a/aimmo-game/simulation/state/game_state.py b/aimmo-game/simulation/state/game_state.py
--- a/aimmo-game/simulation/state/game_state.py
+++ b/aimmo-game/simulation/state/game_state.py
@@ -1,4 +1,3 @@
-from simulation.avatar import fog_of_war
 
 
 class GameState(object):
@@ -11,12 +10,11 @@ def __init__(self, world_map, avatar_manager, completion_check_callback=lambda:
         self._completion_callback = completion_check_callback
         self.main_avatar_id = None
 
-    def get_state_for(self, avatar_wrapper, fog_of_war=fog_of_war):
-        processed_world_map = fog_of_war.apply_fog_of_war(self.world_map, avatar_wrapper)
+    def get_state_for(self, avatar_wrapper):
         return {
             'avatar_state': avatar_wrapper.serialise(),
             'world_map': {
-                'cells': [cell.serialise() for cell in processed_world_map.all_cells()]
+                'cells': [cell.serialise() for cell in self.world_map.all_cells()]
             }
         }
 


Test patch:
diff --git a/aimmo-game/tests/test_simulation/avatar/test_fog_of_war.py b/aimmo-game/tests/test_simulation/avatar/test_fog_of_war.py
deleted file mode 100644
--- a/aimmo-game/tests/test_simulation/avatar/test_fog_of_war.py
+++ /dev/null
@@ -1,47 +0,0 @@
-from __future__ import absolute_import
-
-from unittest import TestCase
-
-from simulation.avatar.fog_of_war import should_partially_fog, partially_fog_cell
-from simulation.geography.cell import Cell
-
-class Serialiser(object):
-    def __init__(self, content):
-        self.content = content
-
-    def serialise(self):
-        return self.content
-
-
-class TestFogOfWar(TestCase):
-    def test_should_partially_fog(self):
-        self.assertFalse(should_partially_fog(no_fog_distance=20, partial_fog_distance=2, x_dist=1, y_dist=10))
-        self.assertTrue(should_partially_fog(no_fog_distance=1, partial_fog_distance=2, x_dist=20, y_dist=10))
-
-    def _create_full_cell(self):
-        cell = Cell(Serialiser('location'), False, True)
-        cell.avatar = Serialiser('avatar')
-        cell.pickup = Serialiser('pickup')
-        self.expected = {
-            'avatar': 'avatar',
-            'generates_score': True,
-            'habitable': False,
-            'location': 'location',
-            'pickup': 'pickup',
-            'partially_fogged': False
-        }
-        return cell
-
-    def test_partially_fog_cell(self):
-        mock_cell = self._create_full_cell()
-        self.assertEqual(mock_cell.partially_fogged, False)
-        self.assertEqual(mock_cell.habitable, False)
-        self.assertNotEqual(mock_cell.avatar, None)
-        self.assertEqual(mock_cell.generates_score, True)
-        self.assertNotEqual(mock_cell.pickup, None)
-
-        mock_cell = partially_fog_cell(mock_cell)
-        self.assertEqual(mock_cell.partially_fogged, True)
-        self.assertEqual(mock_cell.habitable, True)
-        self.assertEqual(mock_cell.avatar, None)
-        self.assertEqual(mock_cell.pickup, None)
diff --git a/aimmo-game/tests/test_simulation/test_game_state.py b/aimmo-game/tests/test_simulation/test_game_state.py
--- a/aimmo-game/tests/test_simulation/test_game_state.py
+++ b/aimmo-game/tests/test_simulation/test_game_state.py
@@ -68,12 +68,6 @@ def test_add_avatar(self):
         self.assertEqual(avatar.location.x, 10)
         self.assertEqual(avatar.location.y, 10)
 
-    def test_fog_of_war(self):
-        state = GameState(InfiniteMap(), DummyAvatarManager())
-        view = state.get_state_for(DummyAvatar(None, None), FogToEmpty())
-        self.assertEqual(len(view['world_map']['cells']), 0)
-        self.assertEqual(view['avatar_state'], 'Dummy')
-
     def test_updates_map(self):
         map = InfiniteMap()
         state = GameState(map, DummyAvatarManager())
diff --git a/aimmo-game/tests/test_simulation/test_world_map.py b/aimmo-game/tests/test_simulation/test_world_map.py
--- a/aimmo-game/tests/test_simulation/test_world_map.py
+++ b/aimmo-game/tests/test_simulation/test_world_map.py
@@ -49,7 +49,6 @@ def _create_full_cell(self):
             'habitable': False,
             'location': 'location',
             'pickup': 'pickup',
-            'partially_fogged': False
         }
         return cell
 
diff --git a/integration-tests/tests/test_backend.py b/integration-tests/tests/test_backend.py
--- a/integration-tests/tests/test_backend.py
+++ b/integration-tests/tests/test_backend.py
@@ -86,7 +86,7 @@ def _generate_response(self, num_games):
             str(i): {
                 'name': 'Level1',
                 'settings': dumps(DEFAULT_LEVEL_SETTINGS)
-            } for i in xrange(num_games)
+            } for i in range(num_games)
         }
 
 
@@ -150,7 +150,7 @@ class TestService(TestCase):
               self.__build_test([
                   (GameCreatorProxy(self), 1), # pair of proxy and turns
                   (GameProxy(self), 1)
-              ], False)                        # set True for kubernates
+              ], False)                        # set True for kubernetes
 
           * the service runs minikube/localhost for testing
           * kubernates tests should be named: "ktest_..."