adjacent files, one rank ahead of it. Additionally, what is considered to be forward differs based on color, and thus color must also be addressed. Rook The Rook moves only in Simply XORing the straight horizontal or results of checking that vertical lines. the file and rank of the source and destination are equal returns a truth value corresponding to the validity of the move. Knight The Knight moves in an A naive approach might L-shaped pattern, sum the absolute values advancing two spaces in of the differences one direction and one between the destination space perpendicularly. and source file and rank and equate this to the value 3. This would allow the Knight to move three spaces in straight lines. Instead, the CyberChess engine checks whether the sum of the squares of these distances is 5, ensuring that only moves matching the Knight’s movement pattern register as valid, while also removing the need for the slightly more intensive operation of finding absolute value. Bishop The Bishop moves only Equating the squares of in straight diagonal lines. the differences between destination and source files and ranks returns the validity of the move.
adjacent files, one rank ahead of it. Additionally, what is considered to be forward differs based on color, and thus color must also be addressed. Rook The Rook moves only in straight horizontal or vertical lines. Simply XORing the results of checking that the file and rank of the source and destination are equal returns a truth value corresponding to the validity of the move. Knight The Knight moves in an L-shaped pattern, advancing two spaces in one direction and one space perpendicularly. A naive approach might sum the absolute values of the differences between the destination and source file and rank and equate this to the value 3. This would allow the Knight to move three spaces in straight lines. Instead, the CyberChess engine checks whether the sum of the squares of these distances is 5, ensuring that only moves matching the Knight’s movement pattern register as valid, while also removing the need for the slightly more intensive operation of finding absolute value. Bishop The Bishop moves only in straight diagonal lines. Equating the squares of the differences between destination and source files and ranks returns the validity of the move.