chesskit-app / chesskit-swift

♟️ Swift package for implementing chess logic.
MIT License
7 stars 6 forks source link

Question for Game and Board model #36

Closed guiguil81 closed 2 days ago

guiguil81 commented 3 days ago

Hi !

I found your package and for me it's just a amazing package thank you !

I work on projet and i want to build a basic chessBoard game. For now i create a Board model and i create a board like board().

But i don't understand why you separate Board class and Game class ? if i want to implement chessBoard game i need to create Board and Game and make move on both ?

I see on Board class you have private isKingInCheck method. But it's private, if i implement a Game and a Board i don't have method for display game state ? like kinIsCheck ok checkmate etc ?

Thanks

pdil commented 3 days ago

Hey @guiguil81, thanks!

The reason for the two different objects is Board is used to validate the rules and piece movements of a game and represents the state of the game at a given position. This is why it has methods like legalMoves(for:) and move(pieceAt:to:).

On the other hand, Game manages all the positions in a game and is used so you can navigate between the different positions (forward, backward, variations, etc).

The two exist separately and you can use either as you see fit, it's not necessary to use both in all cases (but you will have to make moves in two different places if you want them to be in sync).

As for game state, you can use the BoardDelegate to receive updates when the game ends with checkmate or stalemate (see didEnd(with:)). Unfortunately it does not update when the king is in check but that is a good idea for a future improvement.

guiguil81 commented 2 days ago

Thanks for answer!

Now I understand the logic between Board and Game thank you. Yes, maybe it's a good improvement to see if king is in check haha

Thanks you for this package, and I can't wait to see further improvement!

pdil commented 2 days ago

Thank you! I've opened #38 to track that improvement.