Skip to content

Commit

Permalink
fix: load correct worksheet in aimmo-game (#1476)
Browse files Browse the repository at this point in the history
* fix: load correct worksheet in aimmo-game

* cleanup worksheet __init__

* Merge branch 'development' into fix-game-worksheet
  • Loading branch information
razvan-pro committed Mar 5, 2021
1 parent 8e7711e commit f9bcb61
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 299 deletions.
364 changes: 185 additions & 179 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion aimmo-game/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ pytest-aiohttp = "*"
aioresponses = "*"

[requires]
python_version = "3.7.7"
python_version = "3.7"
260 changes: 166 additions & 94 deletions aimmo-game/Pipfile.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions aimmo-game/simulation/avatar/avatar_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from typing import List
from simulation.avatar.avatar_wrapper import AvatarWrapper
from simulation.avatar.avatar_appearance import AvatarAppearance
from simulation.worksheet import WORKSHEET, WorksheetData
from simulation.worksheet.worksheet import WorksheetData, get_worksheet_data


class AvatarManager(object):
"""
Stores all game avatars.
"""

def __init__(self, worksheet: WorksheetData = WORKSHEET):
def __init__(self, worksheet: WorksheetData = None):
if worksheet is None:
worksheet = get_worksheet_data()

self.avatars_by_id = {}
self.worksheet = worksheet

Expand Down
9 changes: 6 additions & 3 deletions aimmo-game/simulation/game_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
from typing import TYPE_CHECKING

from simulation.interactables import serialize_interactables
from simulation.worksheet import WORKSHEET
from simulation.worksheet.worksheet import get_worksheet_data

if TYPE_CHECKING:
from simulation.world_map import WorldMap
from simulation.avatar.avatar_manager import AvatarManager
from simulation.worksheet import WorksheetData
from simulation.worksheet.worksheet import WorksheetData


class GameState:
"""
Encapsulates the entire game state, including avatars, their code, and the world.
"""

def __init__(self, world_map, avatar_manager, worksheet: WorksheetData = WORKSHEET):
def __init__(self, world_map, avatar_manager, worksheet: WorksheetData = None):
if worksheet is None:
worksheet = get_worksheet_data()

self.world_map: WorldMap = world_map
self.avatar_manager: AvatarManager = avatar_manager
self.turn_count: int = 0
Expand Down
8 changes: 5 additions & 3 deletions aimmo-game/simulation/obstacle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from random import randint

from simulation.cell import Cell
from simulation.worksheet import WORKSHEET, WorksheetData
from simulation.worksheet.worksheet import WorksheetData, get_worksheet_data


@dataclass
Expand All @@ -17,13 +17,15 @@ class Obstacle:
def serialize(self, cell: Cell):
return {"location": cell.location.serialize(), "texture": self.texture_choice}

def make_obstacle(worksheet: WorksheetData = WORKSHEET) -> "Obstacle":
def make_obstacle(worksheet: WorksheetData = None) -> "Obstacle":
"""
Returns an obstacle with a randomly generated texture choice based on number of different
obstacle textures indicated in the worksheet.
Args:
worksheet (WorksheetData, optional): The worksheet to use to generate the obstacle. Defaults to WORKSHEET.
worksheet (WorksheetData, optional): The worksheet to use to generate the obstacle. Defaults to get_worksheet_data().
"""
if worksheet is None:
worksheet = get_worksheet_data()
texture_choice = randint(1, worksheet.number_of_obstacle_textures)
return Obstacle(texture_choice)
11 changes: 7 additions & 4 deletions aimmo-game/simulation/simulation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import TYPE_CHECKING

from simulation.action import PRIORITIES
from simulation.game_logic import EffectApplier, MapContext, PickupUpdater
from simulation.worksheet import WORKSHEET, WorksheetData
from simulation.game_logic import EffectApplier, MapContext
from simulation.worksheet.worksheet import WorksheetData, get_worksheet_data

if TYPE_CHECKING:
from turn_collector import CollectedTurnActions
Expand All @@ -24,10 +24,13 @@ class SimulationRunner(object):
daemon = True
__metaclass__ = ABCMeta

def __init__(self, game_state, communicator, worksheet: WorksheetData = WORKSHEET):
def __init__(self, game_state, communicator, worksheet: WorksheetData = None):
if worksheet is None:
worksheet = get_worksheet_data()

self.game_state = game_state
self.communicator = communicator
self.worksheet: WorksheetData = WORKSHEET
self.worksheet: WorksheetData = worksheet
self._lock = threading.RLock()

@abstractmethod
Expand Down
3 changes: 0 additions & 3 deletions aimmo-game/simulation/worksheet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .worksheet import WorksheetData, WORKSHEET

__all__ = ["WORKSHEET", "WorksheetData"]
3 changes: 0 additions & 3 deletions aimmo-game/simulation/worksheet/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,3 @@ class WorksheetData:
def get_worksheet_data() -> WorksheetData:
worksheet_id = int(os.environ.get("worksheet_id", 1))
return worksheets.get(worksheet_id, worksheets[1])


WORKSHEET = get_worksheet_data()
14 changes: 7 additions & 7 deletions aimmo-game/tests/test_simulation/test_simulation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from simulation.avatar.avatar_appearance import AvatarAppearance
from simulation.game_logic import PickupUpdater
from simulation.worksheet import WorksheetData
from simulation.worksheet.worksheet import WorksheetData
from simulation.interactables.pickups import Artefact
from simulation.interactables.score_location import ScoreLocation
from simulation.location import Location
Expand Down Expand Up @@ -56,12 +56,12 @@ def generate_grid(columns=2, rows=2):

class TestSimulationRunner:
"""
Key:
> : Avatar moving eastward
< : Avatar moving westward
x : Avatar waiting / blocked
o : Avatar successfully moved
! : Dead avatar (that should be waiting)
Key:
> : Avatar moving eastward
< : Avatar moving westward
x : Avatar waiting / blocked
o : Avatar successfully moved
! : Dead avatar (that should be waiting)
"""

def assertGridSize(self, world_map, expected_columns, expected_rows=None):
Expand Down

0 comments on commit f9bcb61

Please sign in to comment.