Prev | Current Page 822 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Note that the place() method is executed each time
any of the two players clicks on the grid at any time, and also when it is not their turn. The action is
validated and simply ignored by the server if inappropriate.
interface IPlayerServer
{
function attend() : Void;
function place(r : Int, c : Int) : Void;
}
The GameBoard class maintains the playing grid that is defined by three triplets of 0 values. The class
also maintains the results of the game to determine if one player won or the game was concluded in a tie.
The system adopted to maintain the result is weirdly brainiac but it is efficient and short in lines of code.
Each position of the results array can contain a number between  3 and 3. If the number is equal to 3 the
first player wins; if the number is equal to  3 it is the second player who wins. Every value in the middle
is not relevant. The positions from 0 to 5 are for the sum of each row and each column. The positions
8 and 13 are for the two diagonals. Every other position in the array can be potentially used by the
algorithm but can never reach a winning value.


Pages:
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834