I started reading a book about artificial intelligence. It’s an older book, but only $4 and it came highly recommended as a starting point, since a lot of the basic concepts are still the same. Based on the things I was reading and this xkcd, I figured it might be within my capabilities to write a program that plays Tic Tac Toe. And I have. Sort of. You can play it here. Kinda.

See, the concepts of artificial intelligence and the basics of programming aren’t so hard. What’s hard is making it work in the “real world.” 

I knew JavaScript was good for interactive stuff, and I knew HTML/CSS could handle the graphics bit, and I wanted to make my game public on the web anyway, so this seemed the logical route to go, even though I didn’t really know much JS beyond the very, very basics taught over at codecademy. I knew this was a bit beyond my abilities, but I wanted it to be a learning experience, and I wanted to do everything from scratch myself. Of course there’s been thousands of Tic Tac Toe playing programs written over the years, but I wanted to get my hands dirty and try it myself.

Up until this project, I had never done any programming with the end user in mind. All the programs I’ve written have been to do science (gather data, run statistics, make spreadsheets, parse data, etc). So I’ve learned a lot in the last few weeks about event listeners (lines of code that allow the computer to know when the user has clicked something), and about the Document Object Model, which is how JavaScript accesses and manipulates elements in the HTML page.

Basically, the hardest part for me so far has been getting the interactive bit to work. The user picks which square s/he wants, then the computer takes its turn, and they can’t pick the same square, and there’s only nine of them.

Next, I have to teach the program when the game is over. Right now, you can keep playing even if one of the players has made a row, column, or diagonal. After that, I have to teach the computer strategy (right now, the computer just picks a square at random from the remaining available squares).

But for now, I have a working thing that resembles Tic Tac Toe, and is interactive, and is live on the web. And I’m pretty darn proud of that!

You must be logged in to leave a reply.