Skip to content

feat: log per-move deltas to matchLogs/{roomId}.moves[] (single-document array) #20

Description

@ibloud

Summary

Implement per-move stat capture in gameNamespace.js by writing move deltas into a single Firestore document at matchLogs/{roomId}, using an append-only moves array (not a subcollection).

Schema alignment

This issue follows docs/design/player-profile-schema.md:

  • One parent document per match: matchLogs/{roomId}
  • Per-move deltas stored in moves[] on that parent document
  • Typical payload (~16KB) remains well below Firestore's 1MB document limit

Implementation

  • On first confirmed make_move, create (or upsert) matchLogs/{roomId}.
  • Ensure base fields exist (example):
    • roomId, createdAt, startedAt, players, completedAt, winner
    • moves: []
  • After each confirmed move, append one entry to moves[] with:
    • moveNum, color, from, to, piece, capturedPiece
    • evalBefore, evalAfter, severity
    • veiled, veiledOpponent, sacrifice
    • inversionClause, promotedTo
    • timeMs, timestamp
  • On gameOver=true, set:
    • completedAt
    • winner

Constraints

  • moves[] must be append-only and preserve chronological order.
  • Writes should be idempotent against duplicate move events (no duplicate moveNum entries).
  • Keep document size under Firestore limits for expected match lengths.

Acceptance Criteria

  • A completed remote match produces one readable matchLogs/{roomId} document.
  • Per-move deltas are present in moves[] and ordered by moveNum.
  • No subcollection is used for move logs.
  • Finalization fields (completedAt, winner) are set on game completion.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    player-profileplayerProfiles schema/persistencestat-capturemove log + aggregation work

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions