Closed niklasf closed 7 years ago
We ran into each other once on github via the python-chess libray. Hello again!
The whole reason I developed this crate was to prevent duplication of work. As a result, I definitely think we should join forces on some of these things.
I would be completely fine with adding support for other chess variants, so long as it didn't affect performance on the main variant. I haven't looked at your implementation of how you did that yet.
I noticed that your implementation had UCI code in it. I was planning a separate chess engine communication library, that depends on the 'chess' crate. I definitely want to keep all the chess things organized, and as a result I definitely would want to keep the UCI/XBoard stuff separate.
Cool. How do you feel about switching to nightly Rust and adding some #[bench]
tests like these, so we can make sure that patches don't decrease performance?
Edit: associated_consts
would be another nice unstable feature to have. But if you need stable support that's ok, of course.
There are actually a few things from unstable that I want, but I'm trying to stick with stable for now. To take #[bench]
as an example, the entire framework has been unstable since rust 1.1, and has had very little work done on it since.
I'd be fine with using something like bencher
, however.
I'm not sure exactly where I'd use associated_consts
.
Edit: I saw you were using this: #[cfg(target_feature="bmi2")]
I will definitely be using that too once I can safely do it on stable.
Some general thoughts:
Board
struct. The only thing that I think would need to change is the castling rules. IIRC, if a 960 game is started with the normal board position, the rules of the game are exactly the same.BoardTrait
(named something better than that), that handles chess variants. Then, each variant can implement the same trait. At the end, if needed, we could have an enum AnyVariant { Chess(x), ThreeCheck(x) ... }
that impl
s BoardTrait
, and variant users could have easier access with that.chess
as a dependency?chess_syzygy
crate.chess_pgn
crate (maybe fork chess_pgn_parser
, which already exists?)chess_network
crate(s) (eg. lichess.org public API, FICS, ICC, or whatever else has an open API).UCI
and XBoard
.Edit: Thoughts?
That looks like a solid plan.
There's one thing that worries me: I just tried (as an experiment) to factor out the very basics (Square, Bitboard, ...) into their own crate: https://github.com/niklasf/rust-chess/commit/8ab2084561b20e6830d5af612a70da022fd027e4. This was a huge performance hit (6x slower). It seems that many optimizations don't work across crate boundaries. Not sure if there's anything that can be done about it ...
Update: Looks like #[inline]
includes code in the crate metadata to allow inlining across crates. In my experimental benchmark it achieves the same performance again. We just potentially have to put #[inline]
on a lot of stuff. (As opposed to #[inline(always)]
the compiler still can decide not to actually inline).
So with that I am happy to move forward ... first steps for me would be to polish Square
and Bitboard
and add Chess960 support.
It almost has to be non-inlined functions that is causing problems. I'll run valgrind when I get home on that branch and see if I can pinpoint the issue.
I'm not sure I like the structure of the chess_base
module that has been created.
One of the problems I immediately note is that many of the modules are not generic enough to support some chess variants. (For example, some variants are on an 8x10 board).
I'm not sure that separating out the squares/ranks/files/bitboards/etc from move generation for the base game is really gonna be helpful.
I think a better method may be to add lots of traits to the existing module.
I think the best place to start will be some sort of Board
trait, and some sort of MoveGen
trait.
I will work on this some this weekend I think. I'm really aiming to write a MoveGen
trait very soon to get rid of some ugly code there right now.
Yeah, the chess_base
module was just an experiment to see how such a thing would perform, not intended to actually merge.
Btw. I am only intrested in variants played on an 8x8 board. It's ok if you want to be even more general, but then we might have to switch to a move generation method other than bitboards.
Ok ... I think I can close this as we agree on the general direction. I'll post a patch every now and then.
Hi, recently I started another general purpose chess lib (https://github.com/niklasf/shakmaty) and found your crate only now. Now I wonder how to move forward without duplicating too much work.
Your crate is superior here:
Some missing features:
Now ... you may or may not want (all of) these features, which certainly come at the cost of some complexity. Before I continue with this essay ... what's your stance on this?
Best, Niklas