Closed Starlight-30036225 closed 7 months ago
I need to find a way to do this that is not going to create an infinite loop as well, this is going to be tricky
For this reason, I might split possible moves into possible and legal. Possible moves will not check if the move is legal, and will be simplier, just returning intentions.
Legal moves will check all moves for legality before returning them. The legal move function therefore can call the possible move function of any number of pieces without it creating a loop.
Potentially...
To simulate a move, the initial location of a piece is saved to local variables. Then the piece is forcibly moved to the new location, ignoring legality. If there is a piece in the new location, it is saved to avoid being overriden.
Then the safety of the king is checked using the 'is location safe' function I created here #16. If the king is safe after this check, the move is legal.
This function is called for all moves created through the possible moves function
As seen here, the pawn is selected but has no valid moves.
The king can only move to spaces the bishop cannot attack.
And the night can only block the bishop.
This works perfectly.
Under the standard rules of chess, neither player can make a move that will put them in check. This means that I will need to simulate every move to see if doing so will put the king in check. If i can implement this, It should make the check system later a lot easier to implement.