hahaharry10 / Chess-Game

This project will create a command line chess game that will talk wirelessly to a second device.
0 stars 0 forks source link

scan for check and checkmate. #14

Closed hahaharry10 closed 1 year ago

hahaharry10 commented 1 year ago

Code can already identify if the player is in check however checkmate checker needs to be implemented

hahaharry10 commented 1 year ago

A way to scan for checkmate is to:

1) Scan for check. 2) Check if the king can move out of check. 3) Check if the attacking piece can be taken. 4) Check if any piece can be played to obstruct the check.

The function has an integer return type and will return only 3 values:

The steps to conduct each are: 1) Scan for check.

hahaharry10 commented 1 year ago

upon reflection steps 3 and 4 can be implemented in the same function and will be implemented as one

hahaharry10 commented 1 year ago

in the checkCanBeObstructed() function, I will need to create a path between the check-threatening pieces and the king, I have found the following logic to be appropriate and to reduce computational power:

If there is one check-threatening piece then I just need to create a path for that one threat.

If there are multiple check-threatening pieces I still only need to map out a singular path as the opponent can only move once per go, their next move must simultaneously obstruct both threats. Therefore the algorithm will work like this:

  1. map out a singular path between a check-threatening piece and a king.
  2. Check if the check can be obstructed. If the check can be obstructed check if it also obstructs other threats. If not move on.
  3. If a move that obstructs the check also obstructs the other threats then the player is just in check. If no move can be found then the player is in checkmate
hahaharry10 commented 1 year ago
  1. If a move that obstructs the check also obstructs the other threats then the player is just in check. If no move can be found then the player is in checkmate

You do not need to check the path for a knight as a knights path cannot be obstructed, you only need to check if it can be taken.

hahaharry10 commented 1 year ago

hopefully, by the time the path begins to be mapped, the checkers will guarantee that every threatening piece can reach the opposing king, therefore I can write an abstract path mapping algorithm that does not need to be piece specific. Apart from the knight that requires a specific algorithm as the path cannot be obstructed.

hahaharry10 commented 1 year ago

only escape from a double check is a king move! further simplifies implementation