Saturday, February 19, 2011

A Simple example of Artificial Intelligence using Delphi The article explores Delphi approach to AI, using the pebble picking game.

Artificial Intelligence (AI) is an advance branch of science that studies the process of human thinking and attempts to apply the knowledge to simulate the same process in machines.

As computers are far ahead in the marathon of processing machines, AI is considered to be the branch of Computer Science than that of General Science. There have been many research and development in the field of Artificial Intelligence. The area of research include speech and pattern recognition, natural language processing, learning from previous experiences (learning by making and correcting mistakes!), reasoning under the situations providing limited or incomplete information etc. 

AI is practically applied in the field of computer games, expert systems, neural networks, robotics and many other fields of science and technology.

The game

In this article we will try to demonstrate a very simple practical example of artificial Intelligence programming in Delphi using Delphi arrays.

I have chosen a Nepali game named "GATTA TIPNE KHEL" (meaning pebble picking game) for this purpose. We can see small children playing this game in the playground. In this pebble picking game a pile of some pebbles is kept in the ground. One of the two players picks one, two or three pebbles at a time in his turn, leaving the pile for the other player to pick for his alternate turn. In this alternate picking process, the player who picks the last pebble(s) will be the loser and called to be a DOOM in Nepali. 

The main logic of the game is to leave the pile of pebbles with 13, 9, 5 or 1 pebble(s) for the opponent to pick. In the program the starting number of pebbles are set to 17, 21, 25, 29 … etc. so that computer could win always if it does not make a mistake. But in the real play computer seems to be gradually learning by correcting mistakes of the previously played games. At last it finds all its mistakes and corrects them to become an unbeatable champion. 

It seems computer simulates the psychological learning process of animal, learning by correcting and not repeating the mistakes. A multidimensional array of elements (1..4,1..3) is chosen as the instruction book for the computer to pick the pebbles. The instruction book contains four pages with three lines of instructions to pick pebbles. The first line instructs to pick a single pebble, the second line instructs to pick 2 and the third line instructs to pick 3 pebbles. At the beginning, computer chooses a random page and a random line of instruction to pick the pebble. 

When the game finishes, if computer looses the game, the last instruction is red-marked (erased) and the instruction will not be read in the future. After playing many games, all the instructions leading to a lost game will be red marked and there will be left only the instructions those lead to a win. Well, it is enough for the description of the game. Let us jump directly to the code... 

Download full game source code

http://delphi.about.com/od/gameprogramming/a/aigamesample.htm

 References:
delphiabout.com
Akash Mondal
MM09b001






No comments:

Post a Comment