Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12324


Ignore:
Timestamp:
Apr 27, 2019, 4:49:54 PM (5 years ago)
Author:
peterf
Message:

PacmanPink seems to work most of the time now

Location:
code/branches/3DPacman_FS19/src/modules/pacman
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc

    r12323 r12324  
    224224    }
    225225
    226     /*Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){
    227         //given that the position of a pacman is generally not "neat",
    228         //we need to set it to the nearest point on the map
    229         // if the pacman is not moving anymore, i.e. has reached a point
    230         int i=0;
    231         while(!(findpos(possibleposition[i], posToSet))){
    232             i++;
    233         }
    234         return possibleposition[i];
    235     }*/
    236 
    237226    Vector3 PacmanGhost::getPlayerPos()
    238227    {
     
    747736    }
    748737
    749 
    750 
    751 
    752 
    753         /*Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){
    754         //this function should then somehow produce the algorithm and call all other functions
    755         //and finally return the best neighboor of the actual position of the pacman
    756        
    757 
    758     graphVertex listOfVerticesM[67]; //our list of all possible graphs
    759     graphVertex* actualVertex;// = new graphVertex(); //we will walk through the array with a pointer
    760    
    761         if(start==goal){ // basic case
    762             return start;
    763         }
    764 
    765         for(int an=0; an < 67; an++){
    766       listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file
    767     if(start==possibleposition[an]){
    768      actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array
    769     //cout<<an<<endl;
    770             }
    771         }
    772 
    773         actualVertex->alreadyVisited=true; //our start point is now visited
    774         actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0
    775         findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);
    776         // second parameter is an array ! //third is our global array
    777 
    778         while(actualVertex->position!=goal){
    779             for(int h=0;h < 4; h++){
    780                 if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex
    781  
    782          //h=2 and 3 never reached
    783                     updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]);
    784                 } //we "update" the neighboors of our new visited vertex
    785        
    786             }
    787            
    788             actualVertex=findNextVertexToConsider(listOfVerticesM);
    789             actualVertex->alreadyVisited=true;
    790     //cout<<actualVertex->position<<endl;
    791             if(actualVertex->position!=goal){
    792                 findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);
    793                 //we find the neighboors of our new visited vertex
    794                 }
    795         }
    796 
    797     //cout<<"meuejeeke"<<endl; never reached
    798 
    799         //we should have reached our goal at this point
    800 
    801         while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor
    802             actualVertex=actualVertex->actuelPredecessor;
    803         }
    804         // the predecessor is our starting point, in other words we are now on an
    805         //adjacent vertex of the start
    806 
    807         return actualVertex->position; //we return the position of this - adjacent to start - vertex
    808     }
    809 
    810 //end of getShortestPath
    811 
    812 
    813     int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){
    814     //cout<<hgj++<<endl;
    815         Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));
    816 
    817         return differenceVector.x+differenceVector.z;
    818     }
    819 
    820     void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){
    821         //apply this method to all non visited neighboors of a vertex.
    822         // This method should always be run on a vertex after we marked it as visited.
    823         if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors.
    824             if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&&
    825         (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart +
    826                 graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case !
    827        
    828                 neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart +
    829                 graphDistance(vertex.position, neighboor.position);
    830                 neighboor.actuelPredecessor = &vertex;
    831             }
    832         }
    833     }
    834 
    835     void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex){
    836             //find nearest non visited neighboor of a given already visited vertex
    837         int shortestDistance = -1;
    838         graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any.
    839         //Also, if all neighboors are already visited, we return nullptr, i.e. there is no
    840         //nearest non visited neighboor.
    841         for(int i=0; i < 4; i++){
    842             if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)){
    843                 if(shortestDistance==-1){   //(concerns line above) we want a non visited neighboor
    844                     shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
    845                     nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
    846     //cout<<shortestDistance<<endl;
    847                 }
    848                 else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){
    849                     shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
    850                     nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
    851         //cout<<(hgj++)%4<<endl;
    852                 }
    853             }
    854         }
    855         vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses !
    856     //cout<<hgj++<<endl;
    857     }
    858 
    859 
    860     PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[]){ //find next, nearest from start, non visited vertex in our listOfVertices array
    861 
    862         int shortestDistance = -1;
    863         graphVertex* nextVertexToConsider;
    864 
    865         for(int i=0; i < 67; i++){ //we loop over all possible positions
    866 
    867             if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited
    868 
    869                 findNearestNonVisitedNeighboor(listOfVerticesP[i]); //we update nearest neighboor
    870                 //of all visited vertices given that one of the nearest neighboor of a visited
    871                 // vertex is now also visited because it was chosen as next optimal vertex
    872 
    873                 if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate!
    874                 if(shortestDistance==-1){ //our first possible candidate
    875 
    876             shortestDistance=graphDistance(listOfVerticesP[i].position,
    877             listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
    878             listOfVerticesP[i].shortestDistanceToStart;
    879 
    880             nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
    881     //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor
    882 
    883                 }
    884                 else if(shortestDistance > graphDistance(listOfVerticesP[i].position,
    885                 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
    886                     listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available
    887 
    888             shortestDistance=graphDistance(listOfVerticesP[i].position,
    889             listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
    890             listOfVerticesP[i].shortestDistanceToStart;
    891 
    892             nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
    893     //we dont need the & because we are not giving the adress of the array element
    894     //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor
    895                     }
    896                 }
    897             }
    898             //we want after all to return the nearest non visited neighboor
    899         }
    900 
    901         return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array
    902     }
    903 
    904     //////////////////////////////////////////////////////////////////////////////////////////////
    905 
    906     //if vertex already visited, call function on it and reapeat until you reach non visited vertex
    907     // ---> not sure if a good idea because we risk infinite loop
    908 
    909     //-215 -185 -135 -70 -20 0 20 70 135 185 215
    910 
    911     //-195 -135 -85 -35 15 60 105 150 195 245
    912 
    913     void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){     
    914 
    915 
    916             if(findpos(actuelposition,possibleposition[0])){
    917                 // we should use listOfVerticesP2[i] instead of possibleposition[i] I think
    918                 // so that all neighboors are "the same"
    919                 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);  //need to do it everywhere !!!
    920                 adjacentVertices[1]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
    921                 adjacentVertices[2]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ?
    922             }
    923             else if(findpos(actuelposition,possibleposition[1])){
    924                 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
    925                 adjacentVertices[1]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
    926             }
    927             else if(findpos(actuelposition,possibleposition[2])){
    928                 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);
    929                 adjacentVertices[1]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
    930             }
    931             else if(findpos(actuelposition,possibleposition[3])){
    932                 adjacentVertices[0]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
    933                 adjacentVertices[1]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
    934                 adjacentVertices[2]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
    935             }
    936             else if(findpos(actuelposition,possibleposition[4])){
    937                 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
    938                 adjacentVertices[1]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
    939             }
    940             else if(findpos(actuelposition,possibleposition[5])){
    941                 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
    942                 adjacentVertices[1]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
    943             }
    944             else if(findpos(actuelposition,possibleposition[6])){
    945                 adjacentVertices[0]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
    946                 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
    947                 adjacentVertices[2]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
    948             }
    949             else if(findpos(actuelposition,possibleposition[7])){
    950                 adjacentVertices[0]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
    951                 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
    952             }
    953             else if(findpos(actuelposition,possibleposition[8])){
    954                 adjacentVertices[0]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
    955                 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
    956             }
    957             else if(findpos(actuelposition,possibleposition[9])){
    958                 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
    959                 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
    960                 adjacentVertices[2]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
    961                 adjacentVertices[3]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
    962             }
    963             else if(findpos(actuelposition,possibleposition[10])){
    964                 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
    965                 adjacentVertices[1]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
    966                 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
    967             }
    968             else if(findpos(actuelposition,possibleposition[11])){
    969                 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
    970                 adjacentVertices[1]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
    971                 adjacentVertices[2]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
    972             }
    973             else if(findpos(actuelposition,possibleposition[12])){
    974                 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
    975                 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
    976             }
    977             else if(findpos(actuelposition,possibleposition[13])){
    978                 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
    979                 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
    980                 adjacentVertices[2]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
    981                 adjacentVertices[3]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
    982             }
    983             else if(findpos(actuelposition,possibleposition[14])){
    984                 adjacentVertices[0]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
    985                 adjacentVertices[1]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
    986                 adjacentVertices[2]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
    987             }
    988             else if(findpos(actuelposition,possibleposition[15])){
    989                 adjacentVertices[0]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
    990                 adjacentVertices[1]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
    991             }
    992             else if(findpos(actuelposition,possibleposition[16])){
    993                 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
    994                 adjacentVertices[1]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
    995                 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
    996             }
    997             else if(findpos(actuelposition,possibleposition[17])){
    998                 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
    999                 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
    1000             }
    1001             else if(findpos(actuelposition,possibleposition[18])){
    1002                 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
    1003                 adjacentVertices[1]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);               
    1004             }
    1005             else if(findpos(actuelposition,possibleposition[19])){
    1006                 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
    1007                 adjacentVertices[1]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
    1008                 adjacentVertices[2]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
    1009                          }
    1010             else if(findpos(actuelposition,possibleposition[20])){
    1011                 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
    1012                 adjacentVertices[1]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
    1013                        }
    1014             else if(findpos(actuelposition,possibleposition[21])){
    1015                 adjacentVertices[0]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
    1016                 adjacentVertices[1]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
    1017                        }
    1018             else if(findpos(actuelposition,possibleposition[22])){
    1019                 adjacentVertices[0]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
    1020                 adjacentVertices[1]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
    1021                 adjacentVertices[2]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
    1022                           }
    1023             else if(findpos(actuelposition,possibleposition[23])){
    1024                 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
    1025                 adjacentVertices[1]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
    1026                        }
    1027             else if(findpos(actuelposition,possibleposition[24])){
    1028                 adjacentVertices[0]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
    1029                 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
    1030                        }
    1031             else if(findpos(actuelposition,possibleposition[25])){
    1032                 adjacentVertices[0]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
    1033                 adjacentVertices[1]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
    1034                        }
    1035             else if(findpos(actuelposition,possibleposition[26])){
    1036                 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
    1037                 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
    1038                 adjacentVertices[2]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
    1039                          }
    1040             else if(findpos(actuelposition,possibleposition[27])){
    1041                 adjacentVertices[0]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
    1042                 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
    1043                 adjacentVertices[2]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
    1044                           }
    1045             else if(findpos(actuelposition,possibleposition[28])){
    1046                 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
    1047                 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
    1048                 adjacentVertices[2]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
    1049                           }
    1050             else if(findpos(actuelposition,possibleposition[29])){
    1051                 adjacentVertices[0]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);
    1052                 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
    1053                 adjacentVertices[2]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
    1054                           }
    1055             else if(findpos(actuelposition,possibleposition[30])){
    1056                 adjacentVertices[0]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
    1057                 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
    1058                 adjacentVertices[2]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
    1059                           }
    1060             else if(findpos(actuelposition,possibleposition[31])){
    1061                 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
    1062                 adjacentVertices[1]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
    1063                        }
    1064             else if(findpos(actuelposition,possibleposition[32])){
    1065                 adjacentVertices[0]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
    1066                 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
    1067                        }
    1068             else if(findpos(actuelposition,possibleposition[33])){
    1069                 adjacentVertices[0]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
    1070                 adjacentVertices[1]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
    1071                        }
    1072             else if(findpos(actuelposition,possibleposition[34])){
    1073                 adjacentVertices[0]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
    1074                 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
    1075                 adjacentVertices[2]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
    1076                 adjacentVertices[3]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
    1077                
    1078             }
    1079             else if(findpos(actuelposition,possibleposition[35])){
    1080                 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
    1081                 adjacentVertices[1]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
    1082                 adjacentVertices[2]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
    1083                           }
    1084             else if(findpos(actuelposition,possibleposition[36])){
    1085                 adjacentVertices[0]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
    1086                 adjacentVertices[1]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
    1087                        }
    1088             else if(findpos(actuelposition,possibleposition[37])){
    1089                 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
    1090                 adjacentVertices[1]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
    1091                        }
    1092             else if(findpos(actuelposition,possibleposition[38])){
    1093                 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
    1094                 adjacentVertices[1]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
    1095                 adjacentVertices[2]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
    1096                          }
    1097             else if(findpos(actuelposition,possibleposition[39])){
    1098                 adjacentVertices[0]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
    1099                 adjacentVertices[1]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
    1100                 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
    1101                           }
    1102             else if(findpos(actuelposition,possibleposition[40])){
    1103                 adjacentVertices[0]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
    1104                 adjacentVertices[1]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
    1105             }
    1106             else if(findpos(actuelposition,possibleposition[41])){
    1107                 adjacentVertices[0]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
    1108                 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
    1109                        }
    1110             else if(findpos(actuelposition,possibleposition[42])){
    1111                 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
    1112                 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
    1113                 adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
    1114                           }
    1115             else if(findpos(actuelposition,possibleposition[43])){
    1116                 adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
    1117                 adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
    1118                        }
    1119             else if(findpos(actuelposition,possibleposition[44])){
    1120                 adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
    1121                 adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
    1122                        }
    1123             else if(findpos(actuelposition,possibleposition[45])){
    1124                 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
    1125                 adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
    1126                 adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
    1127                           }
    1128             else if(findpos(actuelposition,possibleposition[46])){
    1129                 adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
    1130                 adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
    1131                        }
    1132             else if(findpos(actuelposition,possibleposition[47])){
    1133                 adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
    1134                 adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
    1135                 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
    1136                           }
    1137             else if(findpos(actuelposition,possibleposition[48])){
    1138                 adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
    1139                 adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
    1140                 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
    1141                           }
    1142             else if(findpos(actuelposition,possibleposition[49])){
    1143                 adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
    1144                 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
    1145                        }
    1146             else if(findpos(actuelposition,possibleposition[50])){
    1147                 adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
    1148                 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
    1149                        }
    1150             else if(findpos(actuelposition,possibleposition[51])){
    1151                 adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
    1152                 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
    1153                        }
    1154             else if(findpos(actuelposition,possibleposition[52])){
    1155                 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
    1156                 adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
    1157                        }
    1158             else if(findpos(actuelposition,possibleposition[53])){
    1159                 adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
    1160                 adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
    1161                        }
    1162             else if(findpos(actuelposition,possibleposition[54])){
    1163                 adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
    1164                 adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
    1165                 adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
    1166                           }
    1167             else if(findpos(actuelposition,possibleposition[55])){
    1168                 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
    1169                 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
    1170                        }
    1171             else if(findpos(actuelposition,possibleposition[56])){
    1172                 adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
    1173                 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
    1174                 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
    1175                           }
    1176             else if(findpos(actuelposition,possibleposition[57])){
    1177                 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
    1178                 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
    1179                 adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
    1180                 adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
    1181                
    1182             }
    1183             else if(findpos(actuelposition,possibleposition[58])){
    1184                 adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
    1185                 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
    1186                 adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
    1187                           }
    1188             else if(findpos(actuelposition,possibleposition[59])){
    1189                 adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
    1190                 adjacentVertices[1]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
    1191                 adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
    1192                           }
    1193             else if(findpos(actuelposition,possibleposition[60])){
    1194                 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
    1195                 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
    1196                 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
    1197                           }
    1198             else if(findpos(actuelposition,possibleposition[61])){
    1199                 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
    1200                 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
    1201                 adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
    1202                           }
    1203             else if(findpos(actuelposition,possibleposition[62])){
    1204                 adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
    1205                 adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
    1206                        }
    1207             else if(findpos(actuelposition,possibleposition[63])){
    1208                 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
    1209                 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
    1210                        }
    1211             else if(findpos(actuelposition,possibleposition[64])){
    1212                 adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
    1213                 adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
    1214                 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
    1215                           }
    1216             else if(findpos(actuelposition,possibleposition[65])){
    1217                 adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
    1218                 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
    1219                        }
    1220             else if(findpos(actuelposition,possibleposition[66])){
    1221                 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
    1222                 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
    1223                        }
    1224     }*/
    1225 
    1226 
    1227 
    1228 
    1229738    //functions taken from PacmanPink
    1230 
    1231 
    1232 
    1233739
    1234740
  • code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc

    r12322 r12324  
    1717        this->target_z=15;
    1818        this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135);
     19        this->pointInFrontOfPlayer=Vector3(0,0,0);
    1920         
    2021    }
     
    3839
    3940        for(int u=0; u < 67; u++){//always check if player passed a point
    40             if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
    41             this->lastPlayerPassedPoint=possibleposition[u];
    42                     }
     41            if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ 
     42                    this->lastPlayerPassedPoint=possibleposition[u];       
     43                }
    4344            }
    4445
     46        int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
     47        this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
     48        /*std::cout<<this->pointInFrontOfPlayer<<endl;
     49        std::cout<<this->lastPlayerPassedPoint<<endl;*/
    4550       
    4651        //Stop, if target arrived
     
    6873            this->ismoving=false;
    6974        }
     75        else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){
     76            std::cout<<"arheeuuuu"<<endl;
     77
     78            Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
     79
     80            setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint));
     81
     82
     83        }
    7084        //Check on which position the ghost has arrived and set new target
    7185         else{
     
    7488
    7589            Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
     90
     91            //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
     92            //this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
    7693           
    7794            std::cout<<this->lastPlayerPassedPoint<<endl;
    78 
    79             int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
    80             this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
    8195
    8296            std::cout<<this->pointInFrontOfPlayer<<endl;
     
    8498
    8599
    86 
    87             /*if(findPos(player.getPos(), player.lastPassedPoint)){
    88                 // if player is on a point, for simplicity go to it
    89             Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint);
    90             setNewTargetPink(nextMove);
    91             }
    92 
    93             else{ //if player is not on a point either go to next neighboor, or if no
    94             //neighboor in player direction available, go to last point passed by player.
    95 
    96             int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos());
    97             //not in other sense!
    98 
    99             Vector3[] neighboors;
    100             findNeighboor(player.lastPassedPoint, neighboors);
    101             //we need to create function that finds neighboors of player last point
    102             //We can use and even should use the part of the tick random function
    103             // that determines the neighboors. But array neighboor should be in form
    104             // south-west-north-east respectively to array index.
    105 
    106             for(int s=0; s < 4; s++){
    107                 //find next neighboor between player and player.lastPassedPoint
    108                 if((neighboors[s]!=NULL)&&(s==dir)){
    109                         if(dir==0){
    110                                 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
    111                                 setNewTargetPink(nextMove);
    112                         }
    113                         else if(dir==1){
    114                                 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
    115                                 setNewTargetPink(nextMove);
    116                         }
    117                         else if(dir==2){
    118                                 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
    119                                 setNewTargetPink(nextMove);
    120                         }
    121                         else{//last is default
    122                                 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
    123                                 setNewTargetPink(nextMove);
    124                                         }
    125                         }
    126                 else{//if no further point after last player point possible
    127                         //then simply go to this last point.
    128                 Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint);
    129                         setNewTargetPink(nextMove);
    130                         }
    131 
    132                 }
    133 
    134             }*/
    135100            lockmove=false;
    136101
     
    149114        Vector3 nextTarget;
    150115
    151        nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
     116        if(playerPos==pointToAvoidP11){
     117            nextTarget = getShortestPath(pinkPosP, playerPos);
     118        }
     119        else{
     120        nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
     121        }
    152122   
    153123       setNewTargetGhost(nextTarget);
Note: See TracChangeset for help on using the changeset viewer.