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.
Comments
Post a Comment
If you have any doubts, please let me know