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      
   There are t3 rooms :
  • kitchen 
  • Library
  • Ballroom 
There are 3 weapons : 
  • Knife 
  • Revolver 
  • wrench

There are 3 characters, 3 rooms, 3 weapons. One of the characters murders someone. Now we provide some clue to find out the murderer like, not in library not mr.plum like this. After analysis the information and the clue computer will give us the murderer. 



The python code to implement Game of Clue 

First, we have to import the logic file.  

 Pseudocode :

# 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 



Here we can see that Ms.Scarlet is the murderer. She had murdered in the library with Knife. If we give another clue in the pseudo code then we will get another result. Like, if we give in clue that,  Ms.Scarlet is not murderer then another one will be the murderer.

Conclusion : 
First, we introduced the problem. After that, we explain the problem and how we can solve the problem. then we explain the algorithm after that we write the code and give comments that's why you can easily understand the code. I hope anyone can easily understand the code. we discuss the result. If anyone follows this article then he/she can easily understand everything, They can also do this very easily. 
we can say this is the only reflection of the way that Sir has taught us. So this is the best AI course in Bangladesh. 
 
You are free to copy the code from here or some other concluding remarks

 

 


No comments

Powered by Blogger.