feat(battleship,tictactoe,engine): add multi-board support and keepTurn logic

### Core Engine
- Updated `GameRules.ApplyMove` to return `(changed, gameOver, winnerIdx, keepTurn)`
- Added keepTurn handling in `MatchLoop` to support Battleship mode B (classic rules)
- Removed old single-board handling from MatchState and MatchInit
- Cleaned go.mod by marking protobuf dependency as indirect

### Battleship
- Implemented board-based state tracking using MatchState.Boards:
  - `p0_ships`, `p0_shots`, `p1_ships`, `p1_shots`
- Removed legacy metadata-based ship/shot board encoding
- Rewrote ValidateMove to use structured boards
- Rewrote ApplyMove for classic Battleship rules (mode B):
  - Hits allow the attacker to keep their turn
  - Miss switches turn
  - Destroyed ship sections marked `X`
- Improved CheckGameOver using structured boards

### TicTacToe
- Updated ApplyMove signature to match new interface
- Ensured TicTacToe always returns `keepTurn = false`
- Updated code paths to use MatchState.Boards instead of Board

### Summary
This commit completes the migration from a single-board architecture to a
multi-board architecture across the engine, TicTacToe, and Battleship, enabling
support for more complex games and multiple modes such as Battleship Mode B.
This commit is contained in:
2025-12-03 18:09:49 +05:30
parent bcdc5faea5
commit d75dcd3c74
4 changed files with 58 additions and 54 deletions

View File

@@ -318,7 +318,7 @@ func (m *GenericMatch) MatchLoop(
}
// Delegate to rules.ApplyMove which returns (changed, gameOver, winnerIndex)
stateChanged, gameOver, winnerIdx := m.Rules.ApplyMove(s, playerIdx, payload)
stateChanged, gameOver, winnerIdx, keepTurn := m.Rules.ApplyMove(s, playerIdx, payload)
if stateChanged {
changed = true
@@ -328,7 +328,7 @@ func (m *GenericMatch) MatchLoop(
s.GameOver = true
s.Winner = winnerIdx
} else {
if len(s.Players) > 0 {
if !keepTurn && len(s.Players) > 0 {
s.Turn = (s.Turn + 1) % len(s.Players)
}
}