#include #include "Grid.h" #include "Umpire.h" // Initialised its own version // of the grid. // We could use the grid directly but // it would be more complicated as we would // have to access the data member grid of the // grid class (overloading [][] operation for instance Umpire::Umpire() { int i,j; for (i= 0; i < 3; i++) { for (j = 0; j < 3; j++) { myGrid[i][j] = ' '; } } } // Validates a grid move. // Checks for state of the move (valid, invalid) // And Game (won, draw) char Umpire::validate(char t, int r, int c) { int i, j; if(r > 2 || c > 2 || myGrid[r][c]!=' ') { return 'i'; } myGrid[r][c] = t; if(myGrid[r][0]==myGrid[r][1] && myGrid[r][1]==myGrid[r][2]) return 'w'; if(myGrid[0][c]==myGrid[1][c] && myGrid[1][c]==myGrid[2][c]) return 'w'; for(i=0;i<3;i++) for(j=0;j<3;j++) if (myGrid[i][j]==' ') return 'v'; return 'd'; }