Skip to content

[BE-2] Implement Turn Management System #25

Description

@sarkarshuvojit

Parent Epic

#22

Description

Implement turn rotation logic so players take turns in order.

Requirements

  • Track current player in RoomState (CurrentPlayer field exists)
  • Initialize turn order when game starts (after all boards submitted)
  • Rotate to next player after each valid move
  • Skip players who are eliminated (all ships sunk)
  • Broadcast turn changes to all players

Turn Order

  • 3 players: A → B → C → A → ...
  • If B is eliminated: A → C → A → C → ...

Events

  • Outbound: NEXT_TURN (already defined)

Files to Modify

  • internal/game/types.go - Turn tracking
  • internal/api/handlers/room.go - Turn initialization
  • internal/api/jobs/game_jobs.go - Turn rotation job

Unit Tests

  • Turn initializes to first player
  • Turn rotates correctly after move
  • Eliminated players are skipped
  • Turn broadcasts to all players

Acceptance Criteria

  • Turn system implemented
  • Players can only act on their turn
  • Invalid turn attempts rejected with error
  • Unit tests passing

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

    backendBackend related issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions