/** * Get best line * * @param $type */ protected function getWinLine($type) { $oppositeType = Cell::getOppositeType($type); if ($this->winCounts[$type] < $this->winCounts[$oppositeType]) { return $this->winLines[$oppositeType]; } else { return $this->winLines[$type]; } }
/** * Just put first free cell on board */ public function getCell(Board $board, $type) { $free = $board->getFreeCell(); if (empty($free)) { ExceptionFactory::runtime("Not have free cells"); } $position = $this->getPosition($board, $type); switch ($type) { case Cell::TIC: $cell = Cell::createTic($position); break; default: $cell = Cell::createTac($position); } return $cell; }
/** * Add cell only on free and exist cell * * @param Cell $cell */ public function addCell(Cell $cell) { if (!isset($this->kitCells[$cell->getPosition()])) { ExceptionFactory::positionOutOfRangeException($cell->getPosition()); } if (!empty($this->kitCells[$cell->getPosition()])) { ExceptionFactory::positionAlreadyExistException($cell->getPosition()); } $this->kitCells[$cell->getPosition()] = $cell; }
/** * One step * * @param $type * @param $position * * @throws Exception\WrongCellException */ public function step($type, $position) { switch ($type) { case Cell::TIC: $cell = Cell::createTic($position); break; case Cell::TAC: $cell = Cell::createTac($position); break; default: throw ExceptionFactory::wrongCellException($type); break; } // Human step $this->board->addCell($cell); if ($this->board->isFinish()) { return; } // Strategy step $cell = $this->strategy->getCell($this->board, $this->oppositeType); $this->board->addCell($cell); }
/** * @param Cell $cell */ public function addCell(Cell $cell) { $this->count[$cell->getType()]++; }