Documentation ¶
Overview ¶
Package scouts implements the game of Scouts.
Index ¶
- Constants
- Variables
- func IsPlayerBase(player Player, pt Point) bool
- type Board
- func (b *Board) Bounds() image.Rectangle
- func (b *Board) HasPieceAt(p Point) bool
- func (b *Board) PieceAt(p Point) Piece
- func (b *Board) PieceKindAt(p Point) PieceKind
- func (b *Board) Pieces() []Piece
- func (b *Board) PointIsPiece(p Point, kind PieceKind) bool
- func (b *Board) PointIsPlayer(p Point, player Player) bool
- type BoulderMove
- type BoulderPiece
- type BoulderPieceModel
- type CurrentTurn
- type DashMove
- type FormattedBoard
- type Game
- func (g *Game) Apply(p Player, move Move) error
- func (g *Game) Board() *Board
- func (g *Game) CurrentTurn() CurrentTurn
- func (g *Game) Ended() (Player, bool)
- func (g *Game) MakeMove(p Player, move Move) error
- func (g *Game) PastTurns() []PastTurn
- func (g *Game) PlayerPastTurns(p Player) []PastTurn
- func (g *Game) PossibleMoves(p Player) PossibleMoves
- type JumpMove
- type Move
- type MoveType
- type Moves
- type PastTurn
- type Piece
- type PieceKind
- type PlaceScoutMove
- type Player
- type Point
- func (p Point) Add(q Point) Point
- func (p Point) Div(k int) Point
- func (p Point) Eq(q Point) bool
- func (p Point) In(r image.Rectangle) bool
- func (p Point) MarshalJSON() ([]byte, error)
- func (p Point) MarshalText() ([]byte, error)
- func (p Point) Mul(k int) Point
- func (p Point) String() string
- func (p Point) Sub(q Point) Point
- func (p *Point) UnmarshalJSON(data []byte) error
- func (p *Point) UnmarshalText(text []byte) error
- type PossibleMoves
- type ScoutPiece
- type ScoutsPieceModel
- type SkipMove
- type UnexpectedGameStateError
- type UnexpectedPieceError
Constants ¶
const ( FormattedPlayerAScoutPiece = 'A' FormattedPlayerBScoutPiece = 'B' FormattedPlayerABoulderPiece = 'a' FormattedPlayerBBoulderPiece = 'b' FormattedBlankPiece = '.' )
const ( Player1 = PlayerA Player2 = PlayerB )
const PlaceScoutTurns = 5
PlaceScoutTurns is the number of turns that each player has to place their scouts. After this number of turns, other moves are allowed.
const PlaysPerTurn = 2
PlaysPerTurn is the number of plays that each player has at the beginning of each turn after the start.
const StartingPlaysPerTurn = 1
StartingPlaysPerTurn is the number of plays that each player has at the beginning of each turn. The start is always when the player must place a scout.
Variables ¶
var BoardBounds = image.Rect(0, 0, 8, 10)
BoardBounds is the size of the board.
Functions ¶
func IsPlayerBase ¶
IsPlayerBase returns whether the given point is on the base of the given player.
Types ¶
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board is a type that represents the board. Player A is at the bottom of the board and player B is at the top of the board. It exposes no methods for modifying the board, only for reading it. To modify the board, use the Apply method on a Move.
func (*Board) HasPieceAt ¶
HasPieceAt returns whether there is a piece at the given point.
func (*Board) PieceAt ¶
PieceAt returns the piece at the given point, or nil if there is no piece at the given point.
func (*Board) PieceKindAt ¶
type BoulderMove ¶
type BoulderMove struct { // TopLeft is the top left position of the boulder. TopLeft Point `json:"top_left"` }
BoulderMove represents a move that places a boulder on the board. A boulder is a 2x2 piece that cannot be moved.
func (*BoulderMove) MarshalText ¶
func (m *BoulderMove) MarshalText() ([]byte, error)
func (*BoulderMove) String ¶
func (m *BoulderMove) String() string
func (*BoulderMove) UnmarshalText ¶
func (m *BoulderMove) UnmarshalText(text []byte) error
type BoulderPiece ¶
type BoulderPiece struct {
// contains filtered or unexported fields
}
BoulderPiece is a type that represents a boulder piece on the board.
func (*BoulderPiece) Kind ¶
func (p *BoulderPiece) Kind() PieceKind
Kind returns the kind of the piece.
func (*BoulderPiece) MarshalJSON ¶
func (p *BoulderPiece) MarshalJSON() ([]byte, error)
MarshalJSON marshals the boulder piece to JSON.
func (*BoulderPiece) Player ¶
func (p *BoulderPiece) Player() Player
Player returns the player that owns the piece.
func (*BoulderPiece) Position ¶
func (p *BoulderPiece) Position() []Point
Position returns the position of the piece, which may be multiple points.
type BoulderPieceModel ¶
type BoulderPieceModel struct { Kind PieceKind `json:"kind"` Player Player `json:"player"` Position [4]Point `json:"position"` }
BoulderPieceModel is the JSON model for a boulder piece.
type CurrentTurn ¶
type CurrentTurn struct { // Moves is the list of past valid moves that the player has made. Moves []Move // Plays is the number of plays that the player has left. Plays int // Player is the player whose turn it is. Player Player }
CurrentTurn is a type that represents the current turn in the game. A current turn instance will not contain any invalid moves, but it may not be a complete turn.
type DashMove ¶
type DashMove struct { ScoutPosition Point `json:"scout_position"` Destination Point `json:"destination"` }
DashMove represents a dash move. A player may dash a scout in any direction in 1 unit increments. The scout may not dash off the board.
func (*DashMove) MarshalText ¶
func (*DashMove) UnmarshalText ¶
type FormattedBoard ¶
type FormattedBoard string
FormattedBoard is a type that represents a board in a human-readable format. This is mostly used for debugging.
func FormatBoard ¶
func FormatBoard(board *Board) FormattedBoard
FormatBoard returns a human-readable representation of the board.
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game is a game instance.
func NewGameFromPastTurns ¶
NewGameFromPastTurns returns a new game instance from the given past turns.
func (*Game) CurrentTurn ¶
func (g *Game) CurrentTurn() CurrentTurn
CurrentTurn returns the current turn.
func (*Game) PastTurns ¶
PastTurns returns the past turns. It only contains valid turns. It does not contain the current turn.
func (*Game) PlayerPastTurns ¶
PlayerPastTurns returns the past turns for the given player. It only contains valid turns. It does not contain the current turn.
func (*Game) PossibleMoves ¶
func (g *Game) PossibleMoves(p Player) PossibleMoves
PossibleMoves returns the possible moves for the given player.
type JumpMove ¶
type JumpMove struct { ScoutPosition Point `json:"scout_position"` Destination Point `json:"destination"` }
JumpMove represents a jump move. A jump move describes a piece jumping over another piece in one of the four cardinal directions. A jump move costs 0 plays, but later jumps must be made on the same scout.
func (*JumpMove) MarshalText ¶
func (*JumpMove) UnmarshalText ¶
type Move ¶
type Move interface { encoding.TextMarshaler encoding.TextUnmarshaler fmt.Stringer // Type returns the move type. Type() MoveType // contains filtered or unexported methods }
Move is a type that represents a move.
type MoveType ¶
type MoveType string
MoveType is a type that represents a move type.
const BoulderMoveType MoveType = "boulder"
const DashMoveType MoveType = "dash"
const JumpMoveType MoveType = "jump"
const PlaceScoutMoveType MoveType = "place_scout"
const SkipMoveType MoveType = "skip"
type Moves ¶
type Moves []Move
Moves is a list of moves.
func (*Moves) MarshalText ¶
func (*Moves) UnmarshalText ¶
type PastTurn ¶
type PastTurn struct { // Moves is the list of past valid moves that the player has made. Moves []Move // Player is the player whose turn it is. Player Player }
PastTurn is a type that represents a turn in the game. A game turn instance must represent a valid turn, meaning it must contian no invalid moves.
type Piece ¶
type Piece interface { json.Marshaler // Kind returns the kind of the piece. Kind() PieceKind // Player returns the player that owns the piece. Player() Player // Position returns the position of the piece, which may be multiple points. Position() []Point }
Piece is a type that represents a piece on the board. A piece must be able to be marshaled to JSON. It must not be unmarshaled.
type PieceKind ¶
type PieceKind string
PieceKind is a type that can either be ScoutPiece or BoulderPiece.
type PlaceScoutMove ¶
type PlaceScoutMove struct {
ScoutPosition Point `json:"scout_position"`
}
PlaceScoutMove represents a place scout move. Each player must place 5 scouts on their base before the game begins.
func (*PlaceScoutMove) MarshalText ¶
func (m *PlaceScoutMove) MarshalText() ([]byte, error)
func (*PlaceScoutMove) String ¶
func (m *PlaceScoutMove) String() string
func (*PlaceScoutMove) UnmarshalText ¶
func (m *PlaceScoutMove) UnmarshalText(text []byte) error
type Player ¶
type Player int
Player is a type that represents a player.
func ParsePlayer ¶
ParsePlayer parses a player from a string. To convert a player to a string, use the String method.
type Point ¶
Point is a point on the board.
func (Point) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Point) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Point) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Point) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type PossibleMoves ¶
type PossibleMoves struct { // Moves is a list of possible moves. It never contains BoulderMove, since // that's a special case that's determined through the CanPlaceBoulder // field. Moves Moves `json:"moves"` // CanPlaceBoulder is whether or not the player can place a boulder. CanPlaceBoulder bool `json:"can_place_boulder"` }
PossibleMoves represents a list of possible moves.
func (PossibleMoves) String ¶
func (m PossibleMoves) String() string
type ScoutPiece ¶
type ScoutPiece struct {
// contains filtered or unexported fields
}
ScoutPiece is a type that represents a scout piece on the board.
func (*ScoutPiece) MarshalJSON ¶
func (p *ScoutPiece) MarshalJSON() ([]byte, error)
MarshalJSON marshals the scout piece to JSON.
func (*ScoutPiece) Player ¶
func (p *ScoutPiece) Player() Player
Player returns the player that owns the piece.
func (*ScoutPiece) Position ¶
func (p *ScoutPiece) Position() []Point
Position returns the position of the piece, which may be multiple points.
func (*ScoutPiece) Returning ¶
func (p *ScoutPiece) Returning() bool
Returning returns whether the scout is returning to its base.
type ScoutsPieceModel ¶
type ScoutsPieceModel struct { Kind PieceKind `json:"kind"` Player Player `json:"player"` Position Point `json:"position"` Returning bool `json:"returning"` }
ScoutsPieceModel is the JSON model for a scout piece.
type SkipMove ¶
type SkipMove struct{}
SkipMove represents a skip move.
func (*SkipMove) MarshalText ¶
func (*SkipMove) UnmarshalText ¶
type UnexpectedGameStateError ¶
type UnexpectedGameStateError struct { Expected gameState `json:"expected"` Actual gameState `json:"actual"` }
UnexpectedGameStateError is an error that is returned when the game state is not the expected game state.
func (UnexpectedGameStateError) Error ¶
func (e UnexpectedGameStateError) Error() string
type UnexpectedPieceError ¶
type UnexpectedPieceError struct { Position Point `json:"position"` Expected PieceKind `json:"expected"` Actual PieceKind `json:"actual"` }
UnexpectedPieceError is an error that is returned when a piece is not the expected piece.
func (UnexpectedPieceError) Error ¶
func (e UnexpectedPieceError) Error() string