This project is a mandatory assignment from CS50AI – Lecture 1: "Knowledge".
To run the project locally, follow these steps:
-
Clone the repository to your local machine.
-
Navigate to the project directory:
cd path/to/knowledge -
Run
python puzzle.py
This project is an implementation of the "Knights and Knaves" logic puzzles as described in Raymond Smullyan's book "What is the Name of This Book?". In these puzzles, characters are either knights, who always tell the truth, or knaves, who always lie. The objective is to determine the identity of each character based on their statements.
Using propositional logic and logical connectives, this project models and solves four puzzles. It demonstrates how logical reasoning can be represented programmatically to allow an AI system to solve problems using model checking. The solution uses the logic.py framework provided as part of the project distribution to define logical sentences and perform model checks.
I implemented the "global knowledge" and the logical knowledge bases for four puzzles by translating the rules and statements into propositional logic. This involved:
-
Understanding the puzzle structure and constraints.
-
Encoding the rules for knights and knaves.
-
Translating each character's statements into logical expressions.
-
Using implications to capture the truth-telling or lying behavior of knights and knaves.