feat(core): migrate to multi-board architecture and implement per-game InitBoards
### Major changes - Replace single-board MatchState (`Board`) with multi-board map (`Boards`) - Update GenericMatch to initialize empty Boards and populate them via GameRules.InitBoards - Remove legacy `newEmptyBoard` helper from match.go - Update .gitignore to include *BKP* patterns ### GameRules interface - Add InitBoards(players, cfg) to allow games to construct their own board sets - Add detailed documentation explaining method responsibilities and usage - Improve MovePayload comment clarity ### TicTacToe updates - Implement InitBoards to produce a single `"tictactoe"` board - Replace all old references to `state.Board` with `state.Boards["tictactoe"]` - Make CheckGameOver, ValidateMove, and ApplyMove multi-board compatible ### Battleship updates - Implement InitBoards generating per-player ships + shots boards: - p0_ships, p0_shots - p1_ships, p1_shots ### Match flow updates - Boards are now created only when all players have joined - Initial state broadcast now includes `boards` instead of `board` This completes the backend migration for multi-board games and prepares the architecture for Battleship and other complex board-based games.
This commit is contained in:
@@ -62,6 +62,21 @@ type BattleshipRules struct{}
|
||||
|
||||
func (b *BattleshipRules) MaxPlayers() int { return 2 }
|
||||
|
||||
func (b *BattleshipRules) InitBoards(players []*structs.Player, cfg GameConfiguration) map[string]*structs.Board {
|
||||
boards := make(map[string]*structs.Board)
|
||||
// One ships board and one shots board per player
|
||||
for _, p := range players {
|
||||
pid := fmt.Sprintf("p%d", p.Index)
|
||||
|
||||
// Player's fleet board (ships placement)
|
||||
boards[pid+"_ships"] = structs.NewBoard(cfg.Board.Rows, cfg.Board.Cols)
|
||||
|
||||
// Player's attack tracking board (shots fired at opponent)
|
||||
boards[pid+"_shots"] = structs.NewBoard(cfg.Board.Rows, cfg.Board.Cols)
|
||||
}
|
||||
return boards
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Assign player boards
|
||||
// ------------------------------
|
||||
|
||||
Reference in New Issue
Block a user