[11898] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[11992] | 23 | * Marc Dreher |
---|
[11898] | 24 | * Co-authors: |
---|
[11992] | 25 | * .. |
---|
[11898] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "PacmanGhost.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
| 32 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 33 | |
---|
[12338] | 34 | #include <vector> |
---|
| 35 | |
---|
[11898] | 36 | namespace orxonox |
---|
| 37 | { |
---|
[12304] | 38 | |
---|
[12316] | 39 | |
---|
[12338] | 40 | struct PacmanGhost::graphVertex { |
---|
[12316] | 41 | |
---|
[12338] | 42 | public: |
---|
[12316] | 43 | |
---|
[12338] | 44 | Vector3 position; |
---|
| 45 | graphVertex *adjacentVertices[4]; //neighbooring vertices |
---|
[12316] | 46 | |
---|
[12338] | 47 | int shortestDistanceToStart; //actual shortest distance to start point |
---|
| 48 | graphVertex* actuelPredecessor; //the predecessor giving the for now shortest |
---|
| 49 | //path to start |
---|
| 50 | graphVertex* currentNearestNonVisitedNeighboor; |
---|
| 51 | bool alreadyVisited; |
---|
| 52 | graphVertex(){ //default constructor |
---|
| 53 | position=0; |
---|
| 54 | shortestDistanceToStart= std::numeric_limits<int>::max(); |
---|
| 55 | actuelPredecessor=nullptr; |
---|
| 56 | alreadyVisited=false; |
---|
| 57 | for(int kl =0; kl <4;kl++){ |
---|
| 58 | adjacentVertices[kl]=nullptr; //first put all position in array listing neighboors to 0 |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | graphVertex(Vector3 wantedPosition){ //normal constructor |
---|
| 62 | position=wantedPosition; |
---|
| 63 | shortestDistanceToStart= std::numeric_limits<int>::max(); //default distance is infinity |
---|
| 64 | actuelPredecessor=nullptr; |
---|
| 65 | alreadyVisited=false; |
---|
| 66 | for(int kl =0; kl <4;kl++){ |
---|
| 67 | adjacentVertices[kl]=nullptr; //first put all position in array listing neighboors to 0 |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | graphVertex& operator = (const graphVertex &rightSide){ |
---|
| 71 | this->position=rightSide.position; |
---|
| 72 | this->shortestDistanceToStart=rightSide.shortestDistanceToStart; |
---|
| 73 | this->actuelPredecessor=rightSide.actuelPredecessor; |
---|
| 74 | this->currentNearestNonVisitedNeighboor=rightSide.currentNearestNonVisitedNeighboor; |
---|
| 75 | this->alreadyVisited=rightSide.alreadyVisited; |
---|
[12316] | 76 | |
---|
[12338] | 77 | return *this; |
---|
| 78 | } |
---|
[12316] | 79 | |
---|
[12338] | 80 | }; |
---|
[12316] | 81 | |
---|
| 82 | |
---|
[12338] | 83 | static PacmanGhost::graphVertex listOfVertices[67]; |
---|
[12304] | 84 | |
---|
[12338] | 85 | //Check if there is a collision |
---|
| 86 | bool findpos(Vector3 one, Vector3 other){ |
---|
| 87 | if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true; |
---|
| 88 | return false; |
---|
| 89 | } |
---|
[12304] | 90 | |
---|
[12338] | 91 | //All positions in the map, see documentation |
---|
| 92 | Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4 |
---|
| 93 | Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 |
---|
| 94 | Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14 |
---|
| 95 | Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19 |
---|
| 96 | Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24 |
---|
| 97 | Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29 |
---|
| 98 | Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34 |
---|
| 99 | Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39 |
---|
| 100 | Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44 |
---|
| 101 | Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49 |
---|
| 102 | Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54 |
---|
| 103 | Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 |
---|
| 104 | Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 |
---|
| 105 | Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66 |
---|
[11898] | 106 | |
---|
[12338] | 107 | RegisterClass(PacmanGhost); |
---|
[11898] | 108 | |
---|
[12338] | 109 | /** |
---|
| 110 | @brief |
---|
| 111 | Constructor. Registers the object and initializes some default values. |
---|
| 112 | @param creator |
---|
| 113 | The creator of this object. |
---|
| 114 | */ |
---|
| 115 | PacmanGhost::PacmanGhost(Context* context) : ControllableEntity(context) |
---|
| 116 | { |
---|
| 117 | RegisterObject(PacmanGhost); |
---|
[12316] | 118 | |
---|
[12338] | 119 | this->velocity = Vector3(0, 0, 0); |
---|
[12316] | 120 | |
---|
[12338] | 121 | this->setCollisionType(CollisionType::Dynamic); |
---|
[12304] | 122 | |
---|
[12338] | 123 | this->actuelposition = this->getPosition(); |
---|
[11945] | 124 | |
---|
[12338] | 125 | if(findpos(actuelposition, Vector3(0,-20,0))) |
---|
| 126 | dontmove = true; |
---|
[11898] | 127 | |
---|
[12338] | 128 | this->target_x = actuelposition.x; |
---|
| 129 | this->target_z = actuelposition.z; |
---|
[12316] | 130 | |
---|
[12338] | 131 | } |
---|
[11898] | 132 | |
---|
[12338] | 133 | /** |
---|
| 134 | @brief |
---|
| 135 | Destructor. Destroys ghost, if present. |
---|
| 136 | */ |
---|
| 137 | PacmanGhost::~PacmanGhost() |
---|
| 138 | { |
---|
| 139 | // Deletes the controller if the object was initialized and the pointer to the controller is not nullptr. |
---|
| 140 | } |
---|
[11898] | 141 | |
---|
[12338] | 142 | /** |
---|
| 143 | @brief |
---|
| 144 | Method for creating a ghost through XML. |
---|
| 145 | */ |
---|
| 146 | void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 147 | { |
---|
| 148 | SUPER(PacmanGhost, XMLPort, xmlelement, mode); |
---|
| 149 | } |
---|
[11898] | 150 | |
---|
[12338] | 151 | //Change this with other ghost |
---|
| 152 | void PacmanGhost::changewith(PacmanGhost* otherghost){ |
---|
[11949] | 153 | |
---|
[12338] | 154 | while(lockmove){}; |
---|
| 155 | lockmove = true; //Prevent change of target while ghost is changed |
---|
[11949] | 156 | |
---|
[12338] | 157 | otherghost->setPosition(this->getPosition()); |
---|
| 158 | this->setPosition(0,-20,0); |
---|
| 159 | otherghost->target_x = this->target_x; |
---|
| 160 | otherghost->target_z = this->target_z; |
---|
| 161 | otherghost->ismoving = this->ismoving; |
---|
[11903] | 162 | |
---|
[12338] | 163 | this->dontmove = true; |
---|
| 164 | otherghost->dontmove = false; |
---|
[11949] | 165 | |
---|
[12338] | 166 | lockmove = false; |
---|
| 167 | } |
---|
[11903] | 168 | |
---|
[12338] | 169 | //Move ghost with rotation |
---|
| 170 | void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){ |
---|
| 171 | if(!dontmove){ |
---|
| 172 | this->setPosition(Vector3(actuelposition.x+speed*velocity.x*dt,10,actuelposition.z+speed*velocity.z*dt)); |
---|
[11903] | 173 | |
---|
[12338] | 174 | //Rotate ghost in the direction of movement |
---|
| 175 | if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)){ |
---|
| 176 | if(velocity.x<0){ |
---|
| 177 | this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); |
---|
| 178 | } |
---|
| 179 | else{ |
---|
| 180 | this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)){ |
---|
| 184 | if(velocity.z<0){ |
---|
| 185 | this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); |
---|
| 186 | } |
---|
| 187 | else{ |
---|
| 188 | this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); |
---|
| 189 | } |
---|
| 190 | } |
---|
[11933] | 191 | |
---|
[12338] | 192 | } |
---|
| 193 | } |
---|
[11958] | 194 | |
---|
[12338] | 195 | //Change ability to move |
---|
| 196 | void PacmanGhost::changemovability(){ |
---|
| 197 | if(dontmove){ |
---|
| 198 | dontmove = false;} |
---|
| 199 | else{ |
---|
| 200 | dontmove = true; |
---|
| 201 | } |
---|
| 202 | } |
---|
[12304] | 203 | |
---|
[12338] | 204 | //ResetGhost |
---|
| 205 | void PacmanGhost::resetGhost(){ |
---|
[12304] | 206 | |
---|
[12338] | 207 | this->setPosition(this->resetposition); |
---|
| 208 | this->ismoving = false; |
---|
| 209 | this->actuelposition = this->getPosition(); |
---|
[12304] | 210 | |
---|
[12338] | 211 | this->target_x = actuelposition.x; |
---|
| 212 | this->target_z = actuelposition.z; |
---|
[12316] | 213 | |
---|
[12338] | 214 | } |
---|
[12316] | 215 | |
---|
[12338] | 216 | //Increase speed of ghosts |
---|
| 217 | void PacmanGhost::levelupvelo(){ |
---|
| 218 | speed ++; |
---|
| 219 | } |
---|
[12319] | 220 | |
---|
[12338] | 221 | Vector3 PacmanGhost::getPlayerPos() |
---|
| 222 | { |
---|
| 223 | for (PacmanGelb* player : ObjectList<PacmanGelb>()) |
---|
| 224 | { |
---|
| 225 | return player->getWorldPosition(); |
---|
| 226 | } |
---|
[12357] | 227 | |
---|
[12338] | 228 | return Vector3(0,0,0); //default, should not be used |
---|
[12319] | 229 | |
---|
[12338] | 230 | } |
---|
[12316] | 231 | |
---|
| 232 | |
---|
[12338] | 233 | bool PacmanGhost::jeanfindpos(Vector3 one, Vector3 other){ |
---|
[12357] | 234 | //This function is used to detect the last Vector3 position that the player crossed. |
---|
| 235 | |
---|
[12338] | 236 | if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true; |
---|
| 237 | return false; |
---|
| 238 | } |
---|
[12319] | 239 | |
---|
[12338] | 240 | void PacmanGhost::setNewTargetGhost(Vector3 goalToGo){ |
---|
[12357] | 241 | //Ghosts will go to goalToGo |
---|
[12319] | 242 | |
---|
[12338] | 243 | this->target_x = goalToGo.x; |
---|
| 244 | this->target_z = goalToGo.z; |
---|
| 245 | this->ismoving = true; |
---|
| 246 | } |
---|
[12319] | 247 | |
---|
| 248 | |
---|
[12338] | 249 | /// |
---|
| 250 | //// getShortestPath ///////// |
---|
| 251 | /// |
---|
[12319] | 252 | |
---|
| 253 | |
---|
| 254 | |
---|
[12338] | 255 | Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1){ |
---|
| 256 | //this function should then somehow produce the algorithm and call all other functions |
---|
| 257 | //and finally return the best neighboor of the actual position of the pacman |
---|
[12319] | 258 | |
---|
[12338] | 259 | //(optional parameter) pointToAvoidP1 is a point that cannot be considered |
---|
[12319] | 260 | |
---|
| 261 | |
---|
[12338] | 262 | graphVertex listOfVerticesM[67]; //our list of all possible graphs |
---|
| 263 | graphVertex* actualVertex; //we will walk through the array with a pointer |
---|
[12319] | 264 | |
---|
| 265 | |
---|
[12338] | 266 | if(start==goal){ // basic case |
---|
| 267 | return start; |
---|
| 268 | } |
---|
[12319] | 269 | |
---|
[12338] | 270 | for(int an=0; an < 67; an++){ |
---|
| 271 | listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file |
---|
[12357] | 272 | |
---|
[12319] | 273 | |
---|
[12338] | 274 | if(start==possibleposition[an]){ |
---|
| 275 | actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array |
---|
[12357] | 276 | |
---|
[12338] | 277 | } |
---|
| 278 | } |
---|
[12319] | 279 | |
---|
[12338] | 280 | actualVertex->alreadyVisited=true; //our start point is now visited |
---|
| 281 | actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0 |
---|
| 282 | findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); |
---|
| 283 | // second parameter is an array ! //third is our global array |
---|
[12319] | 284 | |
---|
[12338] | 285 | while(actualVertex->position!=goal){ |
---|
| 286 | for(int h=0;h < 4; h++){ |
---|
| 287 | if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex |
---|
[12319] | 288 | |
---|
[12357] | 289 | |
---|
[12338] | 290 | updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]); |
---|
| 291 | } //we "update" the neighboors of our new visited vertex |
---|
[12319] | 292 | |
---|
[12338] | 293 | } |
---|
[12319] | 294 | |
---|
[12338] | 295 | actualVertex=findNextVertexToConsider(listOfVerticesM, pointToAvoidP1); |
---|
| 296 | actualVertex->alreadyVisited=true; |
---|
[12357] | 297 | |
---|
[12338] | 298 | if(actualVertex->position!=goal){ |
---|
| 299 | findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); |
---|
| 300 | //we find the neighboors of our new visited vertex |
---|
| 301 | } |
---|
| 302 | } |
---|
[12319] | 303 | |
---|
[12338] | 304 | //we should have reached our goal at this point |
---|
[12319] | 305 | |
---|
[12338] | 306 | while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor |
---|
| 307 | actualVertex=actualVertex->actuelPredecessor; |
---|
| 308 | } |
---|
| 309 | // the predecessor is our starting point, in other words we are now on an |
---|
| 310 | //adjacent vertex of the start |
---|
[12319] | 311 | |
---|
[12338] | 312 | return actualVertex->position; //we return the position of this - adjacent to start - vertex |
---|
| 313 | } |
---|
[12319] | 314 | |
---|
[12338] | 315 | //end of getShortestPath |
---|
[12319] | 316 | |
---|
| 317 | |
---|
[12338] | 318 | int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){ |
---|
[12357] | 319 | |
---|
[12338] | 320 | Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z)); |
---|
[12319] | 321 | |
---|
[12338] | 322 | return differenceVector.x+differenceVector.z; |
---|
| 323 | } |
---|
[12319] | 324 | |
---|
[12338] | 325 | void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){ |
---|
| 326 | //apply this method to all non visited neighboors of a vertex. |
---|
| 327 | // This method should always be run on a vertex after we marked it as visited. |
---|
| 328 | if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors. |
---|
| 329 | if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&& |
---|
| 330 | (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart + |
---|
| 331 | graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case ! |
---|
[12319] | 332 | |
---|
[12338] | 333 | neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart + |
---|
| 334 | graphDistance(vertex.position, neighboor.position); |
---|
| 335 | neighboor.actuelPredecessor = &vertex; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
[12319] | 339 | |
---|
[12338] | 340 | void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex, Vector3 pointToAvoidP3){ |
---|
| 341 | //find nearest non visited neighboor of a given already visited vertex |
---|
| 342 | //(optional parameter) pointToAvoidP3 is a point that cannot be considered |
---|
| 343 | int shortestDistance = -1; |
---|
| 344 | graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any. |
---|
| 345 | //Also, if all neighboors are already visited, we return NULL, i.e. there is no |
---|
| 346 | //nearest non visited neighboor. |
---|
| 347 | for(int i=0; i < 4; i++){ |
---|
| 348 | if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)&&(vertex.adjacentVertices[i]->position!=pointToAvoidP3)){ |
---|
| 349 | if(shortestDistance==-1){ //(concerns line above) we want a non visited neighboor //(optional) if the position of the neighboor is the one we want |
---|
| 350 | //to avoid, then we ignore it |
---|
[12319] | 351 | |
---|
[12338] | 352 | shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position); |
---|
| 353 | nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses ! |
---|
[12357] | 354 | |
---|
[12338] | 355 | } |
---|
| 356 | else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){ |
---|
| 357 | shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position); |
---|
| 358 | nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses ! |
---|
[12357] | 359 | |
---|
[12338] | 360 | } |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses ! |
---|
[12357] | 364 | |
---|
[12338] | 365 | } |
---|
[12319] | 366 | |
---|
| 367 | |
---|
[12338] | 368 | PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[], Vector3 pointToAvoidP2){ //find next, nearest from start, non visited vertex in our listOfVertices array |
---|
| 369 | //(optional parameter) pointToAvoidP2 is a point that cannot be considered |
---|
[12317] | 370 | |
---|
[12338] | 371 | int shortestDistance = -1; |
---|
| 372 | graphVertex* nextVertexToConsider; |
---|
[12317] | 373 | |
---|
[12338] | 374 | for(int i=0; i < 67; i++){ //we loop over all possible positions |
---|
[12317] | 375 | |
---|
[12338] | 376 | if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited |
---|
[12317] | 377 | |
---|
[12338] | 378 | findNearestNonVisitedNeighboor(listOfVerticesP[i], pointToAvoidP2); //we update nearest neighboor |
---|
| 379 | //of all visited vertices given that one of the nearest neighboor of a visited |
---|
| 380 | // vertex is now also visited because it was chosen as next optimal vertex |
---|
[12318] | 381 | |
---|
[12338] | 382 | if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate! |
---|
| 383 | if(shortestDistance==-1){ //our first possible candidate |
---|
[12318] | 384 | |
---|
[12338] | 385 | shortestDistance=graphDistance(listOfVerticesP[i].position, |
---|
| 386 | listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + |
---|
| 387 | listOfVerticesP[i].shortestDistanceToStart; |
---|
[12318] | 388 | |
---|
[12338] | 389 | nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor; |
---|
| 390 | //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor |
---|
[12318] | 391 | |
---|
[12338] | 392 | } |
---|
| 393 | else if(shortestDistance > graphDistance(listOfVerticesP[i].position, |
---|
| 394 | listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + |
---|
| 395 | listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available |
---|
[12318] | 396 | |
---|
[12338] | 397 | shortestDistance=graphDistance(listOfVerticesP[i].position, |
---|
| 398 | listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + |
---|
| 399 | listOfVerticesP[i].shortestDistanceToStart; |
---|
[12317] | 400 | |
---|
[12338] | 401 | nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor; |
---|
| 402 | //we dont need the & because we are not giving the adress of the array element |
---|
| 403 | //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor |
---|
| 404 | } |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | //we want after all to return the nearest non visited neighboor |
---|
| 408 | } |
---|
[12317] | 409 | |
---|
[12338] | 410 | return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array |
---|
| 411 | } |
---|
[12317] | 412 | |
---|
[12338] | 413 | ////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[12318] | 414 | |
---|
[12338] | 415 | void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){ |
---|
[12357] | 416 | //Should put in adjacentVertices the neighboor points of actuelposition. listOfVertices is the |
---|
| 417 | //array containing all possible positions in the map. |
---|
[12317] | 418 | |
---|
[12338] | 419 | if(findpos(actuelposition,possibleposition[0])){ |
---|
[12357] | 420 | |
---|
| 421 | adjacentVertices[0]=&listOfVerticesP2[1]; |
---|
| 422 | adjacentVertices[1]=&listOfVerticesP2[17]; |
---|
| 423 | adjacentVertices[2]=&listOfVerticesP2[19]; |
---|
[12338] | 424 | } |
---|
| 425 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
[12357] | 426 | adjacentVertices[0]=&listOfVerticesP2[0]; |
---|
| 427 | adjacentVertices[1]=&listOfVerticesP2[2]; |
---|
[12338] | 428 | } |
---|
| 429 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
[12357] | 430 | adjacentVertices[0]=&listOfVerticesP2[1]; |
---|
| 431 | adjacentVertices[1]=&listOfVerticesP2[3]; |
---|
[12338] | 432 | } |
---|
| 433 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
[12357] | 434 | adjacentVertices[0]=&listOfVerticesP2[2]; |
---|
| 435 | adjacentVertices[1]=&listOfVerticesP2[4]; |
---|
| 436 | adjacentVertices[2]=&listOfVerticesP2[5]; |
---|
[12338] | 437 | } |
---|
| 438 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
[12357] | 439 | adjacentVertices[0]=&listOfVerticesP2[3]; |
---|
| 440 | adjacentVertices[1]=&listOfVerticesP2[6]; |
---|
[12338] | 441 | } |
---|
| 442 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
[12357] | 443 | adjacentVertices[0]=&listOfVerticesP2[3]; |
---|
| 444 | adjacentVertices[1]=&listOfVerticesP2[7]; |
---|
[12338] | 445 | } |
---|
| 446 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
[12357] | 447 | adjacentVertices[0]=&listOfVerticesP2[4]; |
---|
| 448 | adjacentVertices[1]=&listOfVerticesP2[9]; |
---|
| 449 | adjacentVertices[2]=&listOfVerticesP2[26]; |
---|
[12338] | 450 | } |
---|
| 451 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
[12357] | 452 | adjacentVertices[0]=&listOfVerticesP2[5]; |
---|
| 453 | adjacentVertices[1]=&listOfVerticesP2[8]; |
---|
[12338] | 454 | } |
---|
| 455 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
[12357] | 456 | adjacentVertices[0]=&listOfVerticesP2[7]; |
---|
| 457 | adjacentVertices[1]=&listOfVerticesP2[9]; |
---|
[12338] | 458 | } |
---|
| 459 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
[12357] | 460 | adjacentVertices[0]=&listOfVerticesP2[6]; |
---|
| 461 | adjacentVertices[1]=&listOfVerticesP2[8]; |
---|
| 462 | adjacentVertices[2]=&listOfVerticesP2[10]; |
---|
| 463 | adjacentVertices[3]=&listOfVerticesP2[38]; |
---|
[12338] | 464 | } |
---|
| 465 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
[12357] | 466 | adjacentVertices[0]=&listOfVerticesP2[9]; |
---|
| 467 | adjacentVertices[1]=&listOfVerticesP2[11]; |
---|
| 468 | adjacentVertices[2]=&listOfVerticesP2[45]; |
---|
[12338] | 469 | } |
---|
| 470 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
[12357] | 471 | adjacentVertices[0]=&listOfVerticesP2[10]; |
---|
| 472 | adjacentVertices[1]=&listOfVerticesP2[12]; |
---|
| 473 | adjacentVertices[2]=&listOfVerticesP2[13]; |
---|
[12338] | 474 | } |
---|
| 475 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
[12357] | 476 | adjacentVertices[0]=&listOfVerticesP2[11]; |
---|
| 477 | adjacentVertices[1]=&listOfVerticesP2[14]; |
---|
[12338] | 478 | } |
---|
| 479 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
[12357] | 480 | adjacentVertices[0]=&listOfVerticesP2[11]; |
---|
| 481 | adjacentVertices[1]=&listOfVerticesP2[14]; |
---|
| 482 | adjacentVertices[2]=&listOfVerticesP2[16]; |
---|
| 483 | adjacentVertices[3]=&listOfVerticesP2[61]; |
---|
[12338] | 484 | } |
---|
| 485 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
[12357] | 486 | adjacentVertices[0]=&listOfVerticesP2[12]; |
---|
| 487 | adjacentVertices[1]=&listOfVerticesP2[13]; |
---|
| 488 | adjacentVertices[2]=&listOfVerticesP2[15]; |
---|
[12338] | 489 | } |
---|
| 490 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
[12357] | 491 | adjacentVertices[0]=&listOfVerticesP2[14]; |
---|
| 492 | adjacentVertices[1]=&listOfVerticesP2[16]; |
---|
[12338] | 493 | } |
---|
| 494 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
[12357] | 495 | adjacentVertices[0]=&listOfVerticesP2[13]; |
---|
| 496 | adjacentVertices[1]=&listOfVerticesP2[15]; |
---|
| 497 | adjacentVertices[2]=&listOfVerticesP2[62]; |
---|
[12338] | 498 | } |
---|
| 499 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
[12357] | 500 | adjacentVertices[0]=&listOfVerticesP2[0]; |
---|
| 501 | adjacentVertices[1]=&listOfVerticesP2[25]; |
---|
[12338] | 502 | } |
---|
| 503 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
[12357] | 504 | adjacentVertices[0]=&listOfVerticesP2[19]; |
---|
| 505 | adjacentVertices[1]=&listOfVerticesP2[24]; |
---|
[12338] | 506 | } |
---|
| 507 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
[12357] | 508 | adjacentVertices[0]=&listOfVerticesP2[0]; |
---|
| 509 | adjacentVertices[1]=&listOfVerticesP2[18]; |
---|
| 510 | adjacentVertices[2]=&listOfVerticesP2[20]; |
---|
[12338] | 511 | } |
---|
| 512 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
[12357] | 513 | adjacentVertices[0]=&listOfVerticesP2[19]; |
---|
| 514 | adjacentVertices[1]=&listOfVerticesP2[21]; |
---|
[12338] | 515 | } |
---|
| 516 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
[12357] | 517 | adjacentVertices[0]=&listOfVerticesP2[20]; |
---|
| 518 | adjacentVertices[1]=&listOfVerticesP2[22]; |
---|
[12338] | 519 | } |
---|
| 520 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
[12357] | 521 | adjacentVertices[0]=&listOfVerticesP2[21]; |
---|
| 522 | adjacentVertices[1]=&listOfVerticesP2[23]; |
---|
| 523 | adjacentVertices[2]=&listOfVerticesP2[31]; |
---|
[12338] | 524 | } |
---|
| 525 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
[12357] | 526 | adjacentVertices[0]=&listOfVerticesP2[22]; |
---|
| 527 | adjacentVertices[1]=&listOfVerticesP2[30]; |
---|
[12338] | 528 | } |
---|
| 529 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
[12357] | 530 | adjacentVertices[0]=&listOfVerticesP2[18]; |
---|
| 531 | adjacentVertices[1]=&listOfVerticesP2[29]; |
---|
[12338] | 532 | } |
---|
| 533 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
[12357] | 534 | adjacentVertices[0]=&listOfVerticesP2[17]; |
---|
| 535 | adjacentVertices[1]=&listOfVerticesP2[26]; |
---|
[12338] | 536 | } |
---|
| 537 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
[12357] | 538 | adjacentVertices[0]=&listOfVerticesP2[6]; |
---|
| 539 | adjacentVertices[1]=&listOfVerticesP2[25]; |
---|
| 540 | adjacentVertices[2]=&listOfVerticesP2[27]; |
---|
[12338] | 541 | } |
---|
| 542 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
[12357] | 543 | adjacentVertices[0]=&listOfVerticesP2[26]; |
---|
| 544 | adjacentVertices[1]=&listOfVerticesP2[28]; |
---|
| 545 | adjacentVertices[2]=&listOfVerticesP2[37]; |
---|
[12338] | 546 | } |
---|
| 547 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
[12357] | 548 | adjacentVertices[0]=&listOfVerticesP2[27]; |
---|
| 549 | adjacentVertices[1]=&listOfVerticesP2[29]; |
---|
| 550 | adjacentVertices[2]=&listOfVerticesP2[36]; |
---|
[12338] | 551 | } |
---|
| 552 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
[12357] | 553 | adjacentVertices[0]=&listOfVerticesP2[24]; |
---|
| 554 | adjacentVertices[1]=&listOfVerticesP2[28]; |
---|
| 555 | adjacentVertices[2]=&listOfVerticesP2[30]; |
---|
[12338] | 556 | } |
---|
| 557 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
[12357] | 558 | adjacentVertices[0]=&listOfVerticesP2[23]; |
---|
| 559 | adjacentVertices[1]=&listOfVerticesP2[29]; |
---|
| 560 | adjacentVertices[2]=&listOfVerticesP2[34]; |
---|
[12338] | 561 | } |
---|
| 562 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
[12357] | 563 | adjacentVertices[0]=&listOfVerticesP2[22]; |
---|
| 564 | adjacentVertices[1]=&listOfVerticesP2[32]; |
---|
[12338] | 565 | } |
---|
| 566 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
[12357] | 567 | adjacentVertices[0]=&listOfVerticesP2[31]; |
---|
| 568 | adjacentVertices[1]=&listOfVerticesP2[33]; |
---|
[12338] | 569 | } |
---|
| 570 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
[12357] | 571 | adjacentVertices[0]=&listOfVerticesP2[32]; |
---|
| 572 | adjacentVertices[1]=&listOfVerticesP2[34]; |
---|
[12338] | 573 | } |
---|
| 574 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
[12357] | 575 | adjacentVertices[0]=&listOfVerticesP2[30]; |
---|
| 576 | adjacentVertices[1]=&listOfVerticesP2[33]; |
---|
| 577 | adjacentVertices[2]=&listOfVerticesP2[35]; |
---|
| 578 | adjacentVertices[3]=&listOfVerticesP2[42]; |
---|
[12318] | 579 | |
---|
[12338] | 580 | } |
---|
| 581 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
[12357] | 582 | adjacentVertices[0]=&listOfVerticesP2[34]; |
---|
| 583 | adjacentVertices[1]=&listOfVerticesP2[36]; |
---|
| 584 | adjacentVertices[2]=&listOfVerticesP2[41]; |
---|
[12338] | 585 | } |
---|
| 586 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
[12357] | 587 | adjacentVertices[0]=&listOfVerticesP2[28]; |
---|
| 588 | adjacentVertices[1]=&listOfVerticesP2[35]; |
---|
[12338] | 589 | } |
---|
| 590 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
[12357] | 591 | adjacentVertices[0]=&listOfVerticesP2[27]; |
---|
| 592 | adjacentVertices[1]=&listOfVerticesP2[38]; |
---|
[12338] | 593 | } |
---|
| 594 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
[12357] | 595 | adjacentVertices[0]=&listOfVerticesP2[9]; |
---|
| 596 | adjacentVertices[1]=&listOfVerticesP2[37]; |
---|
| 597 | adjacentVertices[2]=&listOfVerticesP2[39]; |
---|
[12338] | 598 | } |
---|
| 599 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
[12357] | 600 | adjacentVertices[0]=&listOfVerticesP2[38]; |
---|
| 601 | adjacentVertices[1]=&listOfVerticesP2[40]; |
---|
| 602 | adjacentVertices[2]=&listOfVerticesP2[45]; |
---|
[12338] | 603 | } |
---|
| 604 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
[12357] | 605 | adjacentVertices[0]=&listOfVerticesP2[39]; |
---|
| 606 | adjacentVertices[1]=&listOfVerticesP2[41]; |
---|
[12338] | 607 | } |
---|
| 608 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
[12357] | 609 | adjacentVertices[0]=&listOfVerticesP2[35]; |
---|
| 610 | adjacentVertices[1]=&listOfVerticesP2[43]; |
---|
| 611 | adjacentVertices[2]=&listOfVerticesP2[40]; |
---|
[12338] | 612 | } |
---|
| 613 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
[12357] | 614 | adjacentVertices[0]=&listOfVerticesP2[34]; |
---|
| 615 | adjacentVertices[1]=&listOfVerticesP2[43]; |
---|
| 616 | adjacentVertices[2]=&listOfVerticesP2[54]; |
---|
[12338] | 617 | } |
---|
| 618 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
[12357] | 619 | adjacentVertices[0]=&listOfVerticesP2[41]; |
---|
| 620 | adjacentVertices[1]=&listOfVerticesP2[46]; |
---|
| 621 | adjacentVertices[2]=&listOfVerticesP2[42]; |
---|
[12338] | 622 | } |
---|
| 623 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
[12357] | 624 | adjacentVertices[0]=&listOfVerticesP2[40]; |
---|
| 625 | adjacentVertices[1]=&listOfVerticesP2[66]; |
---|
[12338] | 626 | } |
---|
| 627 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
[12357] | 628 | adjacentVertices[0]=&listOfVerticesP2[10]; |
---|
| 629 | adjacentVertices[1]=&listOfVerticesP2[39]; |
---|
| 630 | adjacentVertices[2]=&listOfVerticesP2[49]; |
---|
[12338] | 631 | } |
---|
| 632 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
[12357] | 633 | adjacentVertices[0]=&listOfVerticesP2[43]; |
---|
| 634 | adjacentVertices[1]=&listOfVerticesP2[47]; |
---|
[12338] | 635 | } |
---|
| 636 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
[12357] | 637 | adjacentVertices[0]=&listOfVerticesP2[46]; |
---|
| 638 | adjacentVertices[1]=&listOfVerticesP2[52]; |
---|
| 639 | adjacentVertices[2]=&listOfVerticesP2[66]; |
---|
[12338] | 640 | } |
---|
| 641 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
[12357] | 642 | adjacentVertices[0]=&listOfVerticesP2[49]; |
---|
| 643 | adjacentVertices[1]=&listOfVerticesP2[51]; |
---|
| 644 | adjacentVertices[2]=&listOfVerticesP2[66]; |
---|
[12338] | 645 | } |
---|
| 646 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
[12357] | 647 | adjacentVertices[0]=&listOfVerticesP2[45]; |
---|
| 648 | adjacentVertices[1]=&listOfVerticesP2[48]; |
---|
[12338] | 649 | } |
---|
| 650 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
[12357] | 651 | adjacentVertices[0]=&listOfVerticesP2[51]; |
---|
| 652 | adjacentVertices[1]=&listOfVerticesP2[61]; |
---|
[12338] | 653 | } |
---|
| 654 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
[12357] | 655 | adjacentVertices[0]=&listOfVerticesP2[48]; |
---|
| 656 | adjacentVertices[1]=&listOfVerticesP2[50]; |
---|
[12338] | 657 | } |
---|
| 658 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
[12357] | 659 | adjacentVertices[0]=&listOfVerticesP2[47]; |
---|
| 660 | adjacentVertices[1]=&listOfVerticesP2[53]; |
---|
[12338] | 661 | } |
---|
| 662 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
[12357] | 663 | adjacentVertices[0]=&listOfVerticesP2[52]; |
---|
| 664 | adjacentVertices[1]=&listOfVerticesP2[58]; |
---|
[12338] | 665 | } |
---|
| 666 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
[12357] | 667 | adjacentVertices[0]=&listOfVerticesP2[42]; |
---|
| 668 | adjacentVertices[1]=&listOfVerticesP2[55]; |
---|
| 669 | adjacentVertices[2]=&listOfVerticesP2[57]; |
---|
[12338] | 670 | } |
---|
| 671 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
[12357] | 672 | adjacentVertices[0]=&listOfVerticesP2[54]; |
---|
| 673 | adjacentVertices[1]=&listOfVerticesP2[56]; |
---|
[12338] | 674 | } |
---|
| 675 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
[12357] | 676 | adjacentVertices[0]=&listOfVerticesP2[55]; |
---|
| 677 | adjacentVertices[1]=&listOfVerticesP2[57]; |
---|
| 678 | adjacentVertices[2]=&listOfVerticesP2[65]; |
---|
[12338] | 679 | } |
---|
| 680 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
[12357] | 681 | adjacentVertices[0]=&listOfVerticesP2[54]; |
---|
| 682 | adjacentVertices[1]=&listOfVerticesP2[56]; |
---|
| 683 | adjacentVertices[2]=&listOfVerticesP2[58]; |
---|
| 684 | adjacentVertices[3]=&listOfVerticesP2[64]; |
---|
[12317] | 685 | |
---|
[12338] | 686 | } |
---|
| 687 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
[12357] | 688 | adjacentVertices[0]=&listOfVerticesP2[53]; |
---|
| 689 | adjacentVertices[1]=&listOfVerticesP2[57]; |
---|
| 690 | adjacentVertices[2]=&listOfVerticesP2[59]; |
---|
[12338] | 691 | } |
---|
| 692 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
[12357] | 693 | adjacentVertices[0]=&listOfVerticesP2[58]; |
---|
| 694 | adjacentVertices[1]=&listOfVerticesP2[60]; |
---|
| 695 | adjacentVertices[2]=&listOfVerticesP2[63]; |
---|
[12338] | 696 | } |
---|
| 697 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
[12357] | 698 | adjacentVertices[0]=&listOfVerticesP2[59]; |
---|
| 699 | adjacentVertices[1]=&listOfVerticesP2[61]; |
---|
| 700 | adjacentVertices[2]=&listOfVerticesP2[62]; |
---|
[12338] | 701 | } |
---|
| 702 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
[12357] | 703 | adjacentVertices[0]=&listOfVerticesP2[13]; |
---|
| 704 | adjacentVertices[1]=&listOfVerticesP2[50]; |
---|
| 705 | adjacentVertices[2]=&listOfVerticesP2[60]; |
---|
[12338] | 706 | } |
---|
| 707 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
[12357] | 708 | adjacentVertices[0]=&listOfVerticesP2[16]; |
---|
| 709 | adjacentVertices[1]=&listOfVerticesP2[60]; |
---|
[12338] | 710 | } |
---|
| 711 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
[12357] | 712 | adjacentVertices[0]=&listOfVerticesP2[59]; |
---|
| 713 | adjacentVertices[1]=&listOfVerticesP2[64]; |
---|
[12338] | 714 | } |
---|
| 715 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
[12357] | 716 | adjacentVertices[0]=&listOfVerticesP2[57]; |
---|
| 717 | adjacentVertices[1]=&listOfVerticesP2[63]; |
---|
| 718 | adjacentVertices[2]=&listOfVerticesP2[65]; |
---|
[12338] | 719 | } |
---|
| 720 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
[12357] | 721 | adjacentVertices[0]=&listOfVerticesP2[56]; |
---|
| 722 | adjacentVertices[1]=&listOfVerticesP2[64]; |
---|
[12338] | 723 | } |
---|
| 724 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
[12357] | 725 | adjacentVertices[0]=&listOfVerticesP2[47]; |
---|
| 726 | adjacentVertices[1]=&listOfVerticesP2[48]; |
---|
[12338] | 727 | } |
---|
| 728 | } |
---|
[12318] | 729 | |
---|
| 730 | |
---|
[12338] | 731 | Vector3 PacmanGhost::frontPosition(){ |
---|
[12357] | 732 | //Should return the Vector3 point in front of the player. |
---|
[12317] | 733 | |
---|
[12338] | 734 | Vector3 neighborPos[4] = {Vector3(-1,-1,-1)}; |
---|
| 735 | Vector3 frontPoint = Vector3(0,-1,0); |
---|
[12325] | 736 | |
---|
| 737 | |
---|
[12338] | 738 | findNeighboorPositions(this->lastPlayerPassedPoint, neighborPos, possibleposition); |
---|
[12325] | 739 | |
---|
[12338] | 740 | for(int i=0; i<4; i++){ |
---|
[12325] | 741 | |
---|
[12338] | 742 | if((neighborPos[i]!=Vector3(-1,-1,-1))&&(neighborPos[i].y==10)){ |
---|
| 743 | //y==10 to ignore many unwanted strange positions that pop up otherwise and create SIGSEV |
---|
[12325] | 744 | |
---|
[12338] | 745 | if(frontPoint==Vector3(0,-1,0)){ |
---|
| 746 | frontPoint=neighborPos[i]; |
---|
[12325] | 747 | |
---|
[12338] | 748 | } |
---|
| 749 | else if (graphDistance(this->getPlayerPos(), frontPoint)>graphDistance(this->getPlayerPos(), neighborPos[i])){ |
---|
| 750 | frontPoint=neighborPos[i]; |
---|
| 751 | } |
---|
[12325] | 752 | |
---|
[12338] | 753 | } |
---|
| 754 | } |
---|
[12325] | 755 | |
---|
[12338] | 756 | if(frontPoint==Vector3(0,-1,0)){ |
---|
| 757 | //default |
---|
| 758 | return this->lastPlayerPassedPoint; |
---|
| 759 | } |
---|
| 760 | else{ |
---|
| 761 | return frontPoint; |
---|
| 762 | } |
---|
| 763 | } |
---|
[12325] | 764 | |
---|
| 765 | |
---|
| 766 | |
---|
| 767 | |
---|
| 768 | |
---|
| 769 | |
---|
[12338] | 770 | void PacmanGhost::findNeighboorPositions(Vector3 actuelposition, Vector3 adjacentPositions[], Vector3 positionArray[]){ |
---|
[12357] | 771 | //this function should put in adjacentPositions[] the neighboors of actuelposition. |
---|
| 772 | // positionArray[] contains all possible positions of the map. |
---|
[12325] | 773 | |
---|
[12338] | 774 | if(findpos(actuelposition,possibleposition[0])){ |
---|
[12325] | 775 | |
---|
| 776 | |
---|
[12357] | 777 | adjacentPositions[0]=positionArray[1]; |
---|
| 778 | adjacentPositions[1]=positionArray[17]; |
---|
| 779 | adjacentPositions[2]=positionArray[19]; |
---|
[12338] | 780 | } |
---|
| 781 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
[12357] | 782 | adjacentPositions[0]=positionArray[0]; |
---|
| 783 | adjacentPositions[1]=positionArray[2]; |
---|
[12338] | 784 | } |
---|
| 785 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
[12357] | 786 | adjacentPositions[0]=positionArray[1]; |
---|
| 787 | adjacentPositions[1]=positionArray[3]; |
---|
[12338] | 788 | } |
---|
| 789 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
[12357] | 790 | adjacentPositions[0]=positionArray[2]; |
---|
| 791 | adjacentPositions[1]=positionArray[4]; |
---|
| 792 | adjacentPositions[2]=positionArray[5]; |
---|
[12338] | 793 | } |
---|
| 794 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
[12357] | 795 | adjacentPositions[0]=positionArray[3]; |
---|
| 796 | adjacentPositions[1]=positionArray[6]; |
---|
[12338] | 797 | } |
---|
| 798 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
[12357] | 799 | adjacentPositions[0]=positionArray[3]; |
---|
| 800 | adjacentPositions[1]=positionArray[7]; |
---|
[12338] | 801 | } |
---|
| 802 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
[12357] | 803 | adjacentPositions[0]=positionArray[4]; ; |
---|
| 804 | adjacentPositions[1]=positionArray[9]; |
---|
| 805 | adjacentPositions[2]=positionArray[26]; |
---|
[12338] | 806 | } |
---|
| 807 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
[12357] | 808 | adjacentPositions[0]=positionArray[5]; |
---|
| 809 | adjacentPositions[1]=positionArray[8]; |
---|
[12338] | 810 | } |
---|
| 811 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
[12357] | 812 | adjacentPositions[0]=positionArray[7]; |
---|
| 813 | adjacentPositions[1]=positionArray[9]; |
---|
[12338] | 814 | } |
---|
| 815 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
[12357] | 816 | adjacentPositions[0]=positionArray[6]; |
---|
| 817 | adjacentPositions[1]=positionArray[8]; |
---|
| 818 | adjacentPositions[2]=positionArray[10]; |
---|
| 819 | adjacentPositions[3]=positionArray[38]; |
---|
[12338] | 820 | } |
---|
| 821 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
[12357] | 822 | adjacentPositions[0]=positionArray[9]; |
---|
| 823 | adjacentPositions[1]=positionArray[11]; |
---|
| 824 | adjacentPositions[2]=positionArray[45]; |
---|
[12338] | 825 | } |
---|
| 826 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
[12357] | 827 | adjacentPositions[0]=positionArray[10]; |
---|
| 828 | adjacentPositions[1]=positionArray[12]; |
---|
| 829 | adjacentPositions[2]=positionArray[13]; |
---|
[12338] | 830 | } |
---|
| 831 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
[12357] | 832 | adjacentPositions[0]=positionArray[11]; |
---|
| 833 | adjacentPositions[1]=positionArray[14]; |
---|
[12338] | 834 | } |
---|
| 835 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
[12357] | 836 | adjacentPositions[0]=positionArray[11]; |
---|
| 837 | adjacentPositions[1]=positionArray[14]; |
---|
| 838 | adjacentPositions[2]=positionArray[16]; |
---|
| 839 | adjacentPositions[3]=positionArray[61]; |
---|
[12338] | 840 | } |
---|
| 841 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
[12357] | 842 | adjacentPositions[0]=positionArray[12]; |
---|
| 843 | adjacentPositions[1]=positionArray[13]; |
---|
| 844 | adjacentPositions[2]=positionArray[15]; |
---|
[12338] | 845 | } |
---|
| 846 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
[12357] | 847 | adjacentPositions[0]=positionArray[14]; |
---|
| 848 | adjacentPositions[1]=positionArray[16]; |
---|
[12338] | 849 | } |
---|
| 850 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
[12357] | 851 | adjacentPositions[0]=positionArray[13]; |
---|
| 852 | adjacentPositions[1]=positionArray[15]; |
---|
| 853 | adjacentPositions[2]=positionArray[62]; |
---|
[12338] | 854 | } |
---|
| 855 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
[12357] | 856 | adjacentPositions[0]=positionArray[0]; |
---|
| 857 | adjacentPositions[1]=positionArray[25]; |
---|
[12338] | 858 | } |
---|
| 859 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
[12357] | 860 | adjacentPositions[0]=positionArray[19]; |
---|
| 861 | adjacentPositions[1]=positionArray[24]; |
---|
[12338] | 862 | } |
---|
| 863 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
[12357] | 864 | adjacentPositions[0]=positionArray[0]; |
---|
| 865 | adjacentPositions[1]=positionArray[18]; |
---|
| 866 | adjacentPositions[2]=positionArray[20]; |
---|
[12338] | 867 | } |
---|
| 868 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
[12357] | 869 | adjacentPositions[0]=positionArray[19]; |
---|
| 870 | adjacentPositions[1]=positionArray[21]; |
---|
[12338] | 871 | } |
---|
| 872 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
[12357] | 873 | adjacentPositions[0]=positionArray[20]; |
---|
| 874 | adjacentPositions[1]=positionArray[22]; |
---|
[12338] | 875 | } |
---|
| 876 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
[12357] | 877 | adjacentPositions[0]=positionArray[21]; |
---|
| 878 | adjacentPositions[1]=positionArray[23]; |
---|
| 879 | adjacentPositions[2]=positionArray[31]; |
---|
[12338] | 880 | } |
---|
| 881 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
[12357] | 882 | adjacentPositions[0]=positionArray[22]; |
---|
| 883 | adjacentPositions[1]=positionArray[30]; |
---|
[12338] | 884 | } |
---|
| 885 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
[12357] | 886 | adjacentPositions[0]=positionArray[18]; |
---|
| 887 | adjacentPositions[1]=positionArray[29]; |
---|
[12338] | 888 | } |
---|
| 889 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
[12357] | 890 | adjacentPositions[0]=positionArray[17]; |
---|
| 891 | adjacentPositions[1]=positionArray[26]; |
---|
[12338] | 892 | } |
---|
| 893 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
[12357] | 894 | adjacentPositions[0]=positionArray[6]; |
---|
| 895 | adjacentPositions[1]=positionArray[25]; |
---|
| 896 | adjacentPositions[2]=positionArray[27]; |
---|
[12338] | 897 | } |
---|
| 898 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
[12357] | 899 | adjacentPositions[0]=positionArray[26]; |
---|
| 900 | adjacentPositions[1]=positionArray[28]; |
---|
| 901 | adjacentPositions[2]=positionArray[37]; |
---|
[12338] | 902 | } |
---|
| 903 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
[12357] | 904 | adjacentPositions[0]=positionArray[27]; |
---|
| 905 | adjacentPositions[1]=positionArray[29]; |
---|
| 906 | adjacentPositions[2]=positionArray[36]; |
---|
[12338] | 907 | } |
---|
| 908 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
[12357] | 909 | adjacentPositions[0]=positionArray[24]; |
---|
| 910 | adjacentPositions[1]=positionArray[28]; |
---|
| 911 | adjacentPositions[2]=positionArray[30]; |
---|
[12338] | 912 | } |
---|
| 913 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
[12357] | 914 | adjacentPositions[0]=positionArray[23]; |
---|
| 915 | adjacentPositions[1]=positionArray[29]; |
---|
| 916 | adjacentPositions[2]=positionArray[34]; |
---|
[12338] | 917 | } |
---|
| 918 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
[12357] | 919 | adjacentPositions[0]=positionArray[22]; |
---|
| 920 | adjacentPositions[1]=positionArray[32]; |
---|
[12338] | 921 | } |
---|
| 922 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
[12357] | 923 | adjacentPositions[0]=positionArray[31]; |
---|
| 924 | adjacentPositions[1]=positionArray[33]; |
---|
[12338] | 925 | } |
---|
| 926 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
[12357] | 927 | adjacentPositions[0]=positionArray[32]; |
---|
| 928 | adjacentPositions[1]=positionArray[34]; |
---|
[12338] | 929 | } |
---|
| 930 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
[12357] | 931 | adjacentPositions[0]=positionArray[30]; |
---|
| 932 | adjacentPositions[1]=positionArray[33]; |
---|
| 933 | adjacentPositions[2]=positionArray[35]; |
---|
| 934 | adjacentPositions[3]=positionArray[42]; |
---|
[12325] | 935 | |
---|
[12338] | 936 | } |
---|
| 937 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
[12357] | 938 | adjacentPositions[0]=positionArray[34]; |
---|
| 939 | adjacentPositions[1]=positionArray[36]; |
---|
| 940 | adjacentPositions[2]=positionArray[41]; |
---|
[12338] | 941 | } |
---|
| 942 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
[12357] | 943 | adjacentPositions[0]=positionArray[28]; |
---|
| 944 | adjacentPositions[1]=positionArray[35]; |
---|
[12338] | 945 | } |
---|
| 946 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
[12357] | 947 | adjacentPositions[0]=positionArray[27]; |
---|
| 948 | adjacentPositions[1]=positionArray[38]; |
---|
[12338] | 949 | } |
---|
| 950 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
[12357] | 951 | adjacentPositions[0]=positionArray[9]; |
---|
| 952 | adjacentPositions[1]=positionArray[37]; |
---|
| 953 | adjacentPositions[2]=positionArray[39]; |
---|
[12338] | 954 | } |
---|
| 955 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
[12357] | 956 | adjacentPositions[0]=positionArray[38]; |
---|
| 957 | adjacentPositions[1]=positionArray[40]; |
---|
| 958 | adjacentPositions[2]=positionArray[45]; |
---|
[12338] | 959 | } |
---|
| 960 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
[12357] | 961 | adjacentPositions[0]=positionArray[39]; |
---|
| 962 | adjacentPositions[1]=positionArray[41]; |
---|
[12338] | 963 | } |
---|
| 964 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
[12357] | 965 | adjacentPositions[0]=positionArray[35]; |
---|
| 966 | adjacentPositions[1]=positionArray[43]; |
---|
| 967 | adjacentPositions[2]=positionArray[40]; |
---|
[12338] | 968 | } |
---|
| 969 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
[12357] | 970 | adjacentPositions[0]=positionArray[34]; |
---|
| 971 | adjacentPositions[1]=positionArray[43]; |
---|
| 972 | adjacentPositions[2]=positionArray[54]; |
---|
[12338] | 973 | } |
---|
| 974 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
[12357] | 975 | adjacentPositions[0]=positionArray[41]; |
---|
| 976 | adjacentPositions[1]=positionArray[46]; |
---|
| 977 | adjacentPositions[2]=positionArray[42]; |
---|
[12338] | 978 | } |
---|
| 979 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
[12357] | 980 | adjacentPositions[0]=positionArray[40]; |
---|
| 981 | adjacentPositions[1]=positionArray[66]; |
---|
[12338] | 982 | } |
---|
| 983 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
[12357] | 984 | adjacentPositions[0]=positionArray[10]; |
---|
| 985 | adjacentPositions[1]=positionArray[39]; |
---|
| 986 | adjacentPositions[2]=positionArray[49]; |
---|
[12338] | 987 | } |
---|
| 988 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
[12357] | 989 | adjacentPositions[0]=positionArray[43]; |
---|
| 990 | adjacentPositions[1]=positionArray[47]; |
---|
[12338] | 991 | } |
---|
| 992 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
[12357] | 993 | adjacentPositions[0]=positionArray[46]; |
---|
| 994 | adjacentPositions[1]=positionArray[52]; |
---|
| 995 | adjacentPositions[2]=positionArray[66]; |
---|
[12338] | 996 | } |
---|
| 997 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
[12357] | 998 | adjacentPositions[0]=positionArray[49]; |
---|
| 999 | adjacentPositions[1]=positionArray[51]; |
---|
| 1000 | adjacentPositions[2]=positionArray[66]; |
---|
[12338] | 1001 | } |
---|
| 1002 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
[12357] | 1003 | adjacentPositions[0]=positionArray[45]; |
---|
| 1004 | adjacentPositions[1]=positionArray[48]; |
---|
[12338] | 1005 | } |
---|
| 1006 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
[12357] | 1007 | adjacentPositions[0]=positionArray[51]; |
---|
| 1008 | adjacentPositions[1]=positionArray[61]; |
---|
[12338] | 1009 | } |
---|
| 1010 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
[12357] | 1011 | adjacentPositions[0]=positionArray[48]; |
---|
| 1012 | adjacentPositions[1]=positionArray[50]; |
---|
[12338] | 1013 | } |
---|
| 1014 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
[12357] | 1015 | adjacentPositions[0]=positionArray[47]; |
---|
| 1016 | adjacentPositions[1]=positionArray[53]; |
---|
[12338] | 1017 | } |
---|
| 1018 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
[12357] | 1019 | adjacentPositions[0]=positionArray[52]; |
---|
| 1020 | adjacentPositions[1]=positionArray[58]; |
---|
[12338] | 1021 | } |
---|
| 1022 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
[12357] | 1023 | adjacentPositions[0]=positionArray[42]; |
---|
| 1024 | adjacentPositions[1]=positionArray[55]; |
---|
| 1025 | adjacentPositions[2]=positionArray[57]; |
---|
[12338] | 1026 | } |
---|
| 1027 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
[12357] | 1028 | adjacentPositions[0]=positionArray[54]; |
---|
| 1029 | adjacentPositions[1]=positionArray[56]; |
---|
[12338] | 1030 | } |
---|
| 1031 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
[12357] | 1032 | adjacentPositions[0]=positionArray[55]; |
---|
| 1033 | adjacentPositions[1]=positionArray[57]; |
---|
| 1034 | adjacentPositions[2]=positionArray[65]; |
---|
[12338] | 1035 | } |
---|
| 1036 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
[12357] | 1037 | adjacentPositions[0]=positionArray[54]; |
---|
| 1038 | adjacentPositions[1]=positionArray[56]; |
---|
| 1039 | adjacentPositions[2]=positionArray[58]; |
---|
| 1040 | adjacentPositions[3]=positionArray[64]; |
---|
[12325] | 1041 | |
---|
[12338] | 1042 | } |
---|
| 1043 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
[12357] | 1044 | adjacentPositions[0]=positionArray[53]; |
---|
| 1045 | adjacentPositions[1]=positionArray[57]; |
---|
| 1046 | adjacentPositions[2]=positionArray[59]; |
---|
[12338] | 1047 | } |
---|
| 1048 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
[12357] | 1049 | adjacentPositions[0]=positionArray[58]; |
---|
| 1050 | adjacentPositions[1]=positionArray[60]; |
---|
| 1051 | adjacentPositions[2]=positionArray[63]; |
---|
[12338] | 1052 | } |
---|
| 1053 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
[12357] | 1054 | adjacentPositions[0]=positionArray[59]; |
---|
| 1055 | adjacentPositions[1]=positionArray[61]; |
---|
| 1056 | adjacentPositions[2]=positionArray[62]; |
---|
[12338] | 1057 | } |
---|
| 1058 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
[12357] | 1059 | adjacentPositions[0]=positionArray[13]; |
---|
| 1060 | adjacentPositions[1]=positionArray[50]; |
---|
| 1061 | adjacentPositions[2]=positionArray[60]; |
---|
[12338] | 1062 | } |
---|
| 1063 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
[12357] | 1064 | adjacentPositions[0]=positionArray[16]; |
---|
| 1065 | adjacentPositions[1]=positionArray[60]; |
---|
[12338] | 1066 | } |
---|
| 1067 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
[12357] | 1068 | adjacentPositions[0]=positionArray[59]; |
---|
| 1069 | adjacentPositions[1]=positionArray[64]; |
---|
[12338] | 1070 | } |
---|
| 1071 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
[12357] | 1072 | adjacentPositions[0]=positionArray[57]; |
---|
| 1073 | adjacentPositions[1]=positionArray[63]; |
---|
| 1074 | adjacentPositions[2]=positionArray[65]; |
---|
[12338] | 1075 | } |
---|
| 1076 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
[12357] | 1077 | adjacentPositions[0]=positionArray[56]; |
---|
| 1078 | adjacentPositions[1]=positionArray[64]; |
---|
[12338] | 1079 | } |
---|
| 1080 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
[12357] | 1081 | adjacentPositions[0]=positionArray[47]; |
---|
| 1082 | adjacentPositions[1]=positionArray[48]; |
---|
[12338] | 1083 | } |
---|
| 1084 | } |
---|
[12325] | 1085 | |
---|
| 1086 | |
---|
[12338] | 1087 | } |
---|