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
Challenge students with the following task:
With reference to Paragraph 1 Section 2 ask students to create and display an empty 8x8 board
# Create and display an empty 8x8 board using "." for empty spaces.
board = [
[".", ".", ".", ".", ".", ".", ".", "."], # Index 0 (Rank 8)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 1 (Rank 7)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 2 (Rank 6)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 3 (Rank 5)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 4 (Rank 4)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 5 (Rank 3)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 6 (Rank 2)
[".", ".", ".", ".", ".", ".", ".", "."], # Index 7 (Rank 1)
]
print(board)
for row in board:
print(row)
Observe and discuss the iterative structure in the code: this will be explored in more depth later.
With reference to Paragraph 1 Section 2 ask students to write a Python script that generates the data structure representing the board at the start of a game, correctly placing the pawns and the noble pieces (represented by letters).
Applied Concepts
Show and discuss the solution with students: 06_CreatingInitialPositions.pdf
Challenge students with the following task:
Imagine you want to place a White Knight on square g3. Write the Python code to:
Show and discuss the solution with students:
SOLUTION
# 1. Creation and assignment
square_g3 = "N"
# 2. Printing the content
print(square_g3)
Challenge students with the following task:
You have a list representing an empty rank: row = ["."] * 8. Write the code to transform this row into the black pawn configuration (all lowercase "p") using the multiplication operator and print the result.
Show and discuss the solution with students:
SOLUTION
# Transforming the row into black pawns
row = ["p"] * 8
# Printing the result
print(row)
# Expected Output: ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p']
Challenge students with the following task:
Given the following matrix representing part of a board:
Python
reduced_board = [
["r", "n", "b"], # Index 0
["p", "p", "p"], # Index 1
[".", ".", "."] # Index 2
]
Write the print command to display only the Black Knight ("n"), correctly accessing the matrix indices.
Show and discuss the solution with students:
SOLUTION
reduced_board = [
["r", "n", "b"],
["p", "p", "p"],
[".", ".", "."]
]
# Access: [row_index][column_index]
print(reduced_board[0][1])
Challenge students with the following task:
Starting from an empty rank rank_4 = ["."] * 8, a player moves a White Pawn to the fourth column (index 3). Write the code to change the element at index 3 from "." to "P" and print the updated list.
Show and discuss the solution with students:
SOLUTION
rank_4 = ["."] * 8 # Initially empty rank
# We move the white pawn ('P') to the fourth column (index 3)
rank_4[3] = "P"
print(rank_4)
# Expected output: ['.', '.', '.', 'P', '.', '.', '.', '.']
Challenge students with the following task:
You have created a list called noble_pieces = ["R", "N", "B", "Q", "K", "B", "N", "R"]. Write a line of code that uses a built-in Python function to print the total number of elements contained in this list.
Show and discuss the solution with students:
SOLUTION
noble_pieces = ["R", "N", "B", "Q", "K", "B", "N", "R"]
# Calculating and printing the length
length = len(noble_pieces)
print(length)
# Expected output: 8