Implementing Knights and Knaves using Artificial Intelligence in Python.!!

Before going to the program, we should know who is a knight and who is a knave.

A Knight is a person who will always say the truth whereas a Knave is a person who always lie.

The objective of the puzzle is, given a set of sentences spoken by each of the characters, determine, for each character, whether that character is a knight or a knave.

For example, consider a simple puzzle with just a single character named A. A says “I am both a knight and a knave.”

Logically, we might reason that if A were a knight, then that sentence would have to be true. But we know that the sentence cannot possibly be true, because A cannot be both a knight and a knave – we know that each character is either a knight or a knave, but not both. So, we could conclude, A must be a knave.

That puzzle was on the simpler side. With more characters and more sentences, the puzzles can get trickier!

The task in this problem is to determine how to represent these puzzles using propositional logic, such that an AI running a model-checking algorithm could solve these puzzles for us.

Source Code for the above project demonstration is given in the following link:

https://github.com/diesel707/Knights

The above program solves the following four puzzles.
Puzzle 0 A says "I am both a knight and a knave."
Puzzle 1 A says "We are both knaves." B says nothing.
Puzzle 2 A says "We are the same kind." B says "We are of different kinds."
Puzzle 3 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 says "C is a knave." C says "A is a knight."

Comments

Popular

Artificial Intelligence - How to implement Nim game using Python?