Documentation ¶
Index ¶
- Variables
- func CheckMove(storage PieceStorage, move Move) error
- func Perft(generator PerftMoveGenerator, storage PieceStorage, color Color, deep int, ...) int
- type BaseBoard
- type Board
- type Color
- type Kind
- type MapBoard
- type Move
- type MoveGenerator
- type PerftHandler
- type PerftMoveGenerator
- type Piece
- type PieceStorage
- type Position
- type PositionHandler
- type Size
- type SliceBoard
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoMove = errors.New("no move") ErrOutOfSize = errors.New("out of size") ErrNoPiece = errors.New("no piece") ErrFriendlyTarget = errors.New("friendly target") ErrIllegalMove = errors.New("illegal move") ErrKingCapture = errors.New("king capture") )
...
Functions ¶
func CheckMove ¶
func CheckMove(storage PieceStorage, move Move) error
CheckMove ...
It doesn't check for a check before or after the move.
func Perft ¶
func Perft( generator PerftMoveGenerator, storage PieceStorage, color Color, deep int, handler PerftHandler, ) int
Perft ...
Types ¶
type BaseBoard ¶ added in v1.8.0
type BaseBoard struct {
// contains filtered or unexported fields
}
BaseBoard ...
type MapBoard ¶ added in v1.8.0
type MapBoard struct { BaseBoard // contains filtered or unexported fields }
MapBoard ...
func (MapBoard) ApplyMove ¶ added in v1.8.0
func (board MapBoard) ApplyMove(move Move) PieceStorage
ApplyMove ...
It doesn't check that the move is correct.
func (MapBoard) CheckMove ¶ added in v1.8.0
CheckMove ...
It doesn't check for a check before or after the move.
type Move ¶
Move ...
type MoveGenerator ¶
type MoveGenerator struct{}
MoveGenerator ...
func (MoveGenerator) MovesForColor ¶
func (generator MoveGenerator) MovesForColor( storage PieceStorage, color Color, ) ([]Move, error)
MovesForColor ...
It doesn't guarantee an order of returned moves.
It doesn't take into account possible checks and can generate such moves.
It returns an error only on a king capture.
Example ¶
package main import ( "fmt" "sort" models "github.com/thewizardplusplus/go-chess-models" "github.com/thewizardplusplus/go-chess-models/pieces" ) func main() { board := models.NewBoard(models.Size{Width: 5, Height: 5}, []models.Piece{ pieces.NewRook(models.Black, models.Position{File: 2, Rank: 2}), pieces.NewKnight(models.White, models.Position{File: 3, Rank: 3}), pieces.NewPawn(models.White, models.Position{File: 4, Rank: 3}), }) var generator models.MoveGenerator moves, _ := generator.MovesForColor(board, models.White) // sorting only by the final point will be sufficient for the reproducibility // of this example sort.Slice(moves, func(i int, j int) bool { a, b := moves[i].Finish, moves[j].Finish if a.File == b.File { return a.Rank < b.Rank } return a.File < b.File }) for _, move := range moves { fmt.Printf("%+v\n", move) } }
Output: {Start:{File:3 Rank:3} Finish:{File:1 Rank:2}} {Start:{File:3 Rank:3} Finish:{File:1 Rank:4}} {Start:{File:3 Rank:3} Finish:{File:2 Rank:1}} {Start:{File:3 Rank:3} Finish:{File:4 Rank:1}} {Start:{File:4 Rank:3} Finish:{File:4 Rank:4}}
func (MoveGenerator) MovesForPosition ¶
func (generator MoveGenerator) MovesForPosition( storage PieceStorage, position Position, ) ([]Move, error)
MovesForPosition ...
It doesn't take into account possible checks and can generate such moves.
It returns an error only on a king capture.
type PerftMoveGenerator ¶
type PerftMoveGenerator interface {
MovesForColor(storage PieceStorage, color Color) ([]Move, error)
}
PerftMoveGenerator ...
type Piece ¶
type Piece interface { Kind() Kind Color() Color Position() Position ApplyPosition(position Position) Piece // It shouldn't check that move positions is inside the board. // // It shouldn't check that the move finish position isn't equal // to its start position. // // It shouldn't check that the start move position corresponds // to the piece position. // // It shouldn't check that there isn't a friendly piece // on the move finish position. // // It shouldn't check that there isn't an enemy king // on the move finish position. // // It shouldn't check for a check before or after the move. CheckMove(move Move, storage PieceStorage) bool }
Piece ...
type PieceStorage ¶
type PieceStorage interface { Size() Size Piece(position Position) (piece Piece, ok bool) Pieces() []Piece // It shouldn't check that the move is correct. ApplyMove(move Move) PieceStorage // It shouldn't check for a check before or after the move. CheckMove(move Move) error }
PieceStorage ...
func NewMapBoard ¶ added in v1.8.0
func NewMapBoard(size Size, pieces []Piece) PieceStorage
NewMapBoard ...
func NewSliceBoard ¶ added in v1.8.0
func NewSliceBoard(size Size, pieces []Piece) PieceStorage
NewSliceBoard ...
type PositionHandler ¶ added in v1.8.0
PositionHandler ...
type Size ¶
Size ...
func (Size) IteratePositions ¶ added in v1.8.0
func (size Size) IteratePositions(handler PositionHandler) error
IteratePositions ...
func (Size) PositionIndex ¶ added in v1.8.0
PositionIndex ...
type SliceBoard ¶ added in v1.8.0
type SliceBoard struct { BaseBoard // contains filtered or unexported fields }
SliceBoard ...
func (SliceBoard) ApplyMove ¶ added in v1.8.0
func (board SliceBoard) ApplyMove(move Move) PieceStorage
ApplyMove ...
It doesn't check that the move is correct.
func (SliceBoard) CheckMove ¶ added in v1.8.0
func (board SliceBoard) CheckMove(move Move) error
CheckMove ...
It doesn't check for a check before or after the move.