In your implementation a piece appears to be something like an immutable object. The white pawn that is on d2 in the initial position is always that particular pawn. Promoting a pawn to a queen means to take that pawn object from the board and to put a new queen object on the promotion square instead. Therefore for unmaking a promotion you need to remember that particular pawn somehow in order to restore it after removing the queen. As you see this can cause trouble.Henk wrote:Join the club. If I try to explain it, it probably won't help I I'll be busy the next two hours talking about things no one understands.JVMerlino wrote:Nor I....elcabesa wrote:I didn't understand anything
What's easy to understand is this:
If you play pawn moves d3-d2 .. d2-d1 .. Qd1-a1 and later with another pawn e3xd2 and later d2-d1. You have two identical promotion moves (d2-d1)
played one stems from the d-pawn and the other from the e-pawn.
But you could also think about a slightly different modelling of pieces, by making their piece type a property that can be changed. You would have two operations on a piece object for that purpose:
Code: Select all
void promote(PieceType promotionPieceType); // change piece type into given type
void unpromote(); // change piece type into "Pawn"
In many chess engines the representation of pieces and their types is even simpler.
Sven