This project is a simple introduction to knowledge representation and reasoning using classic Knights and Knaves logic puzzles.
It was created as Problem Set 2 (Knowledge) for our Introduction to Artificial Intelligence course.
In these puzzles:
- A Knight always tells the truth.
- A Knave always lies.
- Each character is exactly one of the two.
We write what each character says using logic, then let the program figure out who must be a knight or a knave.
| File | Purpose |
|---|---|
logic.py |
Basic logic system (symbols, AND, OR, NOT, implication, and model checking). |
puzzles.py |
Defines the puzzles and prints the results. |
- We create symbols like:
"A is a Knight"and"A is a Knave". - We enforce that exactly one of those is true for each person.
- We translate each statement into logic.
- The program tests all possibilities (models) and keeps only the ones that fit the rules.
- Anything true in every valid model is printed.
python puzzles.pyYou will see output for each puzzle showing which roles are definitely true.