Example #1
0
 /**
  * Get game strategy by name
  *
  * @param $name
  *
  * @return mixed
  * @throws \Ticki\Core\Exception\UnknownStrategyException
  */
 public function getByName($name)
 {
     if (!isset($this->strategies[$name])) {
         throw ExceptionFactory::undefinedStrategyException($name);
     }
     return $this->strategies[$name];
 }
Example #2
0
 /**
  * @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];
 }
Example #3
0
File: Cell.php Project: Gtvar/Ticki
 /**
  * Construct
  *
  * @param $position
  * @param $type
  */
 public function __construct($position, $type)
 {
     $this->position = $position;
     if (!in_array($type, array(self::TIC, self::TAC))) {
         throw ExceptionFactory::wrongCellException($type);
     }
     $this->type = $type;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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");
     }
 }
Example #6
0
 /**
  * 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);
 }