Skip to main content

3. Knowledge- The Clue Game


Knowledge - Represent Knowledge Using Propositional Logic In Python


Introduction

Representing knowledge is the key issue in Artificial Intelligence. We can develop a knowledgeable AI agent that can analyze like humans. In this lesson, we will develop a game engine that will detect a murder based on its knowledge base. 


If we want a machine to be intelligent enough to think like a human, then first the machine needs some information about the real-world situation/problem. The knowledge of the real world needs to be represented to the machine in the right manner that is readable to a computer system. Propositional logic is one of the simplest methods of knowledge representation to a machine.


In this lesson, we will implement propositional logic to make our game engine knowledgeable, and then we will make able the engine to detect the murderer.



Background/ Interest

This report is a part of the “ CSE 418: Artificial Intelligence Lab” course at City University, Dhaka, Bangladesh conducted by Nuruzzaman Faruqui

This is the best AI course in Bangladesh. 


In this course, we learned AI from scratch. We started from Basic python and ended in Natural language processing. We learned theoretical concepts, essential mathematics properly in the “CSE 417: Artificial Intelligence” course, then implemented our knowledge in the Lab. We have done a lot of lab sessions to master the course and gradually we learned each necessary concept of Artificial Intelligence. 

Now we can build our machine learning model and also can build a neural network to solve a complex problem.



Problem Statement



Doctor Black has just been found dead in his mansion yesterday. Yesterday, there were only Three People in Doctor Black’s mansion. 

They are the prime suspects:

  1. Col. Mustard 

  2. Prof. Plum

  3. Ms. Scarlet

Police found Three Weapons in the mansion:

  1. Knife

  2. Revolver

  3. Wrench

The murder has happened in one of the Three Rooms of the mansion:

  1. Ballroom

  2. Kitchen

  3. Library



We have to find who is the murderer of Dr. Black. We can start creating the knowledge base of our game engine by adding the above information.

We will make our game engine knowledgeable by implementing propositional logic.  We will also receive further clues during the investigation. That will be also added to the knowledge base...



The Python Code to Develop The Clue Game

# we import termcolor to change the color in terminal window 

import termcolor

 

# we have imported 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 the 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 investigation time we got a clue that col. mustard, kitchen, the wrench is not suspicious. 


Further, step by step we have known that  Plum, Ballroom, Revolver is not suspicious too…








Each Clue was added to the knowledge base and finally, the Game engine has detected the Murderer, the Room, and the weapon. 







Conclusion

Firstly we explained the problem, then we implemented it in python code. Although the lesson was too easy, I hope you have learned a lot about propositional logic and how to do knowledge-based engineering in Artificial Intelligence.

However, you can develop a crime detection tool or similar board game by implementing the code snippet given above. In the previous lesson (2nd Article), we learned to generate new knowledge from the existing knowledge base without explicitly programming. You can also combine that idea in your project too. 

This is a simple and easier implementation of the “ CSE 418: Artificial Intelligence Lab” course at City University, Dhaka, Bangladesh conducted by Nuruzzaman Faruqui Sir. Which is the best AI course in Bangladesh. 

You are free to copy the code from here or some other concluding remarks.


Popular posts from this blog

9. Machine Learning - Banknote Authentication

  Building Machine Learning Model to Classify Fraud Bank Note Introduction Machine Learning!!!🤪 The highly interesting technology in today's world 😉. I know that you have heard a lot about it. Today we are going to build a machine learning model to authenticate banknote where it's authentic or not 💵.  Whenever you go to the bank to deposit some cash, the cashier places banknotes in a machine that tells whether a banknote is genuine or counterfeit.  The machine uses some classification techniques to do it. There are many machine learning algorithms for classification. Classification is a type of supervised machine learning. There are multiple machine learning algorithms in the classification. We understand it's hard to know the theoretical concept of each algorithm as a beginner. If it's true for you,  there is nothing to panic about.🤪  We will implement the 'K nearest neighbor, Support vector machine, Perceptron learning & Gaussian naive Bayes' algorithm

7. Optimization - Hill-Climbing Algorithm with "Random Restart" variant

Optimizing Cost Function Through Hill Climbing Algorithm & Random Restart Variant Introduction Hill climbing is a mathematical optimization algorithm, which means its purpose is to find the best solution to a problem that has a (large) number of possible solutions. Explaining the algorithm (and optimization in general) is best done using an example. In the Travelling salesman problem, we have a salesman who needs to visit a number of cities exactly once, after which he returns to the first city. The distances between each pair of cities are known, and we need to find the shortest route. As you can imagine, there is (often) a large number of possible solutions (routes) to a specific Travelling salesman problem; the goal is to find the best (i.e. the shortest) solution. Hill Climbing Variants Due to the limitations of Hill Climbing, multiple variants have been thought of to overcome the problem of being stuck in local minima and maxima. What all variations of the algorithm have in co