Movement validation of chess pieces

Before we allow chess pieces to move, we must have a record of all the possible movement options on the chessboard. At every move, we also need to check whether it is a legitimate turn for a given player and the proposed move should not cause check on the current player's king.

Now, check may occur on the king not only from a chess piece that was moved, but from any other chess piece on the chessboard as a consequence of such a movement. Thus, after every move, we need to calculate the possible moves for all the chess pieces of the opponent.

Accordingly, we will need two methods to do the following:

  • Keep a track of all the available moves for a player
  • Check whether there is check on the king

Let's add two new methods in the Model class (see 4.05model.py).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.189.251