Thursday, January 6, 2011

Othello in Javascript

A few times I have tried this strategy to learn something new. I try to convert some code from a book into a different language. Just copying and running examples out of a book isn't very exciting, and it doesn't force me to understand what is going on in the code.

But porting to another language forces me to understand (better) what the original code is doing, why it is nice in the language used, and how to do the same thing in a different language.

The last few days, I ported code from Peter Norvig's Lisp AI Book into javascript. Learning more about lisp has been a goal of mine for years. Learning javascript is a more recent goal. I have always been interested in AI programming.

Here is the work in progress. Here are some of the known deficiencies:

  • very little testing or cleanup has been done
  • the GUI is a hack
  • there isn't a timer to let the computer know it took too long. On a fast computer, 6 ply look ahead may not be too bad
  • yeah, my use of the google app engine is probably lame. But it serves my static file for me.

The javascript code has a variety of influences. Norvig's code, of course, provides an often literal example. Crockford's book and website were a big help, although I probably didn't succeed in getting the good parts right. My F# experience led to the m_array library object at the top of the javascript file, even though everything I do in that library is probably available in javascript somewhere else.

I probably won't try to add the more advanced AI code from the book, and instead move on to playing with it in lisp.

If you see any dangerous problems here, I would like to know about it.

No comments: