go-chess-models, v1.7.1
Posted on

The library that implements checking and generating of chess moves.
Moving the chessmodels.perft() function from the tests to the main code; adding the go-chess-perft tool and the example for the chessmodels.MoveGenerator.MovesForColor() method; bug fixing.
Change Log
- new features:
- transform the
chessmodels.Board.CheckMove()method to an independent function; - the
chessmodels.Perft()function:- move the
chessmodels.perft()function from the tests to the main code; - pass a handler to all levels in the
chessmodels.Perft()function; - pass a move generator to the
chessmodels.Perft()function via an interface;
- move the
- add the
go-chess-perfttool:- counting all possible moves:
- parameters:
- position;
- color that moves first;
- analysis deep;
- parameters:
- profiling:
- targets:
- CPU usage;
- memory usage;
- storing the results to a file;
- targets:
- counting all possible moves:
- transform the
- bug fixing:
- fix rune conversion from an integer to a string in the
uci.EncodePosition()function; - fix incorrect calculation of the last file in the
uci.EncodePieceStorage()function;
- fix rune conversion from an integer to a string in the
- refactoring:
- simplify the utility functions in the
piecespackage; - merge the
chessmodels.pieceGrouptype with thechessmodels.Boardstructure;
- simplify the utility functions in the
- unit testing:
- complete the tests:
- of the
pieces.NewPiece()function; - of the
uci.DecodePiece()function; - of the
uci.EncodePiece()function;
- of the
- add the long-playing tests to the Travis CI configuration;
- complete the tests:
- examples:
- remove the examples:
- remove the examples with a mock piece;
- remove the redundant examples;
- add the example for the
chessmodels.MoveGenerator.MovesForColor()method.
- remove the examples:
Features
- representing the board as an associative array of pieces with their positions as keys;
- immutable applicating moves to the board via copying the latter;
- checkings of moves:
- universal;
- individual for all types of pieces;
- generating moves via filtering from all possible ones;
- perft function;
- using an abstraction of a piece;
- Forsyth–Edwards Notation:
- parsing:
- of a position;
- of a move;
- of a piece kind;
- of a piece color;
- of a board;
- serialization:
- of a position;
- of a move;
- of a piece kind;
- of a piece color;
- of a board;
- parsing:
- utilities:
- utility for counting all possible moves (based on the perft function):
- counting all possible moves:
- parameters:
- position;
- color that moves first;
- analysis deep;
- parameters:
- profiling:
- targets:
- CPU usage;
- memory usage;
- storing the results to a file.
- targets:
- counting all possible moves:
- utility for counting all possible moves (based on the perft function):
Examples
chessmodels.MoveGenerator.MovesForColor():
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}}
}
Installation of the go-chess-perft Tool
$ go get github.com/thewizardplusplus/go-chess-models/cmd/go-chess-perft
Usage of the go-chess-perft Tool
$ go-chess-perft -h | -help | --help
$ go-chess-perft [options]
Options:
-h,-help,--help— show the help message and exit;-fen STRING— board in Forsyth–Edwards Notation (default:rnbqk/ppppp/5/PPPPP/RNBQK, i.e., Gardner's minichess);-color {black|white}— color that moves first (default:white);-deep INTEGER— analysis deep (default:5);-cpuProfile STRING— file for CPU profile writing;-memoryProfile STRING— file for memory profile writing.
Repository
Link: https://github.com/thewizardplusplus/go-chess-models/tree/v1.7.1.
Content: code.
License: MIT.