https://github.com/savinrazvan/knights
A Python program that solves Knights and Knaves logic puzzles using propositional logic and model-checking algorithms. Determine the truthfulness of characters based on their statements to solve these classic logic puzzles.
https://github.com/savinrazvan/knights
ai algorithmic-puzzles educational-project game-theory knights-and-knaves logic-puzzles logical-reasoning model-checking propositional-logic puzzle-solver python raymond-smullyan
Last synced: 3 months ago
JSON representation
A Python program that solves Knights and Knaves logic puzzles using propositional logic and model-checking algorithms. Determine the truthfulness of characters based on their statements to solve these classic logic puzzles.
- Host: GitHub
- URL: https://github.com/savinrazvan/knights
- Owner: SavinRazvan
- License: mit
- Created: 2024-07-28T16:00:34.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-07-28T23:37:21.000Z (10 months ago)
- Last Synced: 2025-01-10T02:32:51.411Z (5 months ago)
- Topics: ai, algorithmic-puzzles, educational-project, game-theory, knights-and-knaves, logic-puzzles, logical-reasoning, model-checking, propositional-logic, puzzle-solver, python, raymond-smullyan
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## Project Title: Knights and Knaves Logic Puzzle Solver
### Project Description
This project involves developing a Python program to solve Knights and Knaves logic puzzles using propositional logic and model-checking algorithms. Inspired by Raymond Smullyan's puzzles, the challenge is to determine the truthfulness of characters (knights always tell the truth, knaves always lie) based on their statements. The project requires encoding logical sentences and leveraging a model-checking algorithm to deduce solutions for given puzzles.
### Background
Knights and Knaves puzzles feature characters who either always tell the truth (knights) or always lie (knaves). The task is to use propositional logic to analyze statements and determine the nature of each character.
### Files and Structure
- `logic.py`: Defines classes for logical connectives and the `model_check` function.
- `puzzle.py`: Contains knowledge bases and propositional symbols for characters A, B, and C.### Tasks
1. **Puzzle 0**: Single character A says “I am both a knight and a knave.”
2. **Puzzle 1**: Two characters, A and B. A says “We are both knaves.” B says nothing.
3. **Puzzle 2**: Two characters, A and B. A says “We are the same kind.” B says “We are of different kinds.”
4. **Puzzle 3**: Three characters, A, B, and C.
- A says either “I am a knight.” or “I am a knave.”, but you don’t know which.
- B says “A said 'I am a knave.'”
- B then says “C is a knave.”
- C says “A is a knight.”### How to Run
1. Download and unzip the distribution code.
2. Complete the knowledge bases for each puzzle in `puzzle.py`.
3. Run `python puzzle.py` to solve the puzzles.