Updated TicTacToeRules and BattleshipRules to implement ApplyMove(state, playerIdx, payload) (bool, bool, int) as required by GameRules. Added win/draw resolution logic directly inside each game’s ApplyMove return. Removed obsolete convertToGamePlayers helper. Updated GenericMatch to call AssignPlayerSymbols with []*structs.Player directly. Ensured all rule implementations now fully satisfy the GameRules interface.
28 lines
736 B
Go
28 lines
736 B
Go
package games
|
|
|
|
import "localrepo/plugins/structs"
|
|
|
|
// MovePayload is used for incoming move data from clients.
|
|
type MovePayload struct {
|
|
Data map[string]interface{} `json:"data"`
|
|
}
|
|
|
|
type GameRules interface {
|
|
// Number of players needed to start.
|
|
MaxPlayers() int
|
|
|
|
// Assign symbols/colors/pieces at start.
|
|
AssignPlayerSymbols(players []*structs.Player)
|
|
|
|
// Apply a move.
|
|
// Returns: (changed, gameOver, winnerIndex)
|
|
ApplyMove(state *structs.MatchState, playerIdx int, payload MovePayload) (bool, bool, int)
|
|
|
|
// If a player leaves, who wins?
|
|
// Return:
|
|
// >=0 → winner index
|
|
// -1 → draw
|
|
// -2 → invalid
|
|
ForfeitWinner(state *structs.MatchState, leaverIndex int) int
|
|
}
|