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
In the real world, a question can have nuanced answers. In computer science, at the lowest level, everything is black or white (or rather, 1 or 0).
The Boolean Value
A chess move has a fundamental property: it is either Legal or Illegal. There is no such thing as a "more or less legal" move. This binary state is represented by the Boolean data type.
Comparison Operators
To obtain a boolean, we must ask the computer questions by comparing values. Let's imagine we want to check if a square is empty. In Chapter 1, we decided that an empty square contains the string ".".
Chess Question | Python Code | Operator | Explanation |
Is the square empty? | content == "." | == (Equal to) | Checks if two values are identical. |
Is the square occupied? | content != "." | != (Not equal to) | Checks if two values are different. |
Is the piece a King? | piece == "K" | == | Verifies identity. |
Warning: In programming, = is used to assign a value (putting the piece in the box), while == is used to compare (asking if the content is equal to something).