World Conquest Chronicles

World Conquest Chronicles

go-chess-models, v1.8

The library that implements checking and generating of chess moves.

Adding the chessmodels.SliceBoard structure; optimization.

Change Log

  • new features:
    • the chessmodels.BaseBoard structure that stores a board size;
    • the chessmodels.SliceBoard structure:
      • rename the chessmodels.Board structure to chessmodels.MapBoard;
      • add the chessmodels.SliceBoard structure;
      • add the chessmodels.SliceBoard structure to the go-chess-perft tool;
      • make the chessmodels.Board type redirect to the chessmodels.SliceBoard structure;
    • transform the Pieces() methods of the chessmodels.MapBoard and chessmodels.SliceBoard structures to an independent function;
    • the chessmodels.Size structure:
      • add the PositionIndex() method;
      • add the PositionCount() method;
      • add the IteratePositions() method;
  • refactoring:
    • optimize memory allocations;
  • unit testing:
    • slightly improve the tests of the chessmodels.MapBoard structure:
      • of the Piece() method;
      • of the ApplyMove() method;
    • add the benchmarks based on the chessmodels.Perft() function:
      • for the chessmodels.MapBoard structure;
      • for the chessmodels.SliceBoard structure.

Features

  • representing the board:
    • as an associative array of pieces with their positions as keys;
    • as a plain array of pieces with exact correspondence array indices to piece positions;
  • 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;
  • utilities:
    • utility for counting all possible moves (based on the perft function):
      • counting all possible moves:
        • parameters:
          • position;
          • color that moves first;
          • analysis deep;
      • profiling:
        • targets:
          • CPU usage;
          • memory usage;
        • storing the results to a file.

Benchmarks

The chessmodels.Perft() function using the chessmodels.MapBoard structure:

BenchmarkPerft/MapBoard/initial/1Ply-8               486       2239365 ns/op      507723 B/op      13638 allocs/op
BenchmarkPerft/MapBoard/initial/2Ply-8                38      27071904 ns/op     6253672 B/op     165159 allocs/op
BenchmarkPerft/MapBoard/initial/3Ply-8                 3     394039297 ns/op    91006645 B/op    2399815 allocs/op
BenchmarkPerft/MapBoard/kiwipete/1Ply-8              150       7844416 ns/op     1959120 B/op      47637 allocs/op
BenchmarkPerft/MapBoard/kiwipete/2Ply-8                4     311539966 ns/op    80169034 B/op    1892731 allocs/op

The chessmodels.Perft() function used the chessmodels.SliceBoard structure:

BenchmarkPerft/SliceBoard/initial/1Ply-8             810       1419572 ns/op       684016 B/op     13646 allocs/op
BenchmarkPerft/SliceBoard/initial/2Ply-8              68      17883575 ns/op      8331384 B/op    165074 allocs/op
BenchmarkPerft/SliceBoard/initial/3Ply-8               4     253594389 ns/op    121325578 B/op   2399248 allocs/op
BenchmarkPerft/SliceBoard/kiwipete/1Ply-8            220       5340912 ns/op      2583824 B/op     47672 allocs/op
BenchmarkPerft/SliceBoard/kiwipete/2Ply-8              5     208109435 ns/op    103011680 B/op   1895999 allocs/op

Repository

Link: https://github.com/thewizardplusplus/go-chess-models/tree/v1.8.0.

Content: code.

License: MIT.