refactor(server): move shared game logic into games/ and introduce GameConfig system

- Moved common/game.go → plugins/games/rules.go
  - Contains GameRules interface, MovePayload, Player abstraction
  - Centralizes all reusable game rule contract logic

- Added plugins/games/config.go
  - Introduces GameConfiguration struct (players, board size, etc.)
  - Added global GameConfig and RulesRegistry maps
  - Each game (tictactoe, battleship, etc.) now registers its config + rules

- Updated generic_match.go to use:
  - GameConfig for board/players initialization
  - RulesRegistry for rule lookup during MatchInit
  - Removed hardcoded TicTacToe behavior
  - Clean error returns when game param missing or invalid

- Updated folder structure:
    /plugins/
        /games
            rules.go       (formerly common/game.go)
            config.go
            tictactoe.go
            battleship.go
        /structs
        /modules
        main.go

- Ensures GenericMatch pulls:
    m.GameName, m.Mode, m.Config, m.Rules
  directly from config/registry at MatchInit

- Removes old duplicated logic and simplifies how games are registered
This commit is contained in:
2025-12-01 16:05:53 +05:30
parent eeb0a8175f
commit d9c3ecb252
4 changed files with 121 additions and 184 deletions

23
plugins/games/config.go Normal file
View File

@@ -0,0 +1,23 @@
package modules
type BoardConfig struct {
Rows int
Cols int
}
type GameConfiguration struct {
Players int
Board BoardConfig
}
// Static configuration for all supported games.
var GameConfig = map[string]GameConfiguration{
"tictactoe": {
Players: 2,
Board: BoardConfig{Rows: 3, Cols: 3},
},
"battleship": {
Players: 2,
Board: BoardConfig{Rows: 10, Cols: 10},
},
}