Axololly.Chess.MoveGenerator 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Axololly.Chess.MoveGenerator --version 1.0.0                
NuGet\Install-Package Axololly.Chess.MoveGenerator -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Axololly.Chess.MoveGenerator" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Axololly.Chess.MoveGenerator --version 1.0.0                
#r "nuget: Axololly.Chess.MoveGenerator, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Axololly.Chess.MoveGenerator as a Cake Addin
#addin nuget:?package=Axololly.Chess.MoveGenerator&version=1.0.0

// Install Axololly.Chess.MoveGenerator as a Cake Tool
#tool nuget:?package=Axololly.Chess.MoveGenerator&version=1.0.0                

Chess Move Generator

If you can't beat em, join em. And that's what I did when I stayed inside for the last month every evening developing this chess move generator.

If I ever hate myself enough to make a Python version, I'll link it here.

Statistics

Quick section about the statistics of this project:

Source Code

File name Lines Characters File size
Board.cs 1,121 42,128 42.23 KB
Board960.cs 984 38,495 38.55 KB
Utilities.cs 232 7,451 7.50 KB
Bitmasks.cs 86 2,679 2.70 KB
Castling.cs 45 1,742 1.74 KB
Castling960.cs 97 3,656 3.66 KB
Generator.cs 561 19,372 19.46 KB
MagicBitboards.cs 318 17,169 17.08 KB
Tables.cs 59 1,851 1.86 KB
Perft.cs 373 12,147 12.23 KB
Bitboard.cs 119 3,768 3.79 KB
CastlingRights.cs 60 2,081 2.09 KB

Using my project

Quick heads up: I used .NET 8.0 for this.

I have no idea where or how you publish a C# package, so I'll just list how you use the code here, if you ever build the code yourself.

Example Code

using Chess;

class Program
{
    static void Main()
    {
        Board board = new();

        var nextMoves = board.GenerateLegalMoves();

        Console.WriteLine($"Board:\n{board}\n");
        Console.WriteLine($"Next moves: [{string.Join(", ", nextMoves)}]");
    }
}

Result

Board:
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
P P P P P P P P
R N B Q K B N R

Next moves: [b1a3, b1c3, g1f3, g1h3, a2a3, b2b3, c2c3, d2d3, e2e3, f2f3, g2g3, h2h3, a2a4, b2b4, c2c4, d2d4, e2e4, f2f4, g2g4, h2h4]

Note about Chess960

Chess960 is the exact same, just change the using directory to be Chess960 and use the Board960 class instead of the Board class. The methods for controlling the state of the board are identical.

Move Generation Order

  1. Rooks

    • Using magic bitboards
    • Includes the rook part of queen moves
  2. Bishops

    • Using magic bitboards
    • includes the diagonal part of queen moves
  3. Knights

  4. Pawns

    • Single pushes (with and without promotion)
    • Double pushes
    • Left attacks (with and without promotion)
    • Right attacks (with and without promotion)
    • En-passant (thanks to @Disservin for Smallbrain and its EP code)
  5. Normal King Moves

    • Evading checks
    • Not stepping on squares attacked by the opponent
    • Not capturing pieces protected by the opponent
  6. Castling

    • Not supported if in check
    • Not supported if pieces are blocking the path
    • Not supported if pieces are attacking the path
    • Not supported if already castled

All of how I programmed my move generation can be found in the conveniently named folder in this repository called Move Generation.

At some point, I'll write up a bunch of documentation, well, documenting everything about this project in the Documentation folder, which, as of writing this, is about two and a half, maybe three weeks behind schedule. Over the next few days, I'll update it with everything it's missing.

Perft Data

I translated TheRealGioviok's raw text file of example FEN positions and their associated depths, and converted it into a JSON file 74,272 lines long. Substantially longer, but easier to manage.

Each document is structured like this:

{
    "FEN": ...,
    "Depths": {
        "1": ...,
        "2": ...,
        "3": ...,
        "4": ...,
        "5": ...,
        "6": ...
    }
}

And in total, there are around 6,600 of these that you can use to verify that your engine returns the correct move counts.

If you want to perft test my own project, you can do it with the Perft and Perft960 classes, which have the available features: |Type|Method|Explanation| |:-|:-|:-| |Basic|.BasePerftTest()|Returns the number of counted nodes at the end of the function.| |Move-by-Move|.MoveByMovePerftTest()|Prints the move and number of counted nodes, returning the total at the end.| |Global|.GlobalPerftTest()|Prints the number of counted nodes until a given depth is reached.| |Output|.OutputPerftTest()|Redirects the console output into a file for further review.|

All of these work with Chess960 boards - you just need to use Perft960 instead of Perft.

Thanks

Honestly, thank you to everyone in the Stockfish Discord server, from Analog Hors and her magic bitboards article, all the way to Disservin, who I already mentioned above for his code relating to en-passant moves.

It means a lot to me, knowing I've finally completed a project that frustrated me back when I started in June. I learnt a new language, made new friends, and, most importantly, had a lot of fun with this.

So proud of how far I've come. Time to celebrate! 🎉

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.3 71 11/17/2024
1.2.1 123 10/20/2024
1.2.0 126 10/19/2024
1.1.6 97 10/3/2024
1.1.5 86 10/3/2024
1.1.4 101 10/3/2024
1.1.3 98 9/30/2024
1.1.2 85 9/29/2024
1.1.1 92 9/29/2024
1.1.0 92 9/29/2024
1.0.0 91 9/24/2024