示例#1
0
 function isExit($hexagon)
 {
     $isExit = false;
     if (is_object($hexagon)) {
         $X = $hexagon->getX();
         $Y = $hexagon->getY();
     } else {
         list($X, $Y) = Hexagon::getHexPartXY($hexagon);
     }
     $hexpart = new Hexpart($X, $Y);
     $terrainCode = $this->getTerrainCode($hexpart);
     if ($this->terrainIs($hexpart, "offmap") == true) {
         $isExit = true;
     }
     return $isExit;
 }
示例#2
0
 function bfsCommunication($goal, $bias, $attackingForceId = false, $maxHex = false)
 {
     $goalArray = array();
     if (is_array($goal)) {
         foreach ($goal as $key => $val) {
             $goalArray[$val] = true;
         }
     } else {
         $goalArray[$goal] = true;
     }
     if ($attackingForceId !== false) {
         $defendingForceId = $this->force->Enemy($attackingForceId);
     } else {
         $attackingForceId = $this->force->attackingForceId;
         $defendingForceId = $this->force->defendingForceId;
     }
     $cnt = 0;
     while (count($this->moveQueue) > 0) {
         $cnt++;
         $hexPath = array_shift($this->moveQueue);
         $hexNum = $hexPath->name;
         if ($maxHex !== false) {
             $movePoints = $hexPath->pointsLeft;
         }
         if (!$hexNum) {
             continue;
         }
         if ($goalArray[$hexNum]) {
             return true;
         }
         if (!isset($this->moves->{$hexNum})) {
             /* first time here */
             $this->moves->{$hexNum} = $hexPath;
         } else {
             /* invalid hex */
             if ($this->moves->{$hexNum}->isValid === false) {
                 continue;
             }
             /* been here, done that */
             continue;
         }
         /* @var MapHex $mapHex */
         $mapHex = $this->mapData->getHex($hexNum);
         if ($mapHex->isOccupied($attackingForceId)) {
             $this->moves->{$hexNum}->isOccupied = true;
         }
         if ($mapHex->isOccupied($defendingForceId)) {
             $this->moves->{$hexNum}->isValid = false;
             continue;
         }
         if ($maxHex !== false) {
             $this->moves->{$hexNum}->pointsLeft = $movePoints;
         }
         $this->moves->{$hexNum}->pathToHere = $hexPath->pathToHere;
         if ($this->moves->{$hexNum}->isZoc == NULL) {
             $this->moves->{$hexNum}->isZoc = $this->force->mapHexIsZOC($mapHex, $defendingForceId);
         }
         if ($this->moves->{$hexNum}->isZoc) {
             if (!$this->moves->{$hexNum}->isOccupied) {
                 continue;
             }
         }
         $path = $hexPath->pathToHere;
         $path[] = $hexNum;
         for ($i = 1; $i <= 6; $i++) {
             $newHexNum = $mapHex->neighbors[$i - 1];
             $gnuHex = Hexagon::getHexPartXY($newHexNum);
             if (!$gnuHex) {
                 continue;
             }
             if ($this->terrain->terrainIsHexSide($hexNum, $newHexNum, "blocked")) {
                 continue;
             }
             if ($this->terrain->terrainIsXY($gnuHex[0], $gnuHex[1], "offmap")) {
                 continue;
             }
             if ($this->terrain->terrainIsXY($gnuHex[0], $gnuHex[1], "blocked")) {
                 continue;
             }
             $newMapHex = $this->mapData->getHex($newHexNum);
             if ($newMapHex->isOccupied($defendingForceId)) {
                 continue;
             }
             if ($maxHex !== false && $movePoints - 1 < 0) {
                 continue;
             }
             $head = false;
             if ($bias[$i]) {
                 $head = true;
             }
             if (isset($this->moves->{$newHexNum})) {
                 if ($maxHex !== false) {
                     if ($this->moves->{$newHexNum}->pointsLeft > $movePoints - 1) {
                         continue;
                     }
                 } else {
                     continue;
                 }
             }
             $newPath = new HexPath();
             $newPath->name = $newHexNum;
             $newPath->pathToHere = $path;
             if ($maxHex !== false) {
                 $newPath->pointsLeft = $movePoints - 1;
             }
             if ($head) {
                 array_unshift($this->moveQueue, $newPath);
             } else {
                 $this->moveQueue[] = $newPath;
             }
         }
     }
     return false;
 }
示例#3
0
 function bfsRoadTrace($goal, $bias, $attackingForceId = false, $maxHex = false)
 {
     $goalArray = array();
     if (is_array($goal)) {
         foreach ($goal as $key => $val) {
             $goalArray[$val] = true;
         }
     } else {
         $goalArray[$goal] = true;
     }
     if ($attackingForceId !== false) {
         $defendingForceId = $this->force->Enemy($attackingForceId);
     } else {
         $attackingForceId = $this->force->attackingForceId;
         $defendingForceId = $this->force->defendingForceId;
     }
     $cnt = 0;
     while (count($this->moveQueue) > 0) {
         $cnt++;
         $hexPath = array_shift($this->moveQueue);
         $hexNum = $hexPath->name;
         if ($maxHex !== false) {
             $movePoints = $hexPath->pointsLeft;
         }
         if (!$hexNum) {
             continue;
         }
         if (!isset($this->moves->{$hexNum})) {
             /* first time here */
             $this->moves->{$hexNum} = $hexPath;
         } else {
             /* invalid hex */
             if ($this->moves->{$hexNum}->isValid === false) {
                 continue;
             }
             /* been here, done that */
             continue;
         }
         /* @var MapHex $mapHex */
         $mapHex = $this->mapData->getHex($hexNum);
         if ($mapHex->isOccupied($attackingForceId)) {
             $this->moves->{$hexNum}->isOccupied = true;
         }
         if ($mapHex->isOccupied($defendingForceId)) {
             $this->moves->{$hexNum}->isValid = false;
             continue;
         }
         if ($maxHex !== false) {
             $this->moves->{$hexNum}->pointsLeft = $movePoints;
         }
         $this->moves->{$hexNum}->pathToHere = $hexPath->pathToHere;
         if ($this->moves->{$hexNum}->isZoc == NULL) {
             $this->moves->{$hexNum}->isZoc = $this->force->mapHexIsZOC($mapHex, $defendingForceId);
         }
         if ($this->moves->{$hexNum}->isZoc) {
             if (!$this->moves->{$hexNum}->isOccupied) {
                 unset($this->moves->{$hexNum});
                 //                    $this->moves->$hexNum->isValid = false;
                 continue;
             }
         }
         $path = $hexPath->pathToHere;
         $path[] = $hexNum;
         for ($i = 1; $i <= 6; $i++) {
             $newHexNum = $mapHex->neighbors[$i - 1];
             $gnuHex = Hexagon::getHexPartXY($newHexNum);
             if (!$gnuHex) {
                 continue;
             }
             if (!($this->terrain->terrainIsHexSide($hexNum, $newHexNum, "road") || $this->terrain->terrainIsHexSide($hexNum, $newHexNum, "trail") || $this->terrain->terrainIsHexSide($hexNum, $newHexNum, "secondaryroad"))) {
                 continue;
             }
             if ($this->terrain->terrainIsXY($gnuHex[0], $gnuHex[1], "offmap")) {
                 continue;
             }
             $newMapHex = $this->mapData->getHex($newHexNum);
             if ($newMapHex->isOccupied($defendingForceId)) {
                 continue;
             }
             /*
              * TODO order is important in if statement check if doing zoc zoc move first then if just one hex move.
              * Then check if oneHex and firstHex
              */
             if ($maxHex !== false && $movePoints - 1 < 0) {
                 continue;
             }
             $head = false;
             if (!empty($bias[$i])) {
                 $head = true;
             }
             if (isset($this->moves->{$newHexNum})) {
                 if ($maxHex !== false) {
                     if ($this->moves->{$newHexNum}->pointsLeft > $movePoints - 1) {
                         continue;
                     }
                 } else {
                     continue;
                 }
             }
             $newPath = new HexPath();
             $newPath->name = $newHexNum;
             $newPath->pathToHere = $path;
             if ($maxHex !== false) {
                 $newPath->pointsLeft = $movePoints - 1;
             }
             if ($head) {
                 array_unshift($this->moveQueue, $newPath);
             } else {
                 $this->moveQueue[] = $newPath;
             }
         }
     }
     return false;
 }