Esempio n. 1
0
 function win()
 {
     // Check the rows, columns and diagonals for a winning line.
     $lines = array(array($this->board[0], $this->board[4], $this->board[8]), array($this->board[2], $this->board[4], $this->board[6]));
     for ($i = 0; $i <= 2; $i++) {
         $lines[] = array($this->board[$i], $this->board[$i + 3], $this->board[$i + 6]);
         $lines[] = array($this->board[$i * 3], $this->board[$i * 3 + 1], $this->board[$i * 3 + 2]);
     }
     foreach ($lines as $line) {
         if (TicTacToe::checkline($line)) {
             if ($line[0] == "o") {
                 return -1;
             } else {
                 if ($line[0] == "x") {
                     return 1;
                 }
             }
         }
     }
     return 0;
 }