public function itSatisfiedBy(Map $map)
 {
     // Check for field status
     if ($map->getStatus() == 1) {
         return false;
     }
     // Check for number
     $countShips = 0;
     foreach (Ship::$ships as $shipType) {
         $countShips += $shipType['number'];
     }
     $alreadyLocated = $this->shipRepository->findOneBy(['player' => 1]);
     if ($alreadyLocated == $countShips) {
         return false;
     }
     // Check for location
     $lastLocated = $this->mapRepository->findOneBy(['player' => 1], ['id' => 'DESC']);
     if ($lastLocated->getXAxis() == $map->getXAxis()) {
         $key = array_search($lastLocated->getYAxis(), Map::$allowedYCoordinates);
     } elseif ($lastLocated->getYAxis() == $map->getYAxis()) {
         $key = array_search($lastLocated->getXAxis(), Map::$allowedXCoordinates);
     } else {
         return false;
     }
     return $this->checkPosition($map, $key);
 }
 public function locate(Map $map, Ship $ship)
 {
     if (!$this->shipCanBeLocated->itSatisfiedBy($map)) {
         throw new RuntimeException();
     }
     $this->mapRepository->save($map);
     $this->shipRepository->save($ship);
 }
 /**
  * Get random target
  *
  * @return mixed
  */
 public function get()
 {
     $allTargets = $this->mapRepository->getAllTargets();
     return $allTargets[rand(0, count($allTargets) - 1)];
 }