Introducing Chess V2: A New Chess Library in Golang
This has been a project I've been working on for a good bit now, and I'm finally excited to announce version 2.0 of my chess library written in Golang. I've learned a ton from this project, and I'm excited to share it with the world.
Repo - https://github.com/brighamskarda/chess
Docs - https://pkg.go.dev/github.com/brighamskarda/chess/v2
Performance
Version 2 was pretty much rebuilt from the ground up and is overall much more organized and performant. The best maintained chess library currently available in Golang is CorentinGS/chess, and I am pleased to say that in most benchmarks my library equivalent in speed.
In fact, the move generation (arguably the most important metric) in my library is up to 40% faster (sometimes even more)!
Postition | brighamskarda | CorentinGS |
---|---|---|
Starting | 2820ns | 4448ns |
Midgame | 6026ns | 9987ns |
Endgame | 2167ns | 4468ns |
My library does use more heap allocations overall though, which may reduce performance in larger environments. This is yet to be seen though.
A Few Things I'm Proud Of
Here are a few of the things I'm proud of with this project.Documentation
I've made an effort to provide good documentation with examples. Documentation is something that can easily be set aside, but I feel it is something that separates good libraries from great libraries. Even including just a few examples really helps one figure out which parts of the library are most important.
Robust PGN Parsing
Anytime you're dealing with user generated data such as a PGN file, things get difficult. Once you get into it, the PGN specification is not as concrete as one would hope. But I feel like I've done a good job making a PGN parser that should accept most files it comes across.
Bitboards
Bitboards can be a daunting task for someone just getting into chess development. This project forced me to learn about them, and now I am much more familiar bit operations than I ever was before.
I didn't use magic bitboards as those are still rather confusing to me. But in retrospect I got probably 90% of the benefits from bitboards even without using them.
An Optimized Position Type
Forgoing move validation on the position type is a huge improvement for engine development. Moving a piece is now a really fast operation, and position is now a more flexible type that does not need to enforce legality as much.
What's Next?
Development does not stop here. I still have a lot of plans for this library. Implementing the UCI standard for engine development is the next big goal. This will really round out the library for engine development and make it a more useful tool overall.
And of course, if you the reader have any ideas, or would like to contribute feel free to look at the github page, or email me at [email protected].