Documentation ¶
Index ¶
- func DecodeMove(text string) (move common.Move, err error)
- func DecodePiece(fen rune, factory common.PieceFactory) (common.Piece, error)
- func DecodePieceStorage(fen string, pieceFactory common.PieceFactory, ...) (common.PieceStorage, error)
- func DecodePosition(text string) (position common.Position, err error)
- func EncodeMove(move common.Move) string
- func EncodePiece(piece common.Piece) string
- func EncodePieceStorage(storage common.PieceStorage) string
- func EncodePosition(position common.Position) string
- type PieceStorageFactory
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeMove ¶
DecodeMove ...
It decodes a move from pure algebraic coordinate notation.
Example ¶
package main import ( "fmt" "github.com/thewizardplusplus/go-chess-models/encoding/uci" ) func main() { move, _ := uci.DecodeMove("d4c3") fmt.Printf("%+v\n", move) }
Output: {Start:{File:3 Rank:3} Finish:{File:2 Rank:2}}
func DecodePiece ¶
DecodePiece ...
It decodes a piece from FEN (only a kind and a color, not a position).
func DecodePieceStorage ¶
func DecodePieceStorage( fen string, pieceFactory common.PieceFactory, pieceStorageFactory PieceStorageFactory, ) (common.PieceStorage, error)
DecodePieceStorage ...
It decodes a piece storage from FEN.
Example ¶
package main import ( "fmt" "sort" "github.com/thewizardplusplus/go-chess-models/boards" "github.com/thewizardplusplus/go-chess-models/common" "github.com/thewizardplusplus/go-chess-models/encoding/uci" "github.com/thewizardplusplus/go-chess-models/pieces" ) type ByPosition []common.Piece func (group ByPosition) Len() int { return len(group) } func (group ByPosition) Swap(i int, j int) { group[i], group[j] = group[j], group[i] } func (group ByPosition) Less(i int, j int) bool { a, b := group[i].Position(), group[j].Position() if a.File == b.File { return a.Rank < b.Rank } return a.File < b.File } func main() { const fen = "8/8/8/8/3B4/2r5/8/8" storage, _ := uci.DecodePieceStorage(fen, pieces.NewPiece, boards.NewMapBoard) pieces := storage.Pieces() sort.Sort(ByPosition(pieces)) fmt.Printf("%+v\n", pieces) }
Output: [{Base:{kind:2 color:0 position:{File:2 Rank:2}}} {Base:{kind:3 color:1 position:{File:3 Rank:3}}}]
func DecodePosition ¶
DecodePosition ...
It decodes a position from pure algebraic coordinate notation.
func EncodeMove ¶
EncodeMove ...
It converts the move to pure algebraic coordinate notation.
Example ¶
package main import ( "fmt" "github.com/thewizardplusplus/go-chess-models/common" "github.com/thewizardplusplus/go-chess-models/encoding/uci" ) func main() { move := uci.EncodeMove(common.Move{ Start: common.Position{File: 3, Rank: 3}, Finish: common.Position{File: 2, Rank: 2}, }) fmt.Printf("%v\n", move) }
Output: d4c3
func EncodePiece ¶
EncodePiece ...
It converts the piece to FEN (only a kind and a color, not a position).
func EncodePieceStorage ¶
func EncodePieceStorage(storage common.PieceStorage) string
EncodePieceStorage ...
It converts the piece storage to FEN.
Example ¶
package main import ( "fmt" "github.com/thewizardplusplus/go-chess-models/boards" "github.com/thewizardplusplus/go-chess-models/common" "github.com/thewizardplusplus/go-chess-models/encoding/uci" "github.com/thewizardplusplus/go-chess-models/pieces" ) func main() { board := boards.NewMapBoard(common.Size{Width: 5, Height: 5}, []common.Piece{ pieces.NewRook(common.Black, common.Position{File: 2, Rank: 2}), pieces.NewBishop(common.White, common.Position{File: 3, Rank: 3}), }) fen := uci.EncodePieceStorage(board) fmt.Printf("%v\n", fen) }
Output: 5/3B1/2r2/5/5
func EncodePosition ¶
EncodePosition ...
It converts the position to pure algebraic coordinate notation.
Types ¶
type PieceStorageFactory ¶
PieceStorageFactory ...
Click to show internal directories.
Click to hide internal directories.