The ChessAIThon project (2025-1-ES01-KA220-VET-000354329) is co-funded by the European Union. The views and opinions expressed in this publication are those of the author(s) only and do not necessarily reflect those of the European Union or the Spanish Service for the Internationalisation of Education (SEPIE). Neither the European Union nor the National Agency SEPIE can be held responsible for them.
Table of Contents
Now that we know how to ask questions (True/False), we must act based on the answer. This is where conditional statements come in: If, Elif (Else if), and Else.
Let’s use the Rook as an example. The Rook moves only horizontally or vertically. To move a rook from a starting position (r1, c1) to a destination (r2, c2), one of these two conditions must be true:
The if / else Structure
# Starting coordinates (row, column)
r1, c1 = 4, 4 # Example: Square e5 (indices 4, 4)
# Destination coordinates
r2, c2 = 4, 7 # Example: Square h5 (indices 4, 7)
# Geometric validation logic
if r1 == r2:
print("Valid Horizontal move for the Rook")
elif c1 == c2:
print("Valid Vertical move for the Rook")
else:
print("Error: The Rook cannot move diagonally or in an L-shape")
Code Analysis: