rudzen / ChessLib

C# chess library containing a complete data structure and move generation.
MIT License
81 stars 22 forks source link

api documentation #18

Closed amryounis closed 4 years ago

amryounis commented 5 years ago

hi, could you provide some summary of the api

rudzen commented 5 years ago

Hi.. The library functionality is well documented at code level. So at the moment there are no plans to provide more documentation. Unless of course there is a specific issue with it.

JamesLear92 commented 4 years ago

Hi, Thanks for releasing this code. I have to admit I've spent a couple of minutes now trying to work out how to use this library, despite the well commented code.

For instance, how can I create a new game? The constructor for Game has an iposition parameter, so we have to find a position class which has that interface and find the constructor for that; I find the constructor and there are no parameters, but it's not immediately clear to me if a new position has any pieces by default.

Also game has a lot of the same methods as position, should we be calling these methods from game or the position?

Cheers again for your hard work on this.

rudzen commented 4 years ago

Hi, Thanks for releasing this code. I have to admit I've spent a couple of minutes now trying to work out how to use this library, despite the well commented code. For instance, how can I create a new game? The constructor for Game has an iposition parameter, so we have to find a position class which has that interface and find the constructor for that; I find the constructor and there are no parameters, but it's not immediately clear to me if a new position has any pieces by default.

The Position class implements the IPosition interface so you can simply create a new Position. Then you can use that Position reference when creating a Game reference.

For starting a new game with start position you can do something like

var position = new Position();
var game = GameFactory.Create(position);
var actual = game.NewGame();

The NewGame method has a overload for a FEN string which allows to set the position in the game without having to re-create a new Position object.

You can use the Pos property as it will always contain the current position data (updated when moves are made etc).

To retrieve what pieces that currently is in the game, I would recommend you use the game property Occupied or the various methods on the Position property directly through the game object. This will give a bitboard with the square position of all pieces, which you can simply use a foreach loop like this

var pieces = game.Occupied;
foreach (var sq in pieces)
{
    var piece = game.Pos.GetPiece(sq);
    Console.WriteLine(piece.ToString());
}

Also game has a lot of the same methods as position, should we be calling these methods from game or the position?

I believe you are thinking about the MakeMove() and TakeMove() methods, as they seem very identical.

Where possible, always use the methods located in the game object. If needed, they will use the position variants of those same methods.

The reason for this is that its possible to use the Position class by itself for various things with respects to UI stuff etc.

Cheers again for your hard work on this.

Thanks