Skip to content

Commit

Permalink
fix inconsistent timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
siku2 committed Oct 4, 2022
1 parent e2d53ec commit 334d2e5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ld51_server/board.py
Expand Up @@ -223,7 +223,8 @@ def _perform_player_move_event(
PushConflictOutcome.build(
PushConflictOutcomePayload(
piece_ids=pushers,
collision_point=target_pos,
# TODO: determine
collision_point=None,
)
)
)
Expand Down
67 changes: 67 additions & 0 deletions tests/data/board_states/conflict-cancel-with-push.timeline.json
@@ -0,0 +1,67 @@
[
{
"actions": [
{
"player_id": "00000000-0000-0000-0000-000000000000",
"piece_id": "1882c891-c8e8-5040-9914-92226dd91849",
"action": "move_down"
},
{
"player_id": "00000000-0000-0000-0000-000000000000",
"piece_id": "d6bcda58-eaf5-5111-986b-36189ab57944",
"action": "move_up"
}
],
"outcomes": [
{
"type": "move_conflict",
"payload": {
"piece_ids": [
"1882c891-c8e8-5040-9914-92226dd91849",
"d6bcda58-eaf5-5111-986b-36189ab57944"
],
"collision_point": {
"x": 2,
"y": 1
}
}
}
]
},
{
"actions": [
{
"player_id": "00000000-0000-0000-0000-000000000000",
"piece_id": "57843557-76b2-5568-9503-d05ad730b08e",
"action": "move_right"
},
{
"player_id": "00000000-0000-0000-0000-000000000000",
"piece_id": "897264db-5a3f-5538-938d-062a7897f4e4",
"action": "move_right"
}
],
"outcomes": [
{
"type": "push",
"payload": {
"pusher_piece_id": "57843557-76b2-5568-9503-d05ad730b08e",
"victim_piece_ids": [
"1882c891-c8e8-5040-9914-92226dd91849"
],
"direction": "right"
}
},
{
"type": "push",
"payload": {
"pusher_piece_id": "897264db-5a3f-5538-938d-062a7897f4e4",
"victim_piece_ids": [
"8cc4f4f3-0d5f-59b0-812a-0dabb3b2a699"
],
"direction": "right"
}
}
]
}
]
5 changes: 1 addition & 4 deletions tests/data/board_states/staggered-push.timeline.json
Expand Up @@ -60,10 +60,7 @@
"317cb2ff-3fcb-5e0f-b25a-52125850e919",
"f8ca590a-8db9-5f55-b1f0-e8207f7adc5b"
],
"collision_point": {
"x": 2,
"y": 1
}
"collision_point": null
}
}
]
Expand Down
11 changes: 11 additions & 0 deletions tests/test_game.py
Expand Up @@ -8,6 +8,7 @@

from ld51_server.board import BoardState, PieceInformation
from ld51_server.models import PieceAction, PlayerMove, Position, TimelineEvent
from ld51_server.models.timeline import Outcome

from . import DATA_DIR

Expand Down Expand Up @@ -144,9 +145,19 @@ class Timeline(BaseModel):
__root__: list[TimelineEvent]


def _normalize_outcome(outcome: Outcome):
payload = outcome.payload
try:
payload.piece_ids.sort()
except Exception:
pass


def _normalize_events(events: list[TimelineEvent]) -> None:
for event in events:
event.actions.sort(key=lambda a: a.piece_id)
for outcome in event.outcomes:
_normalize_outcome(outcome)
event.outcomes.sort(key=lambda e: e.json())


Expand Down

0 comments on commit 334d2e5

Please sign in to comment.