PHP CODING
Building PHP Noughts and Crosses
|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
When a move is received by the PHP page each step is carried out by a function. Checkwin() determines whether there is a winning line - three symbols in a row; down, across or diagonally. This sets a flag which then suppresses any attempts to respond to that move. The code next loops through every possible move the server can make for X - every empty cell, that is. Rather than taking the first possible move available the program now tries to determine whether this is the best move to make. The programs estimates which of the possible moves is best by calling BestMove(). In BestMove() every possible move for X is identified then every possible response by O is evaluated. The position after O has responded to each move is then evaluated by ScoreBoard(). ScoreBoard() takes each row of the board - verticals, horizontals and diagonals - and passes them to another function, ScoreRow().
As I mentioned in the introduction, the impetus for writing the noughts and crosses application was to test out some scoring methods for other what-if evaluation - I discovered a number of approaches in my research, from minimax (the same kind of scoring used here) through to learning heuristics where the program assimilates outcomes with their associated games, then determines the best game to play next time: All interesting, worthy of further investigation and waiting for a few hours on a rainy day. As far as it goes I think it exercises some useful PHP, too. |
|||||||||||||||||||||
xxx,xxx