Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add worksheet 4 #1651

Merged
merged 4 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aimmo-game/simulation/worksheet/avatar_state_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ def worksheet3_avatar_state_serializer(avatar: AvatarWrapper) -> Dict:
"orientation": avatar.orientation,
"backpack": [artefact.serialize() for artefact in avatar.backpack],
}


def worksheet4_avatar_state_serializer(avatar: AvatarWrapper) -> Dict:
return {
"location": avatar.location.serialize(),
"id": avatar.player_id,
"orientation": avatar.orientation,
"backpack": [artefact.serialize() for artefact in avatar.backpack],
}
8 changes: 8 additions & 0 deletions aimmo-game/simulation/worksheet/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
worksheet1_avatar_state_serializer,
worksheet2_avatar_state_serializer,
worksheet3_avatar_state_serializer,
worksheet4_avatar_state_serializer,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -62,6 +63,13 @@ class WorksheetData:
number_of_obstacle_textures=1,
avatar_state_serializer=worksheet3_avatar_state_serializer,
),
4: WorksheetData(
worksheet_id=4,
era="modern",
map_updaters=[PickupUpdater(pickup_types=[ChestArtefact, KeyArtefact])],
number_of_obstacle_textures=1,
avatar_state_serializer=worksheet4_avatar_state_serializer,
),
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ def test_worksheet3_avatar_state():
"orientation": "north",
"backpack": [],
}


def test_worksheet4_avatar_state():
worksheet4 = worksheets[4]
avatar_wrapper = AvatarWrapper(32, Location(7, -2), MagicMock())
serialized_avatar_state = worksheet4.avatar_state_serializer(avatar_wrapper)
assert serialized_avatar_state == {
"id": 32,
"location": {"x": 7, "y": -2},
"orientation": "north",
"backpack": [],
}
2 changes: 1 addition & 1 deletion aimmo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_list_running_games(self):
game3 = Game(id=3, name="test", game_class=klass3, status=Game.RUNNING)
game3.save()
game4 = Game(id=4, name="test", game_class=klass4, status=Game.STOPPED)
game3.save()
game4.save()

def expected_game_detail(class_id, worksheet_id):
return {
Expand Down
47 changes: 43 additions & 4 deletions aimmo/worksheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,56 @@ def next_turn(world_state, avatar_state):
name="21st Century",
era=3,
starter_code="""
#-------------------------------------------------------------------------------
# Worksheet 4 challenges:
# Task 1: Examine your backpack
# - Change the code so that you can print how many items are in your backpack.
# - Print the first item from your backpack and the item type.
#
# Task 2: Examine all artefacts
# - Write some code that prints the position of your backpack and
# the item that is in that position.
#
# Task 3: Count your loot
# - Count how many of each artifacts do you have
#
# Task 4: Drop artefacts by type
# - Drop artefacts that you do not need
#
# New commands:
# - avatar_state.backpack
# - avatar_state.location
# - world_state.get_cell(avatar_location)
# - DropAction(index)
#-------------------------------------------------------------------------------

def next_turn(world_state, avatar_state):
new_dir = direction.NORTH
# Your code goes here
action = MoveAction(new_dir)
# Find out where your avatar is
avatar_location = avatar_state.location
current_cell = world_state.get_cell(avatar_location)

# Check if the current cell holds an artefact
if current_cell.has_artefact():
# It does! Pick it up.
action = PickupAction()
else:
# The cell does not contain an artefact
# Find the location of all artefacts nearby
nearby = world_state.scan_nearby(avatar_location)

# Get the nearest one
nearest = nearby[0]

# Move towards the nearest arteface
action = MoveTowardsAction(nearest)

return action
""",
active_image_path="images/worksheets/modern_active.png",
description="After successfully collecting all the missing artefacts from the first time checkpoint, you arrive at what looks like the 21st century. You recognise some cars parked here and there, old-fashioned roads and houses like the ones your history teacher told you about. On the bright side, you seem to be alone and safe to walk around... for now. A more recent timeline doesn’t make artefacts easier to find, though. Or at least not the right ones. In this timeline there seems to be an amount of falsified objects that resemble the ones you’re looking for, but aren’t quite genuine. These will have no value in the museum. Your navigation system will be able to tell you whether an object is genuine or not, but it’s up to you to decide which ones to bring back!",
image_path="images/worksheets/modern.jpg",
short_description="After successfully collecting all the missing artefacts from the first time checkpoint, you arrive at what looks like the 21st century.",
thumbnail_text="Coming Soon",
thumbnail_text="",
student_challenge_url="",
),
5: Worksheet(
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"