Geras1mleo / Chess

C# .NET 6.0 Chess Library
MIT License
49 stars 15 forks source link

Suggestion to add Move.IsPromotion and Move.IsEnpassant #20

Open shishiraiyar opened 8 months ago

shishiraiyar commented 8 months ago

I found a way to achieve this move.Parameter is MovePromotion returns true when the move is a promotion.

And to find out what the promoted piece is, I do

Piece p = new Piece(move.Parameter.ShortStr[1]);
Console.WriteLine(p.Type);

And to check whether a move is EnPassant, I do move.Parameter is MoveEnPassant

I guess this works since a move can't be both En Passant and promotion at the same time. But it's not very straightforward.

It would be nice if the library supported Move.Promotion which returns the promoted piece or null when there is no promotion.

Also consider adding Move.IsEnPassant and Move.IsCastling

Anyways, thanks for the amazing library.

Geras1mleo commented 8 months ago

I like the idea! Will do this in future versions... Thank you for your feedback!

AlphaYui commented 4 months ago

First of all, thanks for this awesome project! Also thanks for making this specific issue, I had the exact same problem and was happy with the solution shown here.

Knowing the solution, I'm honestly quite happy with the current implementation. You can elegantly check the type of move with an is statement and cast it to the specific type (e.g. MovePromotion) to get detailed information (e.g. to which piece the pawn is being promoted). For me this is mainly an issue of documentation. The Parameter property is named very generically and isn't found in the main documentation.

So my suggestion would be to rename the Parameter property to something more intuitive like "SpecialMoveDetails", add a more detailed description than "Move additional parameter", and include a short example in the main documentation on how it can be used to check for move type and get the move details from it.

Geras1mleo commented 4 months ago

@AlphaYui thank you for the feedback, I will make sure the docs are more descriptive