http://www.chrispearson.org/pages/programming/php/oxo/phpoxo.asp
17h04
Thursday, 28. August 2008

PHP PLAYS OXO

A while back I was working on forecasting systems - sales forecasting - and I was experimenting with various ways of evaluating what-ifs. I also needed to get into PHP!

In an attempt to kill two birds with just one stone, I decided to write a PHP page which would play noughts and crosses. It's a fairly straightforward approach to the gameplay, taking all available moves that can be made, looking at the opponent's possible responses and scoring the outcome. As it turns out, this was almost exactly what I did in evaluating the sales forecast scenarios (but adding a couple of orders of parameter magnitude and a few more plys). So it scored as a useful exercise in that respect.

It also helped me to get to grips with some basic PHP: functions, string manipulation and regular expressions for a start. What did impress me were some of the array features of PHP. The board scoring uses an array keyed by the current game board and then sorted by the array element's numeric score.

Have a go.

The application uses a table to create the game board and small, square graphics to show the state of play: A transparent image in empty cells as a spacer image and either O or X images to mark players' moves.
I've run through how the application is coded in Building PHP Noughts and Crosses

xxx,xxx

copyright ©2000 - 2008 Chris Pearson