Showing posts with label ai. Show all posts
Showing posts with label ai. Show all posts

Friday, September 26, 2008

The Most Simple Introduction to Artificial Neural Networks


I would like to share you a good stuff on learning the basic of Artificial Neural Networks.

Artificial Neural Networks (ANNs), often refer to as Neural Networks, is one of the most well-known tool in Machine Learning. There are many websites available which provide basic theory of Neural Networks so I will not cover them here.

The hard part about ANNs is the Mathematics involed, how to implement them, and apply them to good use. There are many articles in CodeProject.com that try to present the ANNs in a simple, reusable ways. But, in my personal opinion, they are all hard to understand and reuse. I had read some of these articles once and I found that most of the content are too advanced. I just need to know a very basic part of ANNs and put them into good use, in short time.

I also have to admit that, sometimes, Object-oriented and Reusability are what make the code more harder to understand than it should be. I just need a "top-to-bottom" code in single method that explains what is going on. Distributing the data and logic in OO style is just not suitable for the purpose of learning algorithm.

Then, I came across this page: Implementing a Neural Network in C. This page explains very briefly everything you need to know and implementing an ANNs. And, most of all, the code is in non-object-oriented C language! That makes it is easy to learn and understand. I then followed the article with Java and everything was fine. I could adapt it to my homework problem at the university and got quite good result.

Finally, I really recommend this page to everyone who need to get started with ANNs, quick :)

Tuesday, July 31, 2007

Simple Tic-Tac-Toe AI in JavaScript

Click here to see the Tic-Tac-Toe game in action! (open in new window)

Last year, I was challenged by the thread at Thaiadmin to implement a two-player OX (or Tic-Tac-Toe, XO, what you may call) game. I had done this kind of program in VB6 before, so I decided to implement the one-player JavaScript version.

The hardest part of of this project is debugging the JavaScript. I had to write the value of each variable and things done in each step to the screen (as you see in the bottom of the figure above) to diagnose the problems. I was so embarrassed that I did not know any of the great web developer's tools such as FireBug.

The ideas behind the decisions making part (or the AI) are to search every possible moves and take the best one. In each move, We assumed that the opponent chose his best move and we chose our best move. This method is "Minimax" method. As described in Wikipedia:

Minimax (sometimes minmax) is a method in decision theory for minimizing the maximum possible loss. Alternatively, it can be thought of as maximizing the minimum gain (maximin). It started from two player zero-sum game theory, covering both the cases where players take alternate moves and those where they make simultaneous moves. It has also been extended to more complex games and to general decision making in the presence of uncertainty.

The Minimax method can be applied to many other board games too. But in some complex games such as Chess, there was so many game states that you cannot search into them entirely (it would take many many years on an ordinary computer). So some heuristic must be used to approximately determine value of each state and the search must be limited at a fixed level (deeper level of search makes the AI cleverer).

In my case, there was not too many game states so I can search on them entirely. You can test my game here - http://m3rlinez.googlepages.com/oxai.htm. Choose View->Source to view the JavaScript source code.

Wednesday, January 10, 2007

.NET Remoting Object in Action!

About .NET Remoting Object

I have started learning .NET nearly two years ago. One of the topics which is hard to understand and confused many newbies is .NET Remoting Object.

.NET Remoting Object is often compared to ASP.NET Web Service as an alternative for building distributed system. There are many tutorials on the internet that show how to consume web service or how to create a web service. So we can see clearly how and where web service would plug into our applications. But for .NET Remoting Object, there are less tutorial. And I really don't know how can I make use of it in my application.

The Situation
Here at my university, My friends and I (as a group of Microsoft Student Ambassadors) conduct a competition on AI programming. Competitors have to code his/her robot in C#. The robot can move in 4 directions and can place a bomb just like in the "Bomberman" game. 4 of these will be placed in the same map in each round and the last stand wins.

So what's the problem ?

The competitors have to code his/her robot as a derived class from "BaseAIBot" which is a class derived from "Thread". Then they have to compile their projects into DLLs. And have these DLLs run in our host application.

This is COMPLETE BLIND DEBUGGING !!

So the competitors must find someway debugging their programs. One approach is to have information dump into text file. This solution is OK but I really hate switching back and forth between the host application and the text file. So I decided to write a program which acts as a text terminal to receive text message from robot.

The root of problem

The problem is how can I send information across application domain or process ?

Yes, the answer is to use .NET Remoting Object.

I will have one object setup at my "Terminal" application and let the robot get this object and call "PushMessage(string)" method to add a message. After a message is pushed, the MessageReceived will be raised. And the UI will be updated.

This results as a program in the screen shot in the left.

Useful links

I studied how to implement .NET Remoting from the two web pages below :

http://www.developer.com/net/net/article.php/2201701 - This covers the basics of .NET Remoting Object. What is it ? And when to use it.

http://www.codeproject.com/csharp/RemotingChatSample.asp - This is the working sample for application using .NET Remoting Object.