Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

PacmanPink seems to work most of the time now

  • Property svn:executable set to *
File size: 61.6 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                       }
622            else if(findpos(actuelposition,possibleposition[42])){
623                adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
624                adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
625                adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
626                          }
627            else if(findpos(actuelposition,possibleposition[43])){
628                adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
629                adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
630                       }
631            else if(findpos(actuelposition,possibleposition[44])){
632                adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
633                adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
634                       }
635            else if(findpos(actuelposition,possibleposition[45])){
636                adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
637                adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
638                adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
639                          }
640            else if(findpos(actuelposition,possibleposition[46])){
641                adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
642                adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
643                       }
644            else if(findpos(actuelposition,possibleposition[47])){
645                adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
646                adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
647                adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
648                          }
649            else if(findpos(actuelposition,possibleposition[48])){
650                adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
651                adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
652                adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
653                          }
654            else if(findpos(actuelposition,possibleposition[49])){
655                adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
656                adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
657                       }
658            else if(findpos(actuelposition,possibleposition[50])){
659                adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
660                adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
661                       }
662            else if(findpos(actuelposition,possibleposition[51])){
663                adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
664                adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
665                       }
666            else if(findpos(actuelposition,possibleposition[52])){
667                adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
668                adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
669                       }
670            else if(findpos(actuelposition,possibleposition[53])){
671                adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
672                adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
673                       }
674            else if(findpos(actuelposition,possibleposition[54])){
675                adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
676                adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
677                adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
678                          }
679            else if(findpos(actuelposition,possibleposition[55])){
680                adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
681                adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
682                       }
683            else if(findpos(actuelposition,possibleposition[56])){
684                adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
685                adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
686                adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
687                          }
688            else if(findpos(actuelposition,possibleposition[57])){
689                adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
690                adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
691                adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
692                adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
693               
694            }
695            else if(findpos(actuelposition,possibleposition[58])){
696                adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
697                adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
698                adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
699                          }
700            else if(findpos(actuelposition,possibleposition[59])){
701                adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
702                adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[59]);
703                adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
704                          }
705            else if(findpos(actuelposition,possibleposition[60])){
706                adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
707                adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
708                adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
709                          }
710            else if(findpos(actuelposition,possibleposition[61])){
711                adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
712                adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
713                adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
714                          }
715            else if(findpos(actuelposition,possibleposition[62])){
716                adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
717                adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
718                       }
719            else if(findpos(actuelposition,possibleposition[63])){
720                adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
721                adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
722                       }
723            else if(findpos(actuelposition,possibleposition[64])){
724                adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
725                adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
726                adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
727                          }
728            else if(findpos(actuelposition,possibleposition[65])){
729                adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
730                adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
731                       }
732            else if(findpos(actuelposition,possibleposition[66])){
733                adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
734                adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
735                       }
736    }
737
738    //functions taken from PacmanPink
739
740
741    Vector3 PacmanGhost::diffVector (Vector3 start, Vector3 goal){
742
743        Vector3 result;
744        result.x=goal.x-start.x;
745        result.z=goal.z-start.z;
746        return result;
747    }
748
749
750    bool PacmanGhost::playerFindPos(Vector3 one, Vector3 other){
751       if((abs(one.x - other.x)<15) && (abs(one.z - other.z)<15)) return true;
752        return false;
753        }
754
755
756
757
758    int PacmanGhost::findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
759        //return 0 for south, 1 for west, 2 for north, 3 for east
760
761
762        if(playerFindPos(playerPosBefore, playerPos)){
763            //if player is still near last crossed point
764
765            return 4; //return the last crossed point for simplicity
766        }
767
768
769        if(abs(playerPos.x-playerPosBefore.x)<14){ //player is moving vertically
770            if((playerPos.z-playerPosBefore.z)<0){//move west
771                return 0;
772            }
773            if((playerPos.z-playerPosBefore.z)>0){//move east
774                return 2;
775            }
776        }
777
778        if(abs(playerPos.z-playerPosBefore.z)<14){ //player is moving horizontally
779            if((playerPos.x-playerPosBefore.x)<0){//move south
780                return 1;
781            }
782            if((playerPos.x-playerPosBefore.x)>0){//move north
783                return 3;
784            }
785        }
786
787
788        /*Vector3 difference = diffVector(playerPosBefore, playerPos);
789        if((difference.z < 0)&&(difference.z>difference.x)){ //move south
790
791            return 0;
792        }
793        else if((difference.z>0)&&(difference.z>difference.x)){ //mouve north
794
795            return 2;
796        }
797        else if((difference.x < 0)&&(difference.x > difference.z )){//move west
798
799            return 1;
800        }
801
802        else if((difference.x>0)&&(difference.x>difference.z)){ //move east
803            return 3;
804
805        }
806
807        else { //default move west Can still be changed
808
809        return 1;
810            }*/
811       
812        }
813
814    Vector3 PacmanGhost::getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){
815        //return the Vector3 point that Pinky should target to
816        //be in front of pacman
817
818        if(indexForSWNE==4){
819            //std::cout<<"Ryukyu"<<endl;
820            return pacLasVisPos;
821        }
822
823        Vector3 listOfNeighboors[4];
824        //first element is south, 2nd west, 3d north, 4th east
825
826            if(findpos(pacLasVisPos,possibleposition[0])){
827                //no south neighbor
828                listOfNeighboors[1]=possibleposition[19]; // west neighbor
829                listOfNeighboors[2]=possibleposition[17]; //north
830                listOfNeighboors[3]=possibleposition[1]; //east
831                return listOfNeighboors[indexForSWNE];
832            }
833            else if(findpos(pacLasVisPos,possibleposition[1])){
834                listOfNeighboors[1]=possibleposition[0]; // west neighbor
835                listOfNeighboors[2]=possibleposition[2]; //north
836                return listOfNeighboors[indexForSWNE];
837            }
838            else if(findpos(pacLasVisPos,possibleposition[2])){
839                listOfNeighboors[0]=possibleposition[1];  //south
840                listOfNeighboors[1]=possibleposition[3]; //west
841                return listOfNeighboors[indexForSWNE];
842            }
843            else if(findpos(pacLasVisPos,possibleposition[3])){
844                listOfNeighboors[1]=possibleposition[4]; //west
845                listOfNeighboors[2]=possibleposition[5]; //north
846                listOfNeighboors[3]=possibleposition[2]; //east
847                return listOfNeighboors[indexForSWNE];
848            }
849            else if(findpos(pacLasVisPos,possibleposition[4])){
850                listOfNeighboors[2]=possibleposition[6]; //north
851                listOfNeighboors[3]=possibleposition[3]; //east
852                return listOfNeighboors[indexForSWNE];
853            }
854            else if(findpos(pacLasVisPos,possibleposition[5])){
855                listOfNeighboors[0]=possibleposition[3]; //south
856                listOfNeighboors[3]=possibleposition[7]; //east
857                return listOfNeighboors[indexForSWNE];
858            }
859            else if(findpos(pacLasVisPos,possibleposition[6])){
860                listOfNeighboors[0]=possibleposition[4]; //south
861                listOfNeighboors[1]=possibleposition[26]; //west
862                listOfNeighboors[2]=possibleposition[9]; //north
863                return listOfNeighboors[indexForSWNE];
864            }
865            else if(findpos(pacLasVisPos,possibleposition[7])){
866                listOfNeighboors[1]=possibleposition[5]; //west
867                listOfNeighboors[2]=possibleposition[8]; //north
868                return listOfNeighboors[indexForSWNE];
869            }
870            else if(findpos(pacLasVisPos,possibleposition[8])){
871                listOfNeighboors[0]=possibleposition[7]; //south
872                listOfNeighboors[1]=possibleposition[9]; //west
873                return listOfNeighboors[indexForSWNE];
874            }
875            else if(findpos(pacLasVisPos,possibleposition[9])){
876                listOfNeighboors[0]=possibleposition[6]; //south
877                listOfNeighboors[1]=possibleposition[38]; //west
878                listOfNeighboors[2]=possibleposition[10]; //north
879                listOfNeighboors[3]=possibleposition[8]; //east
880                return listOfNeighboors[indexForSWNE];
881            }
882            else if(findpos(pacLasVisPos,possibleposition[10])){
883
884                if(indexForSWNE==3){ //nothing eastward
885                    return pacLasVisPos;
886                }
887
888                listOfNeighboors[0]=possibleposition[9]; //south
889                listOfNeighboors[1]=possibleposition[45]; //west
890                listOfNeighboors[2]=possibleposition[11]; //north
891                return listOfNeighboors[indexForSWNE];
892            }
893            else if(findpos(pacLasVisPos,possibleposition[11])){
894                listOfNeighboors[0]=possibleposition[10]; //south
895                listOfNeighboors[2]=possibleposition[13]; //north
896                listOfNeighboors[3]=possibleposition[12]; //east
897                return listOfNeighboors[indexForSWNE];
898            }
899            else if(findpos(pacLasVisPos,possibleposition[12])){
900                listOfNeighboors[1]=possibleposition[11]; //west
901                listOfNeighboors[2]=possibleposition[14]; //north
902                return listOfNeighboors[indexForSWNE];
903            }
904            else if(findpos(pacLasVisPos,possibleposition[13])){
905                listOfNeighboors[0]=possibleposition[11]; //south
906                listOfNeighboors[1]=possibleposition[61]; //west
907                listOfNeighboors[2]=possibleposition[16]; //north
908                listOfNeighboors[3]=possibleposition[14]; //east
909                return listOfNeighboors[indexForSWNE];
910            }
911            else if(findpos(pacLasVisPos,possibleposition[14])){
912                listOfNeighboors[0]=possibleposition[12]; //south
913                listOfNeighboors[1]=possibleposition[13]; //west
914                listOfNeighboors[2]=possibleposition[15]; //north
915                return listOfNeighboors[indexForSWNE];
916            }
917            else if(findpos(pacLasVisPos,possibleposition[15])){
918                listOfNeighboors[0]=possibleposition[14]; //south
919                listOfNeighboors[1]=possibleposition[16]; //west
920                return listOfNeighboors[indexForSWNE];
921            }
922            else if(findpos(pacLasVisPos,possibleposition[16])){
923                listOfNeighboors[0]=possibleposition[13]; //south
924                listOfNeighboors[1]=possibleposition[62]; //west
925                listOfNeighboors[2]=possibleposition[15]; //north
926                return listOfNeighboors[indexForSWNE];
927            }
928            else if(findpos(pacLasVisPos,possibleposition[17])){
929                listOfNeighboors[0]=possibleposition[0]; //south
930                listOfNeighboors[3]=possibleposition[25]; //east
931                return listOfNeighboors[indexForSWNE];
932            }
933            else if(findpos(pacLasVisPos,possibleposition[18])){
934                listOfNeighboors[0]=possibleposition[19]; //south
935                listOfNeighboors[1]=possibleposition[24]; //west
936                return listOfNeighboors[indexForSWNE];
937            }
938            else if(findpos(pacLasVisPos,possibleposition[19])){
939                listOfNeighboors[1]=possibleposition[20]; //west
940                listOfNeighboors[2]=possibleposition[18]; //north
941                listOfNeighboors[3]=possibleposition[0]; //east
942                return listOfNeighboors[indexForSWNE];
943            }
944            else if(findpos(pacLasVisPos,possibleposition[20])){
945                listOfNeighboors[2]=possibleposition[21]; //north
946                listOfNeighboors[3]=possibleposition[19]; //east
947                return listOfNeighboors[indexForSWNE];
948            }
949            else if(findpos(pacLasVisPos,possibleposition[21])){
950                listOfNeighboors[0]=possibleposition[20]; //south
951                listOfNeighboors[3]=possibleposition[22]; //east
952                return listOfNeighboors[indexForSWNE];
953            }
954            else if(findpos(pacLasVisPos,possibleposition[22])){
955                listOfNeighboors[1]=possibleposition[21]; //west
956                listOfNeighboors[2]=possibleposition[31]; //north
957                listOfNeighboors[3]=possibleposition[23]; //east
958                return listOfNeighboors[indexForSWNE];
959            }
960            else if(findpos(pacLasVisPos,possibleposition[23])){
961                listOfNeighboors[1]=possibleposition[22]; //west
962                listOfNeighboors[2]=possibleposition[30]; //north
963                return listOfNeighboors[indexForSWNE];
964            }
965            else if(findpos(pacLasVisPos,possibleposition[24])){
966                listOfNeighboors[2]=possibleposition[29]; //north
967                listOfNeighboors[3]=possibleposition[18]; //east
968                return listOfNeighboors[indexForSWNE];
969            }
970            else if(findpos(pacLasVisPos,possibleposition[25])){
971                listOfNeighboors[1]=possibleposition[17]; //west
972                listOfNeighboors[2]=possibleposition[26]; //north
973                return listOfNeighboors[indexForSWNE];
974            }
975            else if(findpos(pacLasVisPos,possibleposition[26])){
976                listOfNeighboors[0]=possibleposition[25]; //south
977                listOfNeighboors[1]=possibleposition[27]; //west
978                listOfNeighboors[3]=possibleposition[6]; //east
979                return listOfNeighboors[indexForSWNE];
980            }
981            else if(findpos(pacLasVisPos,possibleposition[27])){
982                listOfNeighboors[1]=possibleposition[28]; //west
983                listOfNeighboors[2]=possibleposition[37]; //north
984                listOfNeighboors[3]=possibleposition[26]; //east
985                return listOfNeighboors[indexForSWNE];
986            }
987            else if(findpos(pacLasVisPos,possibleposition[28])){
988                listOfNeighboors[1]=possibleposition[29]; //west
989                listOfNeighboors[2]=possibleposition[36]; //north
990                listOfNeighboors[3]=possibleposition[27]; //east
991                return listOfNeighboors[indexForSWNE];
992            }
993            else if(findpos(pacLasVisPos,possibleposition[29])){
994                listOfNeighboors[0]=possibleposition[24]; //south
995                listOfNeighboors[1]=possibleposition[30]; //west
996                listOfNeighboors[3]=possibleposition[28]; //east
997                return listOfNeighboors[indexForSWNE];
998            }
999            else if(findpos(pacLasVisPos,possibleposition[30])){
1000                listOfNeighboors[0]=possibleposition[23]; //south
1001                listOfNeighboors[2]=possibleposition[34]; //north
1002                listOfNeighboors[3]=possibleposition[29]; //east
1003                return listOfNeighboors[indexForSWNE];
1004            }
1005            else if(findpos(pacLasVisPos,possibleposition[31])){
1006                listOfNeighboors[0]=possibleposition[22]; //south
1007                listOfNeighboors[1]=possibleposition[32]; //west
1008                return listOfNeighboors[indexForSWNE];
1009            }
1010            else if(findpos(pacLasVisPos,possibleposition[32])){
1011                listOfNeighboors[2]=possibleposition[33]; //north
1012                listOfNeighboors[3]=possibleposition[31]; //east
1013                return listOfNeighboors[indexForSWNE];
1014            }
1015            else if(findpos(pacLasVisPos,possibleposition[33])){
1016                listOfNeighboors[0]=possibleposition[32]; //south
1017                listOfNeighboors[3]=possibleposition[34]; //east
1018                return listOfNeighboors[indexForSWNE];
1019            }
1020            else if(findpos(pacLasVisPos,possibleposition[34])){
1021                listOfNeighboors[0]=possibleposition[30]; //south
1022                listOfNeighboors[1]=possibleposition[33]; //west
1023                listOfNeighboors[2]=possibleposition[92]; //north
1024                listOfNeighboors[3]=possibleposition[35]; //east
1025                return listOfNeighboors[indexForSWNE];
1026            }
1027            else if(findpos(pacLasVisPos,possibleposition[35])){
1028                listOfNeighboors[1]=possibleposition[34]; //west
1029                listOfNeighboors[2]=possibleposition[91]; //north
1030                listOfNeighboors[3]=possibleposition[36]; //east
1031                return listOfNeighboors[indexForSWNE];
1032            }
1033            else if(findpos(pacLasVisPos,possibleposition[36])){
1034                listOfNeighboors[0]=possibleposition[28]; //south
1035                listOfNeighboors[1]=possibleposition[35]; //west
1036                return listOfNeighboors[indexForSWNE];
1037            }
1038            else if(findpos(pacLasVisPos,possibleposition[37])){
1039                listOfNeighboors[0]=possibleposition[27]; //south
1040                listOfNeighboors[3]=possibleposition[38]; //east
1041                return listOfNeighboors[indexForSWNE];
1042            }
1043            else if(findpos(pacLasVisPos,possibleposition[38])){
1044                listOfNeighboors[1]=possibleposition[37]; //west
1045                listOfNeighboors[2]=possibleposition[39]; //north
1046                listOfNeighboors[3]=possibleposition[9]; //east
1047                return listOfNeighboors[indexForSWNE];
1048            }
1049            else if(findpos(pacLasVisPos,possibleposition[39])){
1050                listOfNeighboors[0]=possibleposition[38]; //south
1051                listOfNeighboors[1]=possibleposition[40]; //west
1052                listOfNeighboors[2]=possibleposition[45]; //north
1053                return listOfNeighboors[indexForSWNE];
1054            }
1055            else if(findpos(pacLasVisPos,possibleposition[40])){
1056                listOfNeighboors[1]=possibleposition[41]; //west
1057                //Not return in center
1058                listOfNeighboors[3]=possibleposition[39]; //east
1059                return listOfNeighboors[indexForSWNE];
1060            }
1061            else if(findpos(pacLasVisPos,possibleposition[41])){
1062                listOfNeighboors[0]=possibleposition[35]; //south
1063                listOfNeighboors[2]=possibleposition[43]; //north
1064                listOfNeighboors[3]=possibleposition[40]; //east
1065                return listOfNeighboors[indexForSWNE];
1066            }
1067            else if(findpos(pacLasVisPos,possibleposition[42])){
1068
1069                if(indexForSWNE==1){//nothing westward
1070                    return pacLasVisPos;
1071                }
1072
1073                listOfNeighboors[0]=possibleposition[39]; //south
1074                listOfNeighboors[2]=possibleposition[59]; //north
1075                listOfNeighboors[3]=possibleposition[43]; //east
1076                return listOfNeighboors[indexForSWNE];
1077            }
1078            else if(findpos(pacLasVisPos,possibleposition[43])){
1079                listOfNeighboors[0]=possibleposition[41]; //south
1080                listOfNeighboors[1]=possibleposition[42]; //west
1081                listOfNeighboors[2]=possibleposition[46]; //north
1082                return listOfNeighboors[indexForSWNE];
1083            }
1084            else if(findpos(pacLasVisPos,possibleposition[44])){
1085                listOfNeighboors[0]=possibleposition[40]; //south
1086                listOfNeighboors[2]=possibleposition[66]; //north
1087                return listOfNeighboors[indexForSWNE];
1088            }
1089            else if(findpos(pacLasVisPos,possibleposition[45])){
1090                listOfNeighboors[0]=possibleposition[39]; //south
1091                listOfNeighboors[2]=possibleposition[49]; //north
1092                listOfNeighboors[3]=possibleposition[10]; //east
1093                return listOfNeighboors[indexForSWNE];
1094            }
1095            else if(findpos(pacLasVisPos,possibleposition[46])){
1096                listOfNeighboors[0]=possibleposition[43]; //south
1097                listOfNeighboors[3]=possibleposition[47]; //east
1098                return listOfNeighboors[indexForSWNE];
1099            }
1100            else if(findpos(pacLasVisPos,possibleposition[47])){
1101                listOfNeighboors[1]=possibleposition[46]; //west
1102                listOfNeighboors[2]=possibleposition[52]; //north
1103                listOfNeighboors[3]=possibleposition[66]; //east
1104                return listOfNeighboors[indexForSWNE];
1105            }
1106            else if(findpos(pacLasVisPos,possibleposition[48])){
1107                listOfNeighboors[1]=possibleposition[66]; //west
1108                listOfNeighboors[2]=possibleposition[51]; //north
1109                listOfNeighboors[3]=possibleposition[49]; //east
1110                return listOfNeighboors[indexForSWNE];
1111            }
1112            else if(findpos(pacLasVisPos,possibleposition[49])){
1113                listOfNeighboors[0]=possibleposition[45]; //south
1114                listOfNeighboors[1]=possibleposition[48]; //west
1115                return listOfNeighboors[indexForSWNE];
1116            }
1117            else if(findpos(pacLasVisPos,possibleposition[50])){
1118                listOfNeighboors[1]=possibleposition[51]; //west
1119                listOfNeighboors[2]=possibleposition[61]; //north
1120                return listOfNeighboors[indexForSWNE];
1121            }
1122            else if(findpos(pacLasVisPos,possibleposition[51])){
1123                listOfNeighboors[0]=possibleposition[48]; //south
1124                listOfNeighboors[3]=possibleposition[50]; //east
1125                return listOfNeighboors[indexForSWNE];
1126            }
1127            else if(findpos(pacLasVisPos,possibleposition[52])){
1128                listOfNeighboors[0]=possibleposition[47]; //south
1129                listOfNeighboors[1]=possibleposition[53]; //west
1130                return listOfNeighboors[indexForSWNE];
1131            }
1132            else if(findpos(pacLasVisPos,possibleposition[53])){
1133                listOfNeighboors[2]=possibleposition[58]; //north
1134                listOfNeighboors[3]=possibleposition[52]; //east
1135                return listOfNeighboors[indexForSWNE];
1136            }
1137            else if(findpos(pacLasVisPos,possibleposition[54])){
1138                listOfNeighboors[0]=possibleposition[42]; //south
1139                listOfNeighboors[1]=possibleposition[55]; //west
1140                listOfNeighboors[2]=possibleposition[57]; //north
1141                return listOfNeighboors[indexForSWNE];
1142            }
1143            else if(findpos(pacLasVisPos,possibleposition[55])){
1144                listOfNeighboors[2]=possibleposition[56]; //north
1145                listOfNeighboors[3]=possibleposition[54]; //east
1146                return listOfNeighboors[indexForSWNE];
1147            }
1148            else if(findpos(pacLasVisPos,possibleposition[56])){
1149                listOfNeighboors[0]=possibleposition[55]; //south
1150                listOfNeighboors[2]=possibleposition[65]; //north
1151                listOfNeighboors[3]=possibleposition[57]; //east
1152                return listOfNeighboors[indexForSWNE];
1153            }
1154            else if(findpos(pacLasVisPos,possibleposition[57])){
1155                listOfNeighboors[0]=possibleposition[54]; //south
1156                listOfNeighboors[1]=possibleposition[56]; //west
1157                listOfNeighboors[2]=possibleposition[64]; //north
1158                listOfNeighboors[3]=possibleposition[58]; //east
1159                return listOfNeighboors[indexForSWNE];
1160            }
1161            else if(findpos(pacLasVisPos,possibleposition[58])){
1162                listOfNeighboors[0]=possibleposition[53]; //south
1163                listOfNeighboors[1]=possibleposition[57]; //west
1164                listOfNeighboors[3]=possibleposition[59]; //east
1165                return listOfNeighboors[indexForSWNE];
1166            }
1167            else if(findpos(pacLasVisPos,possibleposition[59])){
1168                listOfNeighboors[1]=possibleposition[58]; //west
1169                listOfNeighboors[2]=possibleposition[63]; //north
1170                listOfNeighboors[3]=possibleposition[60]; //east
1171                return listOfNeighboors[indexForSWNE];
1172            }
1173            else if(findpos(pacLasVisPos,possibleposition[60])){
1174                listOfNeighboors[1]=possibleposition[59]; //west
1175                listOfNeighboors[2]=possibleposition[62]; //north
1176                listOfNeighboors[3]=possibleposition[61]; //east
1177                return listOfNeighboors[indexForSWNE];
1178            }
1179            else if(findpos(pacLasVisPos,possibleposition[61])){
1180                listOfNeighboors[0]=possibleposition[50]; //south
1181                listOfNeighboors[1]=possibleposition[60]; //west
1182                listOfNeighboors[3]=possibleposition[13]; //east
1183                return listOfNeighboors[indexForSWNE];
1184            }
1185            else if(findpos(pacLasVisPos,possibleposition[62])){
1186                listOfNeighboors[0]=possibleposition[60]; //south
1187                listOfNeighboors[3]=possibleposition[16]; //east
1188                return listOfNeighboors[indexForSWNE];
1189            }
1190            else if(findpos(pacLasVisPos,possibleposition[63])){
1191                listOfNeighboors[0]=possibleposition[59]; //south
1192                listOfNeighboors[1]=possibleposition[64]; //west
1193                return listOfNeighboors[indexForSWNE];
1194            }
1195            else if(findpos(pacLasVisPos,possibleposition[64])){
1196                listOfNeighboors[0]=possibleposition[57]; //south
1197                listOfNeighboors[1]=possibleposition[65]; //west
1198                listOfNeighboors[3]=possibleposition[63]; //east
1199                return listOfNeighboors[indexForSWNE];
1200            }
1201            else if(findpos(pacLasVisPos,possibleposition[65])){
1202                listOfNeighboors[0]=possibleposition[56]; //south
1203                listOfNeighboors[3]=possibleposition[64]; //east
1204                return listOfNeighboors[indexForSWNE];
1205            }
1206            else if(findpos(pacLasVisPos,possibleposition[66])){
1207                //Not back in center
1208                listOfNeighboors[1]=possibleposition[47]; //west
1209                listOfNeighboors[3]=possibleposition[48]; //east
1210                return listOfNeighboors[indexForSWNE];           
1211            }
1212
1213        }
1214
1215
1216}
Note: See TracBrowser for help on using the repository browser.