/** * @param $type * * @return mixed * @throws \Ticki\Core\Exception\RuntimeException */ public function getByType($type) { if (!in_array($type, array(Cell::TIC, Cell::TAC))) { throw ExceptionFactory::runtime(sprintf("Invalid type: %s", $type)); } return $this->count[$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; }
/** * Construct * * @param $strategy * @param $sideCount * @param $myType * @param int $winCount */ public function __construct($strategy, $sideCount, $myType, $winCount = 0) { if (!in_array($myType, array(Cell::TIC, Cell::TAC))) { throw ExceptionFactory::wrongCellException($myType); } if (!in_array($sideCount, Board::$availableSideCount)) { throw ExceptionFactory::runtime("Wrong side number"); } if ($winCount > $sideCount) { throw ExceptionFactory::runtime("winCount should be less oq equal than sideCount"); } $this->strategy = $this->getStrategyManager()->getByName($strategy); $this->board = new Board($sideCount, $winCount); $this->myType = $myType; $this->oppositeType = Cell::getOppositeType($myType); }
/** * Check position for available * * @param $position * * @throws \Ticki\Core\Exception\RuntimeException */ public function checkPosition($position) { if (!in_array($position, $this->getFreeCell())) { throw ExceptionFactory::runtime("Wrong position"); } }