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
With reference to Part 2 ask your students to write a script that accepts two coordinates (start and finish) and returns True if the move is geometrically valid for a Rook, and False otherwise.
Applied Concepts
• Integer variables for coordinates.
• Comparison operators (==, !=).
• Conditional blocks.
Show and discuss the solution:
SOLUTION
def validate_rook_move(start_r, start_c, end_r, end_c):
"""
Checks if the move is geometrically valid for a Rook.
Does not check for obstacles in the path.
"""
# 1. Basic check: Did the rook actually move?
# If row AND column are the same, the piece stayed still.
if start_r == end_r and start_c == end_c:
return False # Illegal null move
# 2. Geometric check
if start_r == end_r:
# Row is the same, so it moved along the column (Horizontal)
return True
elif start_c == end_c:
# Column is the same, so it moved along the row (Vertical)
return True
else:
# Neither row nor column is preserved (e.g., diagonal)
return False
# Testing the code
print(f"Move 1 (Horizontal): {validate_rook_move(0, 0, 0, 5)}") # True
print(f"Move 2 (Diagonal): {validate_rook_move(0, 0, 5, 5)}") # False
Challenge students with the following task:
In FEN, uppercase is white and lowercase is black. Write a small script that, given a variable piece = "q", uses an if-else statement to print "Black" if the piece is "q" or "White" if the piece is "Q".
SOLUTION
piece = "q"
if piece == "q":
print("Black")
else:
print("White")
Challenge students with the following task:
A move is "null" if the starting position (r1, c1) is identical to the destination (r2, c2). Write an if block that checks this condition and prints "Invalid move: the piece stayed still" if the coordinates match.
SOLUTION
r1, c1 = 4, 4
r2, c2 = 4, 4
if r1 == r2 and c1 == c2:
print("Invalid move: the piece stayed still")
Challenge students with the following task:
Write a program that takes a variable column. If the column is 0 print "Left edge", if it is 7 print "Right edge", otherwise print "Central column".
SOLUTION
column = 7
if column == 0:
print("Left edge")
elif column == 7:
print("Right edge")
else:
print("Central column")
Challenge students with the following task:
Given r1 = 2 and r2 = 5, write the Python code that calculates the absolute difference between the two rows, saves it in the variable delta_r, and prints it.
SOLUTION
r1 = 2
r2 = 5
delta_r = abs(r1 - r2)
print(delta_r) # Output: 3
Challenge students with the following task:
Given a variable square = ".", write an if statement that checks if the square is occupied (i.e., if it is not equal to a dot) and prints "Square occupied".
SOLUTION
square = "R" # Example: there is a Rook
if square != ".":
print("Square occupied")