Knowledge- Game of Clue
Introduction:
We often see news of murders on television. I think one question that has come to our mind that is how the police find out the murderer. When the police investigate the murders then they find some clue. After analyzing the clues they find the murderer. And they successfully catch the murderer. The game of clue is something like that . we will give some information or clue to our computer and the computer investigate the clues and will give us who is murderer.
First, we give some information to the computer. Then we give some clues. We apply knowledge base to analaysis the clue to find out the murderer.
This is an Artificial Intelligence course conducted in City Universit by Nuruzzaman Faruqui. This is the best course in Bangladesh. Because Sir explained all the necessary things to us well. The problem we are dealing with in the lab. First, sir gives us a very good idea of the problem by using many examples. After that sir explains about the solutions like how we can solve the problem, how they work. For that, we understand everything very easily.
Problem :
First, we have to know about the problem. The problem is :
There are 3 persons :
- Col.Mustard
- Mr. plum
- Ms.Scarlet
- kitchen
- Library
- Ballroom
- Knife
- Revolver
- wrench
The python code to implement Game of Clue
First, we have to import the logic file.
# we import termcolor to change the colour in terminal window import termcolor
# we have import the logic file
from logic import *
#Now we are symboling all of the charecters,rooms,weapons
mustard=Symbol("col.mustard")
plum=Symbol("ProfPlum")
scarlet=Symbol("MsScarlet")
charecters=[mustard,plum,scarlet]
ballroom=Symbol("ballroom")
kitchen=Symbol("kitchen")
library=Symbol("library")
rooms=[ballroom,kitchen,library]
revolber=Symbol("revolber")
knife=Symbol("knife")
wrench=Symbol("wrench")
wreapons=[revolber,knife,wrench]
# Now we are concating characters , rooms and weapons in symbols.
symbols=charecters+rooms+wreapons
# we are checking the model and get some truth value
def check_knowledge(knowledge_base):
for symbol in symbols:
if model_check(knowledge_base,symbol):
termcolor.cprint(f"{symbol}:YES","green")
elif not model_check(knowledge_base,Not(symbol)):
print(f"{symbol}:Maybe")
# Createing knowledge base
knowledge_base=And(
Or(mustard,plum,scarlet),
Or(ballroom,kitchen,library),
Or(knife,revolber,wrench)
)
# They are clue
knowledge_base.add(And(
Not(mustard),Not(kitchen),Not(wrench)
))
knowledge_base.add(Or(
Not(scarlet),Not(library),Not(wrench)
))
knowledge_base.add(Not(plum))
knowledge_base.add(Not(ballroom))
knowledge_base.add(Not(revolber))
check_knowledge(knowledge_base)
Result :
In the pseudo code we give all the information and the clue. If everything fine then we will get this type of result
No comments