Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc @ 12326

Last change on this file since 12326 was 12326, checked in by peterf, 5 years ago

bug fix

  • Property svn:executable set to *
File size: 89.3 KB
Line 
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:
23 *      Marc Dreher
24 *   Co-authors:
25 *      ..
26 *
27 */
28
29#include "PacmanGhost.h"
30
31#include "core/CoreIncludes.h"
32#include "BulletDynamics/Dynamics/btRigidBody.h"
33
34namespace orxonox
35{
36
37
38    struct PacmanGhost::graphVertex {
39
40        public:
41
42            Vector3 position;
43            graphVertex *adjacentVertices[4]; //neighbooring vertices
44
45            //would a vector of vector storing the neighboors not be more suitable ?
46
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;
76   
77            return *this;
78        }
79
80        };
81
82
83    static PacmanGhost::graphVertex listOfVertices[67];
84
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        }
90
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
106
107    RegisterClass(PacmanGhost);
108
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);
118
119        //this->pathAlgorithm = new GetShortestPathAlgorithm;
120
121
122        this->velocity = Vector3(0, 0, 0);
123
124        this->setCollisionType(CollisionType::Dynamic);
125       
126        this->actuelposition = this->getPosition();
127
128        if(findpos(actuelposition, Vector3(0,-20,0)))
129            dontmove = true;
130       
131        this->target_x = actuelposition.x;
132        this->target_z = actuelposition.z; 
133
134        //this->lastPlayerPassedPoint=Vector3(185,10,150); //no idea what to put
135
136    }
137
138    /**
139    @brief
140        Destructor. Destroys ghost, if present.
141    */
142    PacmanGhost::~PacmanGhost()
143    {
144        // Deletes the controller if the object was initialized and the pointer to the controller is not nullptr.
145    }
146
147    /**
148    @brief
149        Method for creating a ghost through XML.
150    */
151     void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode)
152    {
153        SUPER(PacmanGhost, XMLPort, xmlelement, mode);
154    }
155
156    //Change this with other ghost
157    void PacmanGhost::changewith(PacmanGhost* otherghost){
158
159        while(lockmove){};
160        lockmove = true;    //Prevent change of target while ghost is changed
161
162        otherghost->setPosition(this->getPosition());
163        this->setPosition(0,-20,0);
164        otherghost->target_x = this->target_x;   
165        otherghost->target_z = this->target_z;
166        otherghost->ismoving = this->ismoving;
167
168        this->dontmove = true;
169        otherghost->dontmove = false;
170
171        lockmove = false;
172    }
173
174    //Move ghost with rotation
175    void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){
176        if(!dontmove){
177            this->setPosition(Vector3(actuelposition.x+speed*velocity.x*dt,10,actuelposition.z+speed*velocity.z*dt));
178       
179        //Rotate ghost in the direction of movement
180        if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)){
181            if(velocity.x<0){
182                 this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); 
183            }
184            else{
185                 this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); 
186            }
187        }
188        if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)){
189            if(velocity.z<0){
190                 this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); 
191            }
192            else{
193                 this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); 
194            }
195        }
196                     
197     }
198    }
199
200    //Change ability to move
201    void PacmanGhost::changemovability(){
202        if(dontmove){
203         dontmove = false;}
204        else{
205         dontmove = true;   
206        }
207    }
208
209    //ResetGhost
210    void PacmanGhost::resetGhost(){
211   
212        this->setPosition(this->resetposition);
213        this->ismoving = false;
214        this->actuelposition = this->getPosition();
215       
216        this->target_x = actuelposition.x;
217        this->target_z = actuelposition.z;
218   
219    }
220
221    //Increase speed of ghosts
222    void PacmanGhost::levelupvelo(){
223        speed ++;
224    }
225
226    Vector3 PacmanGhost::getPlayerPos()
227    {
228        for (PacmanGelb* player : ObjectList<PacmanGelb>())
229        {
230            return player->getWorldPosition();
231        }
232        //std::cout<<"bug ??"<<endl;
233        return Vector3(0,0,0); //default, should not be used
234   
235    }
236
237
238    bool PacmanGhost::jeanfindpos(Vector3 one, Vector3 other){
239       if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true;
240        return false;
241        }
242
243    void PacmanGhost::setNewTargetGhost(Vector3 goalToGo){
244
245                    this->target_x = goalToGo.x;
246                    this->target_z = goalToGo.z; 
247                    this->ismoving = true;
248    }
249
250
251    ///
252    //// getShortestPath   /////////
253    ///
254
255       
256       
257    Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1){
258        //this function should then somehow produce the algorithm and call all other functions
259        //and finally return the best neighboor of the actual position of the pacman
260       
261    //(optional parameter) pointToAvoidP1 is a point that cannot be considered
262       
263
264    graphVertex listOfVerticesM[67]; //our list of all possible graphs
265    graphVertex* actualVertex; //we will walk through the array with a pointer
266   
267        if(start==goal){ // basic case
268            return start; 
269        }
270
271        for(int an=0; an < 67; an++){
272      listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file
273    if(start==possibleposition[an]){
274     actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array
275    //cout<<an<<endl;
276        }
277        }
278
279        //graphVertex actualVertex= listOfVerticesM[an];
280
281        actualVertex->alreadyVisited=true; //our start point is now visited
282        actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0
283        findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); 
284        // second parameter is an array ! //third is our global array
285
286        while(actualVertex->position!=goal){
287            for(int h=0;h < 4; h++){
288                if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex
289 
290         //h=2 and 3 never reached
291                    updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]);
292                } //we "update" the neighboors of our new visited vertex
293       
294            }
295           
296            actualVertex=findNextVertexToConsider(listOfVerticesM, pointToAvoidP1);
297            actualVertex->alreadyVisited=true;
298    //cout<<actualVertex->position<<endl;
299            if(actualVertex->position!=goal){
300                findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); 
301                //we find the neighboors of our new visited vertex
302                }
303        }
304
305    //cout<<"meuejeeke"<<endl; never reached
306
307        //we should have reached our goal at this point
308
309        while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor
310            actualVertex=actualVertex->actuelPredecessor;
311        }
312        // the predecessor is our starting point, in other words we are now on an
313        //adjacent vertex of the start
314
315        return actualVertex->position; //we return the position of this - adjacent to start - vertex
316    }
317
318//end of getShortestPath
319
320
321    int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){
322    //cout<<hgj++<<endl;
323        Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));
324
325        return differenceVector.x+differenceVector.z;
326    }
327
328    void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){
329        //apply this method to all non visited neighboors of a vertex.
330        // This method should always be run on a vertex after we marked it as visited.
331        if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors.
332            if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&&
333        (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart + 
334                graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case !
335       
336                neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart + 
337                graphDistance(vertex.position, neighboor.position);
338                neighboor.actuelPredecessor = &vertex;
339            }
340        }
341    }
342
343    void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex, Vector3 pointToAvoidP3){ 
344            //find nearest non visited neighboor of a given already visited vertex
345    //(optional parameter) pointToAvoidP3 is a point that cannot be considered
346        int shortestDistance = -1;
347        graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any.
348        //Also, if all neighboors are already visited, we return NULL, i.e. there is no
349        //nearest non visited neighboor.
350        for(int i=0; i < 4; i++){
351            if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)&&(vertex.adjacentVertices[i]->position!=pointToAvoidP3)){
352                if(shortestDistance==-1){   //(concerns line above) we want a non visited neighboor //(optional) if the position of the neighboor is the one we want
353    //to avoid, then we ignore it
354
355                    shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
356                    nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
357    //cout<<shortestDistance<<endl;
358                }
359                else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){
360                    shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
361                    nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
362        //cout<<(hgj++)%4<<endl;
363                }
364            }
365        }
366        vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses !
367    //cout<<hgj++<<endl;
368    }
369
370
371    PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[], Vector3 pointToAvoidP2){ //find next, nearest from start, non visited vertex in our listOfVertices array
372    //(optional parameter) pointToAvoidP2 is a point that cannot be considered
373
374        int shortestDistance = -1;
375        graphVertex* nextVertexToConsider;
376
377        for(int i=0; i < 67; i++){ //we loop over all possible positions
378
379            if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited
380
381                findNearestNonVisitedNeighboor(listOfVerticesP[i], pointToAvoidP2); //we update nearest neighboor
382                //of all visited vertices given that one of the nearest neighboor of a visited
383                // vertex is now also visited because it was chosen as next optimal vertex
384
385                if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate!
386                if(shortestDistance==-1){ //our first possible candidate
387
388            shortestDistance=graphDistance(listOfVerticesP[i].position, 
389            listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 
390            listOfVerticesP[i].shortestDistanceToStart;
391
392            nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
393    //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor
394
395                }
396                else if(shortestDistance > graphDistance(listOfVerticesP[i].position, 
397                listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 
398                    listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available
399
400            shortestDistance=graphDistance(listOfVerticesP[i].position, 
401            listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 
402            listOfVerticesP[i].shortestDistanceToStart;
403
404            nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
405    //we dont need the & because we are not giving the adress of the array element
406    //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor
407                    }
408                }
409            }
410            //we want after all to return the nearest non visited neighboor
411        }
412
413        return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array
414    }
415
416    //////////////////////////////////////////////////////////////////////////////////////////////
417
418    //if vertex already visited, call function on it and reapeat until you reach non visited vertex
419    // ---> not sure if a good idea because we risk infinite loop
420
421    //-215 -185 -135 -70 -20 0 20 70 135 185 215
422
423    //-195 -135 -85 -35 15 60 105 150 195 245
424
425    void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){     
426
427
428            if(findpos(actuelposition,possibleposition[0])){
429                // we should use listOfVerticesP2[i] instead of possibleposition[i] I think
430                // so that all neighboors are "the same"
431                adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);  //need to do it everywhere !!!
432                adjacentVertices[1]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
433                adjacentVertices[2]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ?
434            }
435            else if(findpos(actuelposition,possibleposition[1])){
436                adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
437                adjacentVertices[1]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
438            }
439            else if(findpos(actuelposition,possibleposition[2])){
440                adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);
441                adjacentVertices[1]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
442            }
443            else if(findpos(actuelposition,possibleposition[3])){
444                adjacentVertices[0]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
445                adjacentVertices[1]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
446                adjacentVertices[2]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
447            }
448            else if(findpos(actuelposition,possibleposition[4])){
449                adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
450                adjacentVertices[1]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
451            }
452            else if(findpos(actuelposition,possibleposition[5])){
453                adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
454                adjacentVertices[1]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
455            }
456            else if(findpos(actuelposition,possibleposition[6])){
457                adjacentVertices[0]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
458                adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
459                adjacentVertices[2]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
460            }
461            else if(findpos(actuelposition,possibleposition[7])){
462                adjacentVertices[0]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
463                adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
464            }
465            else if(findpos(actuelposition,possibleposition[8])){
466                adjacentVertices[0]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
467                adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
468            }
469            else if(findpos(actuelposition,possibleposition[9])){
470                adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
471                adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
472                adjacentVertices[2]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
473                adjacentVertices[3]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
474            }
475            else if(findpos(actuelposition,possibleposition[10])){
476                adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
477                adjacentVertices[1]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
478                adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
479            }
480            else if(findpos(actuelposition,possibleposition[11])){
481                adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
482                adjacentVertices[1]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
483                adjacentVertices[2]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
484            }
485            else if(findpos(actuelposition,possibleposition[12])){
486                adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
487                adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
488            }
489            else if(findpos(actuelposition,possibleposition[13])){
490                adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
491                adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
492                adjacentVertices[2]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
493                adjacentVertices[3]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
494            }
495            else if(findpos(actuelposition,possibleposition[14])){
496                adjacentVertices[0]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
497                adjacentVertices[1]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
498                adjacentVertices[2]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
499            }
500            else if(findpos(actuelposition,possibleposition[15])){
501                adjacentVertices[0]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
502                adjacentVertices[1]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
503            }
504            else if(findpos(actuelposition,possibleposition[16])){
505                adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
506                adjacentVertices[1]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
507                adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
508            }
509            else if(findpos(actuelposition,possibleposition[17])){
510                adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
511                adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
512            }
513            else if(findpos(actuelposition,possibleposition[18])){
514                adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
515                adjacentVertices[1]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);               
516            }
517            else if(findpos(actuelposition,possibleposition[19])){
518                adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
519                adjacentVertices[1]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
520                adjacentVertices[2]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
521                         }
522            else if(findpos(actuelposition,possibleposition[20])){
523                adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
524                adjacentVertices[1]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
525                       }
526            else if(findpos(actuelposition,possibleposition[21])){
527                adjacentVertices[0]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
528                adjacentVertices[1]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
529                       }
530            else if(findpos(actuelposition,possibleposition[22])){
531                adjacentVertices[0]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
532                adjacentVertices[1]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
533                adjacentVertices[2]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
534                          }
535            else if(findpos(actuelposition,possibleposition[23])){
536                adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
537                adjacentVertices[1]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
538                       }
539            else if(findpos(actuelposition,possibleposition[24])){
540                adjacentVertices[0]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
541                adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
542                       }
543            else if(findpos(actuelposition,possibleposition[25])){
544                adjacentVertices[0]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
545                adjacentVertices[1]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
546                       }
547            else if(findpos(actuelposition,possibleposition[26])){
548                adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
549                adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
550                adjacentVertices[2]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
551                         }
552            else if(findpos(actuelposition,possibleposition[27])){
553                adjacentVertices[0]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
554                adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
555                adjacentVertices[2]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
556                          }
557            else if(findpos(actuelposition,possibleposition[28])){
558                adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
559                adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
560                adjacentVertices[2]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
561                          }
562            else if(findpos(actuelposition,possibleposition[29])){
563                adjacentVertices[0]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);
564                adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
565                adjacentVertices[2]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
566                          }
567            else if(findpos(actuelposition,possibleposition[30])){
568                adjacentVertices[0]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
569                adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
570                adjacentVertices[2]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
571                          }
572            else if(findpos(actuelposition,possibleposition[31])){
573                adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
574                adjacentVertices[1]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
575                       }
576            else if(findpos(actuelposition,possibleposition[32])){
577                adjacentVertices[0]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
578                adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
579                       }
580            else if(findpos(actuelposition,possibleposition[33])){
581                adjacentVertices[0]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
582                adjacentVertices[1]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
583                       }
584            else if(findpos(actuelposition,possibleposition[34])){
585                adjacentVertices[0]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
586                adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
587                adjacentVertices[2]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
588                adjacentVertices[3]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
589               
590            }
591            else if(findpos(actuelposition,possibleposition[35])){
592                adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
593                adjacentVertices[1]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
594                adjacentVertices[2]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
595                          }
596            else if(findpos(actuelposition,possibleposition[36])){
597                adjacentVertices[0]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
598                adjacentVertices[1]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
599                       }
600            else if(findpos(actuelposition,possibleposition[37])){
601                adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
602                adjacentVertices[1]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
603                       }
604            else if(findpos(actuelposition,possibleposition[38])){
605                adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
606                adjacentVertices[1]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
607                adjacentVertices[2]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
608                         }
609            else if(findpos(actuelposition,possibleposition[39])){
610                adjacentVertices[0]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
611                adjacentVertices[1]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
612                adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
613                          }
614            else if(findpos(actuelposition,possibleposition[40])){
615                adjacentVertices[0]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
616                adjacentVertices[1]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
617            }
618            else if(findpos(actuelposition,possibleposition[41])){
619                adjacentVertices[0]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
620                adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
621                adjacentVertices[2]=&listOfVerticesP2[40]; //error meuh
622                       }
623            else if(findpos(actuelposition,possibleposition[42])){
624                adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
625                adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
626                adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
627                          }
628            else if(findpos(actuelposition,possibleposition[43])){
629                adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
630                adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
631                adjacentVertices[2]=&listOfVerticesP2[42]; //error meuh
632                       }
633            else if(findpos(actuelposition,possibleposition[44])){
634                adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
635                adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
636                       }
637            else if(findpos(actuelposition,possibleposition[45])){
638                adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
639                adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
640                adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
641                          }
642            else if(findpos(actuelposition,possibleposition[46])){
643                adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
644                adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
645                       }
646            else if(findpos(actuelposition,possibleposition[47])){
647                adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
648                adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
649                adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
650                          }
651            else if(findpos(actuelposition,possibleposition[48])){
652                adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
653                adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
654                adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
655                          }
656            else if(findpos(actuelposition,possibleposition[49])){
657                adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
658                adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
659                       }
660            else if(findpos(actuelposition,possibleposition[50])){
661                adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
662                adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
663                       }
664            else if(findpos(actuelposition,possibleposition[51])){
665                adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
666                adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
667                       }
668            else if(findpos(actuelposition,possibleposition[52])){
669                adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
670                adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
671                       }
672            else if(findpos(actuelposition,possibleposition[53])){
673                adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
674                adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
675                       }
676            else if(findpos(actuelposition,possibleposition[54])){
677                adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
678                adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
679                adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
680                          }
681            else if(findpos(actuelposition,possibleposition[55])){
682                adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
683                adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
684                       }
685            else if(findpos(actuelposition,possibleposition[56])){
686                adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
687                adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
688                adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
689                          }
690            else if(findpos(actuelposition,possibleposition[57])){
691                adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
692                adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
693                adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
694                adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
695               
696            }
697            else if(findpos(actuelposition,possibleposition[58])){
698                adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
699                adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
700                adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
701                          }
702            else if(findpos(actuelposition,possibleposition[59])){
703                adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
704                adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[59]);
705                adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
706                          }
707            else if(findpos(actuelposition,possibleposition[60])){
708                adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
709                adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
710                adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
711                          }
712            else if(findpos(actuelposition,possibleposition[61])){
713                adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
714                adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
715                adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
716                          }
717            else if(findpos(actuelposition,possibleposition[62])){
718                adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
719                adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
720                       }
721            else if(findpos(actuelposition,possibleposition[63])){
722                adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
723                adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
724                       }
725            else if(findpos(actuelposition,possibleposition[64])){
726                adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
727                adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
728                adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
729                          }
730            else if(findpos(actuelposition,possibleposition[65])){
731                adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
732                adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
733                       }
734            else if(findpos(actuelposition,possibleposition[66])){
735                adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
736                adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
737                       }
738    }
739
740    //functions taken from PacmanPink
741
742
743    Vector3 PacmanGhost::diffVector (Vector3 start, Vector3 goal){
744
745        Vector3 result;
746        result.x=goal.x-start.x;
747        result.z=goal.z-start.z;
748        return result;
749    }
750
751
752    bool PacmanGhost::playerFindPos(Vector3 one, Vector3 other){
753       if((abs(one.x - other.x)<15) && (abs(one.z - other.z)<15)) return true;
754        return false;
755        }
756
757
758
759
760    int PacmanGhost::findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
761        //return 0 for south, 1 for west, 2 for north, 3 for east
762
763
764        if(playerFindPos(playerPosBefore, playerPos)){
765            //if player is still near last crossed point
766
767            return 4; //return the last crossed point for simplicity
768        }
769
770
771        if(abs(playerPos.x-playerPosBefore.x)<14){ //player is moving vertically
772            if((playerPos.z-playerPosBefore.z)<0){//move west
773                return 0;
774            }
775            if((playerPos.z-playerPosBefore.z)>0){//move east
776                return 2;
777            }
778        }
779
780        if(abs(playerPos.z-playerPosBefore.z)<14){ //player is moving horizontally
781            if((playerPos.x-playerPosBefore.x)<0){//move south
782                return 1;
783            }
784            if((playerPos.x-playerPosBefore.x)>0){//move north
785                return 3;
786            }
787        }
788       
789        }
790
791    Vector3 PacmanGhost::getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){
792        //return the Vector3 point that Pinky should target to
793        //be in front of pacman
794
795        if(indexForSWNE==4){
796            //std::cout<<"Ryukyu"<<endl;
797            return pacLasVisPos;
798        }
799
800        Vector3 listOfNeighboors[4];
801        //first element is south, 2nd west, 3d north, 4th east
802
803            if(findpos(pacLasVisPos,possibleposition[0])){
804                //no south neighbor
805                listOfNeighboors[1]=possibleposition[19]; // west neighbor
806                listOfNeighboors[2]=possibleposition[17]; //north
807                listOfNeighboors[3]=possibleposition[1]; //east
808                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
809            }
810            else if(findpos(pacLasVisPos,possibleposition[1])){
811                listOfNeighboors[1]=possibleposition[0]; // west neighbor
812                listOfNeighboors[2]=possibleposition[2]; //north
813                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
814            }
815            else if(findpos(pacLasVisPos,possibleposition[2])){
816                listOfNeighboors[0]=possibleposition[1];  //south
817                listOfNeighboors[1]=possibleposition[3]; //west
818                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
819            }
820            else if(findpos(pacLasVisPos,possibleposition[3])){
821                listOfNeighboors[1]=possibleposition[4]; //west
822                listOfNeighboors[2]=possibleposition[5]; //north
823                listOfNeighboors[3]=possibleposition[2]; //east
824                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
825            }
826            else if(findpos(pacLasVisPos,possibleposition[4])){
827                listOfNeighboors[2]=possibleposition[6]; //north
828                listOfNeighboors[3]=possibleposition[3]; //east
829                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
830            }
831            else if(findpos(pacLasVisPos,possibleposition[5])){
832                listOfNeighboors[0]=possibleposition[3]; //south
833                listOfNeighboors[3]=possibleposition[7]; //east
834                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
835            }
836            else if(findpos(pacLasVisPos,possibleposition[6])){
837                listOfNeighboors[0]=possibleposition[4]; //south
838                listOfNeighboors[1]=possibleposition[26]; //west
839                listOfNeighboors[2]=possibleposition[9]; //north
840                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
841            }
842            else if(findpos(pacLasVisPos,possibleposition[7])){
843                listOfNeighboors[1]=possibleposition[5]; //west
844                listOfNeighboors[2]=possibleposition[8]; //north
845                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
846            }
847            else if(findpos(pacLasVisPos,possibleposition[8])){
848                listOfNeighboors[0]=possibleposition[7]; //south
849                listOfNeighboors[1]=possibleposition[9]; //west
850                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
851            }
852            else if(findpos(pacLasVisPos,possibleposition[9])){
853                listOfNeighboors[0]=possibleposition[6]; //south
854                listOfNeighboors[1]=possibleposition[38]; //west
855                listOfNeighboors[2]=possibleposition[10]; //north
856                listOfNeighboors[3]=possibleposition[8]; //east
857                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
858            }
859            else if(findpos(pacLasVisPos,possibleposition[10])){
860
861                if(indexForSWNE==3){ //nothing eastward
862                    return pacLasVisPos;
863                }
864
865                listOfNeighboors[0]=possibleposition[9]; //south
866                listOfNeighboors[1]=possibleposition[45]; //west
867                listOfNeighboors[2]=possibleposition[11]; //north
868                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
869            }
870            else if(findpos(pacLasVisPos,possibleposition[11])){
871                listOfNeighboors[0]=possibleposition[10]; //south
872                listOfNeighboors[2]=possibleposition[13]; //north
873                listOfNeighboors[3]=possibleposition[12]; //east
874                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
875            }
876            else if(findpos(pacLasVisPos,possibleposition[12])){
877                listOfNeighboors[1]=possibleposition[11]; //west
878                listOfNeighboors[2]=possibleposition[14]; //north
879                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
880            }
881            else if(findpos(pacLasVisPos,possibleposition[13])){
882                listOfNeighboors[0]=possibleposition[11]; //south
883                listOfNeighboors[1]=possibleposition[61]; //west
884                listOfNeighboors[2]=possibleposition[16]; //north
885                listOfNeighboors[3]=possibleposition[14]; //east
886                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
887            }
888            else if(findpos(pacLasVisPos,possibleposition[14])){
889                listOfNeighboors[0]=possibleposition[12]; //south
890                listOfNeighboors[1]=possibleposition[13]; //west
891                listOfNeighboors[2]=possibleposition[15]; //north
892                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
893            }
894            else if(findpos(pacLasVisPos,possibleposition[15])){
895                listOfNeighboors[0]=possibleposition[14]; //south
896                listOfNeighboors[1]=possibleposition[16]; //west
897                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
898            }
899            else if(findpos(pacLasVisPos,possibleposition[16])){
900                listOfNeighboors[0]=possibleposition[13]; //south
901                listOfNeighboors[1]=possibleposition[62]; //west
902                listOfNeighboors[2]=possibleposition[15]; //north
903                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
904            }
905            else if(findpos(pacLasVisPos,possibleposition[17])){
906                listOfNeighboors[0]=possibleposition[0]; //south
907                listOfNeighboors[3]=possibleposition[25]; //east
908                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
909            }
910            else if(findpos(pacLasVisPos,possibleposition[18])){
911                listOfNeighboors[0]=possibleposition[19]; //south
912                listOfNeighboors[1]=possibleposition[24]; //west
913                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
914            }
915            else if(findpos(pacLasVisPos,possibleposition[19])){
916                listOfNeighboors[1]=possibleposition[20]; //west
917                listOfNeighboors[2]=possibleposition[18]; //north
918                listOfNeighboors[3]=possibleposition[0]; //east
919                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
920            }
921            else if(findpos(pacLasVisPos,possibleposition[20])){
922                listOfNeighboors[2]=possibleposition[21]; //north
923                listOfNeighboors[3]=possibleposition[19]; //east
924                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
925            }
926            else if(findpos(pacLasVisPos,possibleposition[21])){
927                listOfNeighboors[0]=possibleposition[20]; //south
928                listOfNeighboors[3]=possibleposition[22]; //east
929                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
930            }
931            else if(findpos(pacLasVisPos,possibleposition[22])){
932                listOfNeighboors[1]=possibleposition[21]; //west
933                listOfNeighboors[2]=possibleposition[31]; //north
934                listOfNeighboors[3]=possibleposition[23]; //east
935                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
936            }
937            else if(findpos(pacLasVisPos,possibleposition[23])){
938                listOfNeighboors[1]=possibleposition[22]; //west
939                listOfNeighboors[2]=possibleposition[30]; //north
940                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
941            }
942            else if(findpos(pacLasVisPos,possibleposition[24])){
943                listOfNeighboors[2]=possibleposition[29]; //north
944                listOfNeighboors[3]=possibleposition[18]; //east
945                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
946            }
947            else if(findpos(pacLasVisPos,possibleposition[25])){
948                listOfNeighboors[1]=possibleposition[17]; //west
949                listOfNeighboors[2]=possibleposition[26]; //north
950                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
951            }
952            else if(findpos(pacLasVisPos,possibleposition[26])){
953                listOfNeighboors[0]=possibleposition[25]; //south
954                listOfNeighboors[1]=possibleposition[27]; //west
955                listOfNeighboors[3]=possibleposition[6]; //east
956                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
957            }
958            else if(findpos(pacLasVisPos,possibleposition[27])){
959                listOfNeighboors[1]=possibleposition[28]; //west
960                listOfNeighboors[2]=possibleposition[37]; //north
961                listOfNeighboors[3]=possibleposition[26]; //east
962                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
963            }
964            else if(findpos(pacLasVisPos,possibleposition[28])){
965                listOfNeighboors[1]=possibleposition[29]; //west
966                listOfNeighboors[2]=possibleposition[36]; //north
967                listOfNeighboors[3]=possibleposition[27]; //east
968                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
969            }
970            else if(findpos(pacLasVisPos,possibleposition[29])){
971                listOfNeighboors[0]=possibleposition[24]; //south
972                listOfNeighboors[1]=possibleposition[30]; //west
973                listOfNeighboors[3]=possibleposition[28]; //east
974                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
975            }
976            else if(findpos(pacLasVisPos,possibleposition[30])){
977                listOfNeighboors[0]=possibleposition[23]; //south
978                listOfNeighboors[2]=possibleposition[34]; //north
979                listOfNeighboors[3]=possibleposition[29]; //east
980                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
981            }
982            else if(findpos(pacLasVisPos,possibleposition[31])){
983                listOfNeighboors[0]=possibleposition[22]; //south
984                listOfNeighboors[1]=possibleposition[32]; //west
985                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
986            }
987            else if(findpos(pacLasVisPos,possibleposition[32])){
988                listOfNeighboors[2]=possibleposition[33]; //north
989                listOfNeighboors[3]=possibleposition[31]; //east
990                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
991            }
992            else if(findpos(pacLasVisPos,possibleposition[33])){
993                listOfNeighboors[0]=possibleposition[32]; //south
994                listOfNeighboors[3]=possibleposition[34]; //east
995                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
996            }
997            else if(findpos(pacLasVisPos,possibleposition[34])){
998                listOfNeighboors[0]=possibleposition[30]; //south
999                listOfNeighboors[1]=possibleposition[33]; //west
1000                listOfNeighboors[2]=possibleposition[92]; //north
1001                listOfNeighboors[3]=possibleposition[35]; //east
1002                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1003            }
1004            else if(findpos(pacLasVisPos,possibleposition[35])){
1005                listOfNeighboors[1]=possibleposition[34]; //west
1006                listOfNeighboors[2]=possibleposition[91]; //north
1007                listOfNeighboors[3]=possibleposition[36]; //east
1008                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1009            }
1010            else if(findpos(pacLasVisPos,possibleposition[36])){
1011                listOfNeighboors[0]=possibleposition[28]; //south
1012                listOfNeighboors[1]=possibleposition[35]; //west
1013                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1014            }
1015            else if(findpos(pacLasVisPos,possibleposition[37])){
1016                listOfNeighboors[0]=possibleposition[27]; //south
1017                listOfNeighboors[3]=possibleposition[38]; //east
1018                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1019            }
1020            else if(findpos(pacLasVisPos,possibleposition[38])){
1021                listOfNeighboors[1]=possibleposition[37]; //west
1022                listOfNeighboors[2]=possibleposition[39]; //north
1023                listOfNeighboors[3]=possibleposition[9]; //east
1024                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1025            }
1026            else if(findpos(pacLasVisPos,possibleposition[39])){
1027                listOfNeighboors[0]=possibleposition[38]; //south
1028                listOfNeighboors[1]=possibleposition[40]; //west
1029                listOfNeighboors[2]=possibleposition[45]; //north
1030                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1031            }
1032            else if(findpos(pacLasVisPos,possibleposition[40])){
1033                listOfNeighboors[1]=possibleposition[41]; //west
1034                //Not return in center
1035                listOfNeighboors[3]=possibleposition[39]; //east
1036                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1037            }
1038            else if(findpos(pacLasVisPos,possibleposition[41])){
1039                listOfNeighboors[0]=possibleposition[35]; //south
1040                listOfNeighboors[2]=possibleposition[43]; //north
1041                listOfNeighboors[3]=possibleposition[40]; //east
1042                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1043            }
1044            else if(findpos(pacLasVisPos,possibleposition[42])){
1045
1046                if(indexForSWNE==1){//nothing westward
1047                    return pacLasVisPos;
1048                }
1049
1050                listOfNeighboors[0]=possibleposition[39]; //south
1051                listOfNeighboors[2]=possibleposition[59]; //north
1052                listOfNeighboors[3]=possibleposition[43]; //east
1053                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1054            }
1055            else if(findpos(pacLasVisPos,possibleposition[43])){
1056                listOfNeighboors[0]=possibleposition[41]; //south
1057                listOfNeighboors[1]=possibleposition[42]; //west
1058                listOfNeighboors[2]=possibleposition[46]; //north
1059                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1060            }
1061            else if(findpos(pacLasVisPos,possibleposition[44])){
1062                listOfNeighboors[0]=possibleposition[40]; //south
1063                listOfNeighboors[2]=possibleposition[66]; //north
1064                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1065            }
1066            else if(findpos(pacLasVisPos,possibleposition[45])){
1067                listOfNeighboors[0]=possibleposition[39]; //south
1068                listOfNeighboors[2]=possibleposition[49]; //north
1069                listOfNeighboors[3]=possibleposition[10]; //east
1070                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1071            }
1072            else if(findpos(pacLasVisPos,possibleposition[46])){
1073                listOfNeighboors[0]=possibleposition[43]; //south
1074                listOfNeighboors[3]=possibleposition[47]; //east
1075                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1076            }
1077            else if(findpos(pacLasVisPos,possibleposition[47])){
1078                listOfNeighboors[1]=possibleposition[46]; //west
1079                listOfNeighboors[2]=possibleposition[52]; //north
1080                listOfNeighboors[3]=possibleposition[66]; //east
1081                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1082            }
1083            else if(findpos(pacLasVisPos,possibleposition[48])){
1084                listOfNeighboors[1]=possibleposition[66]; //west
1085                listOfNeighboors[2]=possibleposition[51]; //north
1086                listOfNeighboors[3]=possibleposition[49]; //east
1087                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1088            }
1089            else if(findpos(pacLasVisPos,possibleposition[49])){
1090                listOfNeighboors[0]=possibleposition[45]; //south
1091                listOfNeighboors[1]=possibleposition[48]; //west
1092                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1093            }
1094            else if(findpos(pacLasVisPos,possibleposition[50])){
1095                listOfNeighboors[1]=possibleposition[51]; //west
1096                listOfNeighboors[2]=possibleposition[61]; //north
1097                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1098            }
1099            else if(findpos(pacLasVisPos,possibleposition[51])){
1100                listOfNeighboors[0]=possibleposition[48]; //south
1101                listOfNeighboors[3]=possibleposition[50]; //east
1102                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1103            }
1104            else if(findpos(pacLasVisPos,possibleposition[52])){
1105                listOfNeighboors[0]=possibleposition[47]; //south
1106                listOfNeighboors[1]=possibleposition[53]; //west
1107                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1108            }
1109            else if(findpos(pacLasVisPos,possibleposition[53])){
1110                listOfNeighboors[2]=possibleposition[58]; //north
1111                listOfNeighboors[3]=possibleposition[52]; //east
1112                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1113            }
1114            else if(findpos(pacLasVisPos,possibleposition[54])){
1115                listOfNeighboors[0]=possibleposition[42]; //south
1116                listOfNeighboors[1]=possibleposition[55]; //west
1117                listOfNeighboors[2]=possibleposition[57]; //north
1118                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1119            }
1120            else if(findpos(pacLasVisPos,possibleposition[55])){
1121                listOfNeighboors[2]=possibleposition[56]; //north
1122                listOfNeighboors[3]=possibleposition[54]; //east
1123                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1124            }
1125            else if(findpos(pacLasVisPos,possibleposition[56])){
1126                listOfNeighboors[0]=possibleposition[55]; //south
1127                listOfNeighboors[2]=possibleposition[65]; //north
1128                listOfNeighboors[3]=possibleposition[57]; //east
1129                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1130            }
1131            else if(findpos(pacLasVisPos,possibleposition[57])){
1132                listOfNeighboors[0]=possibleposition[54]; //south
1133                listOfNeighboors[1]=possibleposition[56]; //west
1134                listOfNeighboors[2]=possibleposition[64]; //north
1135                listOfNeighboors[3]=possibleposition[58]; //east
1136                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1137            }
1138            else if(findpos(pacLasVisPos,possibleposition[58])){
1139                listOfNeighboors[0]=possibleposition[53]; //south
1140                listOfNeighboors[1]=possibleposition[57]; //west
1141                listOfNeighboors[3]=possibleposition[59]; //east
1142                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1143            }
1144            else if(findpos(pacLasVisPos,possibleposition[59])){
1145                listOfNeighboors[1]=possibleposition[58]; //west
1146                listOfNeighboors[2]=possibleposition[63]; //north
1147                listOfNeighboors[3]=possibleposition[60]; //east
1148                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1149            }
1150            else if(findpos(pacLasVisPos,possibleposition[60])){
1151                listOfNeighboors[1]=possibleposition[59]; //west
1152                listOfNeighboors[2]=possibleposition[62]; //north
1153                listOfNeighboors[3]=possibleposition[61]; //east
1154                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1155            }
1156            else if(findpos(pacLasVisPos,possibleposition[61])){
1157                listOfNeighboors[0]=possibleposition[50]; //south
1158                listOfNeighboors[1]=possibleposition[60]; //west
1159                listOfNeighboors[3]=possibleposition[13]; //east
1160                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1161            }
1162            else if(findpos(pacLasVisPos,possibleposition[62])){
1163                listOfNeighboors[0]=possibleposition[60]; //south
1164                listOfNeighboors[3]=possibleposition[16]; //east
1165                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1166            }
1167            else if(findpos(pacLasVisPos,possibleposition[63])){
1168                listOfNeighboors[0]=possibleposition[59]; //south
1169                listOfNeighboors[1]=possibleposition[64]; //west
1170                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1171            }
1172            else if(findpos(pacLasVisPos,possibleposition[64])){
1173                listOfNeighboors[0]=possibleposition[57]; //south
1174                listOfNeighboors[1]=possibleposition[65]; //west
1175                listOfNeighboors[3]=possibleposition[63]; //east
1176                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1177            }
1178            else if(findpos(pacLasVisPos,possibleposition[65])){
1179                listOfNeighboors[0]=possibleposition[56]; //south
1180                listOfNeighboors[3]=possibleposition[64]; //east
1181                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);
1182            }
1183            else if(findpos(pacLasVisPos,possibleposition[66])){
1184                //Not back in center
1185                listOfNeighboors[1]=possibleposition[47]; //west
1186                listOfNeighboors[3]=possibleposition[48]; //east
1187                return listOfNeighboors[indexForSWNE]; //Vector3(listOfNeighboors[indexForSWNE].x, 10, listOfNeighboors[indexForSWNE].z);           
1188            }
1189
1190        }
1191
1192
1193
1194
1195///////////////////////
1196
1197
1198
1199
1200
1201    Vector3 PacmanGhost::frontPosition(){
1202
1203    Vector3 neighborPos[4] = {Vector3(-1,-1,-1)};
1204    Vector3 frontPoint = Vector3(0,-1,0);
1205
1206
1207    findNeighboorPositions(this->lastPlayerPassedPoint, neighborPos, possibleposition);
1208
1209    for(int i=0; i<4; i++){
1210
1211     if((neighborPos[i]!=Vector3(-1,-1,-1))&&(neighborPos[i].y==10)){
1212     //y==10 to ignore many unwanted strange positions that pop up otherwise and create SIGSEV
1213       
1214        if(frontPoint==Vector3(0,-1,0)){
1215            frontPoint=neighborPos[i];
1216
1217                        }
1218        else if (graphDistance(this->getPlayerPos(), frontPoint)>graphDistance(this->getPlayerPos(), neighborPos[i])){
1219            frontPoint=neighborPos[i];
1220                        }
1221
1222                    }
1223                }
1224
1225    if(frontPoint==Vector3(0,-1,0)){
1226        //default
1227        return this->lastPlayerPassedPoint;
1228            }
1229    else{
1230        //std::cout<<frontPoint<<endl;
1231        return frontPoint;
1232            }
1233    }
1234
1235
1236
1237
1238
1239
1240    void PacmanGhost::findNeighboorPositions(Vector3 actuelposition, Vector3 adjacentPositions[], Vector3 positionArray[]){     
1241            //this function should put in adjacentPosition[] the neighboors of lastPlayerPastPoint
1242
1243            if(findpos(actuelposition,possibleposition[0])){
1244               
1245
1246                adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]);  //need to do it everywhere !!!
1247                adjacentPositions[1]=positionArray[17]; //graphVertex(possibleposition[17]);
1248                adjacentPositions[2]=positionArray[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ?
1249            }
1250            else if(findpos(actuelposition,possibleposition[1])){
1251                adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]);
1252                adjacentPositions[1]=positionArray[2]; //graphVertex(possibleposition[2]);
1253            }
1254            else if(findpos(actuelposition,possibleposition[2])){
1255                adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]);
1256                adjacentPositions[1]=positionArray[3]; //graphVertex(possibleposition[3]);
1257            }
1258            else if(findpos(actuelposition,possibleposition[3])){
1259                adjacentPositions[0]=positionArray[2]; //graphVertex(possibleposition[2]);
1260                adjacentPositions[1]=positionArray[4]; //graphVertex(possibleposition[4]);
1261                adjacentPositions[2]=positionArray[5]; //graphVertex(possibleposition[5]);
1262            }
1263            else if(findpos(actuelposition,possibleposition[4])){
1264                adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]);
1265                adjacentPositions[1]=positionArray[6]; //graphVertex(possibleposition[6]);
1266            }
1267            else if(findpos(actuelposition,possibleposition[5])){
1268                adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]);
1269                adjacentPositions[1]=positionArray[7]; //graphVertex(possibleposition[7]);
1270            }
1271            else if(findpos(actuelposition,possibleposition[6])){
1272                adjacentPositions[0]=positionArray[4]; //graphVertex(possibleposition[4]);
1273                adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]);
1274                adjacentPositions[2]=positionArray[26]; //graphVertex(possibleposition[26]);
1275            }
1276            else if(findpos(actuelposition,possibleposition[7])){
1277                adjacentPositions[0]=positionArray[5]; //graphVertex(possibleposition[5]);
1278                adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]);
1279            }
1280            else if(findpos(actuelposition,possibleposition[8])){
1281                adjacentPositions[0]=positionArray[7]; //graphVertex(possibleposition[7]);
1282                adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]);
1283            }
1284            else if(findpos(actuelposition,possibleposition[9])){
1285                adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]);
1286                adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]);
1287                adjacentPositions[2]=positionArray[10]; //graphVertex(possibleposition[10]);
1288                adjacentPositions[3]=positionArray[38]; //graphVertex(possibleposition[38]);
1289            }
1290            else if(findpos(actuelposition,possibleposition[10])){
1291                adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]);
1292                adjacentPositions[1]=positionArray[11]; //graphVertex(possibleposition[11]);
1293                adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]);
1294            }
1295            else if(findpos(actuelposition,possibleposition[11])){
1296                adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]);
1297                adjacentPositions[1]=positionArray[12]; //graphVertex(possibleposition[12]);
1298                adjacentPositions[2]=positionArray[13]; //graphVertex(possibleposition[13]);
1299            }
1300            else if(findpos(actuelposition,possibleposition[12])){
1301                adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]);
1302                adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]);
1303            }
1304            else if(findpos(actuelposition,possibleposition[13])){
1305                adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]);
1306                adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]);
1307                adjacentPositions[2]=positionArray[16]; //graphVertex(possibleposition[16]);
1308                adjacentPositions[3]=positionArray[61]; //graphVertex(possibleposition[61]);
1309            }
1310            else if(findpos(actuelposition,possibleposition[14])){
1311                adjacentPositions[0]=positionArray[12]; //graphVertex(possibleposition[12]);
1312                adjacentPositions[1]=positionArray[13]; //graphVertex(possibleposition[13]);
1313                adjacentPositions[2]=positionArray[15]; //graphVertex(possibleposition[15]);
1314            }
1315            else if(findpos(actuelposition,possibleposition[15])){
1316                adjacentPositions[0]=positionArray[14]; //graphVertex(possibleposition[14]);
1317                adjacentPositions[1]=positionArray[16]; //graphVertex(possibleposition[16]);
1318            }
1319            else if(findpos(actuelposition,possibleposition[16])){
1320                adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]);
1321                adjacentPositions[1]=positionArray[15]; //graphVertex(possibleposition[15]);
1322                adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]);
1323            }
1324            else if(findpos(actuelposition,possibleposition[17])){
1325                adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]);
1326                adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]);
1327            }
1328            else if(findpos(actuelposition,possibleposition[18])){
1329                adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]);
1330                adjacentPositions[1]=positionArray[24]; //graphVertex(possibleposition[24]);               
1331            }
1332            else if(findpos(actuelposition,possibleposition[19])){
1333                adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]);
1334                adjacentPositions[1]=positionArray[18]; //graphVertex(possibleposition[18]);
1335                adjacentPositions[2]=positionArray[20]; //graphVertex(possibleposition[20]);
1336                         }
1337            else if(findpos(actuelposition,possibleposition[20])){
1338                adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]);
1339                adjacentPositions[1]=positionArray[21]; //graphVertex(possibleposition[21]);
1340                       }
1341            else if(findpos(actuelposition,possibleposition[21])){
1342                adjacentPositions[0]=positionArray[20]; //graphVertex(possibleposition[20]);
1343                adjacentPositions[1]=positionArray[22]; //graphVertex(possibleposition[22]);
1344                       }
1345            else if(findpos(actuelposition,possibleposition[22])){
1346                adjacentPositions[0]=positionArray[21]; //graphVertex(possibleposition[21]);
1347                adjacentPositions[1]=positionArray[23]; //graphVertex(possibleposition[23]);
1348                adjacentPositions[2]=positionArray[31]; //graphVertex(possibleposition[31]);
1349                          }
1350            else if(findpos(actuelposition,possibleposition[23])){
1351                adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]);
1352                adjacentPositions[1]=positionArray[30]; //graphVertex(possibleposition[30]);
1353                       }
1354            else if(findpos(actuelposition,possibleposition[24])){
1355                adjacentPositions[0]=positionArray[18]; //graphVertex(possibleposition[18]);
1356                adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]);
1357                       }
1358            else if(findpos(actuelposition,possibleposition[25])){
1359                adjacentPositions[0]=positionArray[17]; //graphVertex(possibleposition[17]);
1360                adjacentPositions[1]=positionArray[26]; //graphVertex(possibleposition[26]);
1361                       }
1362            else if(findpos(actuelposition,possibleposition[26])){
1363                adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]);
1364                adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]);
1365                adjacentPositions[2]=positionArray[27]; //graphVertex(possibleposition[27]);
1366                         }
1367            else if(findpos(actuelposition,possibleposition[27])){
1368                adjacentPositions[0]=positionArray[26]; //graphVertex(possibleposition[26]);
1369                adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]);
1370                adjacentPositions[2]=positionArray[37]; //graphVertex(possibleposition[37]);
1371                          }
1372            else if(findpos(actuelposition,possibleposition[28])){
1373                adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]);
1374                adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]);
1375                adjacentPositions[2]=positionArray[36]; //graphVertex(possibleposition[36]);
1376                          }
1377            else if(findpos(actuelposition,possibleposition[29])){
1378                adjacentPositions[0]=positionArray[24]; //graphVertex(possibleposition[24]);
1379                adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]);
1380                adjacentPositions[2]=positionArray[30]; //graphVertex(possibleposition[30]);
1381                          }
1382            else if(findpos(actuelposition,possibleposition[30])){
1383                adjacentPositions[0]=positionArray[23]; //graphVertex(possibleposition[23]);
1384                adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]);
1385                adjacentPositions[2]=positionArray[34]; //graphVertex(possibleposition[34]);
1386                          }
1387            else if(findpos(actuelposition,possibleposition[31])){
1388                adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]);
1389                adjacentPositions[1]=positionArray[32]; //graphVertex(possibleposition[32]);
1390                       }
1391            else if(findpos(actuelposition,possibleposition[32])){
1392                adjacentPositions[0]=positionArray[31]; //graphVertex(possibleposition[31]);
1393                adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]);
1394                       }
1395            else if(findpos(actuelposition,possibleposition[33])){
1396                adjacentPositions[0]=positionArray[32]; //graphVertex(possibleposition[32]);
1397                adjacentPositions[1]=positionArray[34]; //graphVertex(possibleposition[34]);
1398                       }
1399            else if(findpos(actuelposition,possibleposition[34])){
1400                adjacentPositions[0]=positionArray[30]; //graphVertex(possibleposition[30]);
1401                adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]);
1402                adjacentPositions[2]=positionArray[35]; //graphVertex(possibleposition[35]);
1403                adjacentPositions[3]=positionArray[42]; //graphVertex(possibleposition[42]);
1404               
1405            }
1406            else if(findpos(actuelposition,possibleposition[35])){
1407                adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]);
1408                adjacentPositions[1]=positionArray[36]; //graphVertex(possibleposition[36]);
1409                adjacentPositions[2]=positionArray[41]; //graphVertex(possibleposition[41]);
1410                          }
1411            else if(findpos(actuelposition,possibleposition[36])){
1412                adjacentPositions[0]=positionArray[28]; //graphVertex(possibleposition[28]);
1413                adjacentPositions[1]=positionArray[35]; //graphVertex(possibleposition[35]);
1414                       }
1415            else if(findpos(actuelposition,possibleposition[37])){
1416                adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]);
1417                adjacentPositions[1]=positionArray[38]; //graphVertex(possibleposition[38]);
1418                       }
1419            else if(findpos(actuelposition,possibleposition[38])){
1420                adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]);
1421                adjacentPositions[1]=positionArray[37]; //graphVertex(possibleposition[37]);
1422                adjacentPositions[2]=positionArray[39]; //graphVertex(possibleposition[39]);
1423                         }
1424            else if(findpos(actuelposition,possibleposition[39])){
1425                adjacentPositions[0]=positionArray[38]; //graphVertex(possibleposition[38]);
1426                adjacentPositions[1]=positionArray[40]; //graphVertex(possibleposition[40]);
1427                adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]);
1428                          }
1429            else if(findpos(actuelposition,possibleposition[40])){
1430                adjacentPositions[0]=positionArray[39]; //graphVertex(possibleposition[39]);
1431                adjacentPositions[1]=positionArray[41]; //graphVertex(possibleposition[41]);
1432            }
1433            else if(findpos(actuelposition,possibleposition[41])){
1434                adjacentPositions[0]=positionArray[35]; //graphVertex(possibleposition[35]);
1435                adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]);
1436                adjacentPositions[2]=positionArray[40];  //error
1437                       }
1438            else if(findpos(actuelposition,possibleposition[42])){
1439                adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]);
1440                adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]);
1441                adjacentPositions[2]=positionArray[54]; //graphVertex(possibleposition[54]);
1442                          }
1443            else if(findpos(actuelposition,possibleposition[43])){
1444                adjacentPositions[0]=positionArray[41]; //graphVertex(possibleposition[41]);
1445                adjacentPositions[1]=positionArray[46]; //graphVertex(possibleposition[46]);
1446                adjacentPositions[2]=positionArray[42]; //error
1447                       }
1448            else if(findpos(actuelposition,possibleposition[44])){
1449                adjacentPositions[0]=positionArray[40]; //graphVertex(possibleposition[40]);
1450                adjacentPositions[1]=positionArray[66]; //graphVertex(possibleposition[66]);
1451                       }
1452            else if(findpos(actuelposition,possibleposition[45])){
1453                adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]);
1454                adjacentPositions[1]=positionArray[39]; //graphVertex(possibleposition[39]);
1455                adjacentPositions[2]=positionArray[49]; //graphVertex(possibleposition[49]);
1456                          }
1457            else if(findpos(actuelposition,possibleposition[46])){
1458                adjacentPositions[0]=positionArray[43]; //graphVertex(possibleposition[43]);
1459                adjacentPositions[1]=positionArray[47]; //graphVertex(possibleposition[47]);
1460                       }
1461            else if(findpos(actuelposition,possibleposition[47])){
1462                adjacentPositions[0]=positionArray[46]; //graphVertex(possibleposition[46]);
1463                adjacentPositions[1]=positionArray[52]; //graphVertex(possibleposition[52]);
1464                adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]);
1465                          }
1466            else if(findpos(actuelposition,possibleposition[48])){
1467                adjacentPositions[0]=positionArray[49]; //graphVertex(possibleposition[49]);
1468                adjacentPositions[1]=positionArray[51]; //graphVertex(possibleposition[51]);
1469                adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]);
1470                          }
1471            else if(findpos(actuelposition,possibleposition[49])){
1472                adjacentPositions[0]=positionArray[45]; //graphVertex(possibleposition[45]);
1473                adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]);
1474                       }
1475            else if(findpos(actuelposition,possibleposition[50])){
1476                adjacentPositions[0]=positionArray[51]; //graphVertex(possibleposition[51]);
1477                adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]);
1478                       }
1479            else if(findpos(actuelposition,possibleposition[51])){
1480                adjacentPositions[0]=positionArray[48]; //graphVertex(possibleposition[48]);
1481                adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]);
1482                       }
1483            else if(findpos(actuelposition,possibleposition[52])){
1484                adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]);
1485                adjacentPositions[1]=positionArray[53]; //graphVertex(possibleposition[53]);
1486                       }
1487            else if(findpos(actuelposition,possibleposition[53])){
1488                adjacentPositions[0]=positionArray[52]; //graphVertex(possibleposition[52]);
1489                adjacentPositions[1]=positionArray[58]; //graphVertex(possibleposition[58]);
1490                       }
1491            else if(findpos(actuelposition,possibleposition[54])){
1492                adjacentPositions[0]=positionArray[42]; //graphVertex(possibleposition[42]);
1493                adjacentPositions[1]=positionArray[55]; //graphVertex(possibleposition[55]);
1494                adjacentPositions[2]=positionArray[57]; //graphVertex(possibleposition[57]);
1495                          }
1496            else if(findpos(actuelposition,possibleposition[55])){
1497                adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]);
1498                adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]);
1499                       }
1500            else if(findpos(actuelposition,possibleposition[56])){
1501                adjacentPositions[0]=positionArray[55]; //graphVertex(possibleposition[55]);
1502                adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]);
1503                adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]);
1504                          }
1505            else if(findpos(actuelposition,possibleposition[57])){
1506                adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]);
1507                adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]);
1508                adjacentPositions[2]=positionArray[58]; //graphVertex(possibleposition[58]);
1509                adjacentPositions[3]=positionArray[64]; //graphVertex(possibleposition[64]);
1510               
1511            }
1512            else if(findpos(actuelposition,possibleposition[58])){
1513                adjacentPositions[0]=positionArray[53]; //graphVertex(possibleposition[53]);
1514                adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]);
1515                adjacentPositions[2]=positionArray[59]; //graphVertex(possibleposition[59]);
1516                          }
1517            else if(findpos(actuelposition,possibleposition[59])){
1518                adjacentPositions[0]=positionArray[58]; //graphVertex(possibleposition[58]);
1519                adjacentPositions[1]=positionArray[60]; //graphVertex(possibleposition[60]); //error 59
1520                adjacentPositions[2]=positionArray[63]; //graphVertex(possibleposition[63]);
1521                          }
1522            else if(findpos(actuelposition,possibleposition[60])){
1523                adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]);
1524                adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]);
1525                adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]);
1526                          }
1527            else if(findpos(actuelposition,possibleposition[61])){
1528                adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]);
1529                adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]);
1530                adjacentPositions[2]=positionArray[60]; //graphVertex(possibleposition[60]);
1531                          }
1532            else if(findpos(actuelposition,possibleposition[62])){
1533                adjacentPositions[0]=positionArray[16]; //graphVertex(possibleposition[16]);
1534                adjacentPositions[1]=positionArray[60]; //graphVertex(possibleposition[60]);
1535                       }
1536            else if(findpos(actuelposition,possibleposition[63])){
1537                adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]);
1538                adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]);
1539                       }
1540            else if(findpos(actuelposition,possibleposition[64])){
1541                adjacentPositions[0]=positionArray[57]; //graphVertex(possibleposition[57]);
1542                adjacentPositions[1]=positionArray[63]; //graphVertex(possibleposition[63]);
1543                adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]);
1544                          }
1545            else if(findpos(actuelposition,possibleposition[65])){
1546                adjacentPositions[0]=positionArray[56]; //graphVertex(possibleposition[56]);
1547                adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]);
1548                       }
1549            else if(findpos(actuelposition,possibleposition[66])){
1550                adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]);
1551                adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]);
1552                       }
1553    }
1554
1555
1556}
Note: See TracBrowser for help on using the repository browser.