2020-01-05 17:08:05 -08:00
|
|
|
package rules
|
2019-12-31 20:43:05 -08:00
|
|
|
|
2020-12-11 10:05:19 -08:00
|
|
|
type RulesetError string
|
|
|
|
|
|
|
|
|
|
func (err RulesetError) Error() string { return string(err) }
|
|
|
|
|
|
2020-01-01 17:22:00 -08:00
|
|
|
const (
|
2020-01-02 16:10:33 -08:00
|
|
|
MoveUp = "up"
|
|
|
|
|
MoveDown = "down"
|
|
|
|
|
MoveRight = "right"
|
|
|
|
|
MoveLeft = "left"
|
2020-12-11 10:05:19 -08:00
|
|
|
|
|
|
|
|
BoardSizeSmall = 7
|
|
|
|
|
BoardSizeMedium = 11
|
|
|
|
|
BoardSizeLarge = 19
|
|
|
|
|
|
|
|
|
|
SnakeMaxHealth = 100
|
|
|
|
|
SnakeStartSize = 3
|
|
|
|
|
|
|
|
|
|
// bvanvugt - TODO: Just return formatted strings instead of codes?
|
|
|
|
|
NotEliminated = ""
|
|
|
|
|
EliminatedByCollision = "snake-collision"
|
|
|
|
|
EliminatedBySelfCollision = "snake-self-collision"
|
|
|
|
|
EliminatedByOutOfHealth = "out-of-health"
|
|
|
|
|
EliminatedByHeadToHeadCollision = "head-collision"
|
|
|
|
|
EliminatedByOutOfBounds = "wall-collision"
|
|
|
|
|
|
|
|
|
|
// TODO - Error consts
|
|
|
|
|
ErrorTooManySnakes = RulesetError("too many snakes for fixed start positions")
|
|
|
|
|
ErrorNoRoomForSnake = RulesetError("not enough space to place snake")
|
|
|
|
|
ErrorNoRoomForFood = RulesetError("not enough space to place food")
|
|
|
|
|
ErrorNoMoveFound = RulesetError("move not provided for snake")
|
|
|
|
|
ErrorZeroLengthSnake = RulesetError("snake is length zero")
|
2020-01-01 17:22:00 -08:00
|
|
|
)
|
2019-12-31 20:43:05 -08:00
|
|
|
|
|
|
|
|
type Point struct {
|
|
|
|
|
X int32
|
|
|
|
|
Y int32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Snake struct {
|
2021-09-07 14:58:10 -07:00
|
|
|
ID string
|
|
|
|
|
Body []Point
|
|
|
|
|
Health int32
|
|
|
|
|
EliminatedCause string
|
|
|
|
|
EliminatedOnTurn int32
|
|
|
|
|
EliminatedBy string
|
2019-12-31 20:43:05 -08:00
|
|
|
}
|
|
|
|
|
|
2020-01-01 17:22:00 -08:00
|
|
|
type SnakeMove struct {
|
2020-01-02 16:10:33 -08:00
|
|
|
ID string
|
|
|
|
|
Move string
|
2020-01-01 17:22:00 -08:00
|
|
|
}
|
2019-12-31 20:43:05 -08:00
|
|
|
|
|
|
|
|
type Ruleset interface {
|
2021-07-02 20:09:55 -07:00
|
|
|
Name() string
|
2021-08-23 17:13:58 -07:00
|
|
|
ModifyInitialBoardState(initialState *BoardState) (*BoardState, error)
|
2020-02-20 10:24:44 -08:00
|
|
|
CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error)
|
2020-05-17 14:38:39 -07:00
|
|
|
IsGameOver(state *BoardState) (bool, error)
|
2019-12-31 20:43:05 -08:00
|
|
|
}
|