- 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
24 lines
436 B
Go
24 lines
436 B
Go
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},
|
|
},
|
|
}
|