Пример #1
0
 /**
  * @return Decision[]
  */
 public function getDecisions() : array
 {
     if ($this->win($this->turn) || $this->lose($this->turn)) {
         return [];
     }
     $decisions = [];
     foreach ($this->board as $row => $rowValues) {
         foreach ($rowValues as $col => $fieldValue) {
             if ($fieldValue->equals(Player::NONE())) {
                 $decisions[] = new Decision($row, $col);
             }
         }
     }
     return $decisions;
 }
Пример #2
0
 public function testExceptionWhenNoMovesLeft()
 {
     $O = Player::O();
     $state = new GameState();
     // OXX
     // XOO
     // XOX
     $state->fillField(2, 0);
     // X
     $state->fillField(0, 0);
     // O
     $state->fillField(0, 2);
     // X
     $state->fillField(1, 1);
     // O
     $state->fillField(0, 1);
     // X
     $state->fillField(2, 1);
     // O
     $state->fillField(2, 2);
     // X
     $state->fillField(1, 2);
     // O
     $state->fillField(1, 0);
     // X
     $engine = new Engine($O);
     $this->expectException(RuntimeException::class);
     $engine->decide($state);
 }