[Orxonox-commit 7731] r12324 - code/branches/3DPacman_FS19/src/modules/pacman
peterf at orxonox.net
peterf at orxonox.net
Sat Apr 27 16:49:55 CEST 2019
Author: peterf
Date: 2019-04-27 16:49:54 +0200 (Sat, 27 Apr 2019)
New Revision: 12324
Modified:
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
Log:
PacmanPink seems to work most of the time now
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-25 12:45:27 UTC (rev 12323)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-27 14:49:54 UTC (rev 12324)
@@ -223,17 +223,6 @@
speed ++;
}
- /*Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){
- //given that the position of a pacman is generally not "neat",
- //we need to set it to the nearest point on the map
- // if the pacman is not moving anymore, i.e. has reached a point
- int i=0;
- while(!(findpos(possibleposition[i], posToSet))){
- i++;
- }
- return possibleposition[i];
- }*/
-
Vector3 PacmanGhost::getPlayerPos()
{
for (PacmanGelb* player : ObjectList<PacmanGelb>())
@@ -746,492 +735,9 @@
}
}
-
-
-
-
- /*Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){
- //this function should then somehow produce the algorithm and call all other functions
- //and finally return the best neighboor of the actual position of the pacman
-
-
- graphVertex listOfVerticesM[67]; //our list of all possible graphs
- graphVertex* actualVertex;// = new graphVertex(); //we will walk through the array with a pointer
-
- if(start==goal){ // basic case
- return start;
- }
-
- for(int an=0; an < 67; an++){
- listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file
- if(start==possibleposition[an]){
- actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array
- //cout<<an<<endl;
- }
- }
-
- actualVertex->alreadyVisited=true; //our start point is now visited
- actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0
- findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);
- // second parameter is an array ! //third is our global array
-
- while(actualVertex->position!=goal){
- for(int h=0;h < 4; h++){
- if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex
-
- //h=2 and 3 never reached
- updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]);
- } //we "update" the neighboors of our new visited vertex
-
- }
-
- actualVertex=findNextVertexToConsider(listOfVerticesM);
- actualVertex->alreadyVisited=true;
- //cout<<actualVertex->position<<endl;
- if(actualVertex->position!=goal){
- findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);
- //we find the neighboors of our new visited vertex
- }
- }
-
- //cout<<"meuejeeke"<<endl; never reached
-
- //we should have reached our goal at this point
-
- while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor
- actualVertex=actualVertex->actuelPredecessor;
- }
- // the predecessor is our starting point, in other words we are now on an
- //adjacent vertex of the start
-
- return actualVertex->position; //we return the position of this - adjacent to start - vertex
- }
-
-//end of getShortestPath
-
-
- int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){
- //cout<<hgj++<<endl;
- Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));
-
- return differenceVector.x+differenceVector.z;
- }
-
- void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){
- //apply this method to all non visited neighboors of a vertex.
- // This method should always be run on a vertex after we marked it as visited.
- if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors.
- if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&&
- (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart +
- graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case !
-
- neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart +
- graphDistance(vertex.position, neighboor.position);
- neighboor.actuelPredecessor = &vertex;
- }
- }
- }
-
- void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex){
- //find nearest non visited neighboor of a given already visited vertex
- int shortestDistance = -1;
- graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any.
- //Also, if all neighboors are already visited, we return nullptr, i.e. there is no
- //nearest non visited neighboor.
- for(int i=0; i < 4; i++){
- if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)){
- if(shortestDistance==-1){ //(concerns line above) we want a non visited neighboor
- shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
- nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
- //cout<<shortestDistance<<endl;
- }
- else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){
- shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
- nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !
- //cout<<(hgj++)%4<<endl;
- }
- }
- }
- vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses !
- //cout<<hgj++<<endl;
- }
-
-
- PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[]){ //find next, nearest from start, non visited vertex in our listOfVertices array
-
- int shortestDistance = -1;
- graphVertex* nextVertexToConsider;
-
- for(int i=0; i < 67; i++){ //we loop over all possible positions
-
- if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited
-
- findNearestNonVisitedNeighboor(listOfVerticesP[i]); //we update nearest neighboor
- //of all visited vertices given that one of the nearest neighboor of a visited
- // vertex is now also visited because it was chosen as next optimal vertex
-
- if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate!
- if(shortestDistance==-1){ //our first possible candidate
-
- shortestDistance=graphDistance(listOfVerticesP[i].position,
- listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
- listOfVerticesP[i].shortestDistanceToStart;
-
- nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
- //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor
-
- }
- else if(shortestDistance > graphDistance(listOfVerticesP[i].position,
- listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
- listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available
-
- shortestDistance=graphDistance(listOfVerticesP[i].position,
- listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +
- listOfVerticesP[i].shortestDistanceToStart;
-
- nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;
- //we dont need the & because we are not giving the adress of the array element
- //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor
- }
- }
- }
- //we want after all to return the nearest non visited neighboor
- }
-
- return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array
- }
-
- //////////////////////////////////////////////////////////////////////////////////////////////
-
- //if vertex already visited, call function on it and reapeat until you reach non visited vertex
- // ---> not sure if a good idea because we risk infinite loop
-
- //-215 -185 -135 -70 -20 0 20 70 135 185 215
-
- //-195 -135 -85 -35 15 60 105 150 195 245
-
- void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){
-
-
- if(findpos(actuelposition,possibleposition[0])){
- // we should use listOfVerticesP2[i] instead of possibleposition[i] I think
- // so that all neighboors are "the same"
- adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]); //need to do it everywhere !!!
- adjacentVertices[1]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
- adjacentVertices[2]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ?
- }
- else if(findpos(actuelposition,possibleposition[1])){
- adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
- adjacentVertices[1]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
- }
- else if(findpos(actuelposition,possibleposition[2])){
- adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);
- adjacentVertices[1]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
- }
- else if(findpos(actuelposition,possibleposition[3])){
- adjacentVertices[0]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);
- adjacentVertices[1]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
- adjacentVertices[2]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
- }
- else if(findpos(actuelposition,possibleposition[4])){
- adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
- adjacentVertices[1]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
- }
- else if(findpos(actuelposition,possibleposition[5])){
- adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);
- adjacentVertices[1]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
- }
- else if(findpos(actuelposition,possibleposition[6])){
- adjacentVertices[0]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);
- adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
- adjacentVertices[2]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
- }
- else if(findpos(actuelposition,possibleposition[7])){
- adjacentVertices[0]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);
- adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
- }
- else if(findpos(actuelposition,possibleposition[8])){
- adjacentVertices[0]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);
- adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
- }
- else if(findpos(actuelposition,possibleposition[9])){
- adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
- adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);
- adjacentVertices[2]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
- adjacentVertices[3]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
- }
- else if(findpos(actuelposition,possibleposition[10])){
- adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
- adjacentVertices[1]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
- adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
- }
- else if(findpos(actuelposition,possibleposition[11])){
- adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
- adjacentVertices[1]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
- adjacentVertices[2]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
- }
- else if(findpos(actuelposition,possibleposition[12])){
- adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
- adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
- }
- else if(findpos(actuelposition,possibleposition[13])){
- adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);
- adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
- adjacentVertices[2]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
- adjacentVertices[3]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
- }
- else if(findpos(actuelposition,possibleposition[14])){
- adjacentVertices[0]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);
- adjacentVertices[1]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
- adjacentVertices[2]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
- }
- else if(findpos(actuelposition,possibleposition[15])){
- adjacentVertices[0]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);
- adjacentVertices[1]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
- }
- else if(findpos(actuelposition,possibleposition[16])){
- adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
- adjacentVertices[1]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);
- adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
- }
- else if(findpos(actuelposition,possibleposition[17])){
- adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
- adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
- }
- else if(findpos(actuelposition,possibleposition[18])){
- adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
- adjacentVertices[1]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);
- }
- else if(findpos(actuelposition,possibleposition[19])){
- adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);
- adjacentVertices[1]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
- adjacentVertices[2]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
- }
- else if(findpos(actuelposition,possibleposition[20])){
- adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);
- adjacentVertices[1]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
- }
- else if(findpos(actuelposition,possibleposition[21])){
- adjacentVertices[0]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);
- adjacentVertices[1]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
- }
- else if(findpos(actuelposition,possibleposition[22])){
- adjacentVertices[0]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);
- adjacentVertices[1]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
- adjacentVertices[2]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
- }
- else if(findpos(actuelposition,possibleposition[23])){
- adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
- adjacentVertices[1]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
- }
- else if(findpos(actuelposition,possibleposition[24])){
- adjacentVertices[0]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);
- adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
- }
- else if(findpos(actuelposition,possibleposition[25])){
- adjacentVertices[0]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);
- adjacentVertices[1]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
- }
- else if(findpos(actuelposition,possibleposition[26])){
- adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);
- adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);
- adjacentVertices[2]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
- }
- else if(findpos(actuelposition,possibleposition[27])){
- adjacentVertices[0]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);
- adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
- adjacentVertices[2]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
- }
- else if(findpos(actuelposition,possibleposition[28])){
- adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
- adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
- adjacentVertices[2]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
- }
- else if(findpos(actuelposition,possibleposition[29])){
- adjacentVertices[0]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);
- adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
- adjacentVertices[2]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
- }
- else if(findpos(actuelposition,possibleposition[30])){
- adjacentVertices[0]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);
- adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);
- adjacentVertices[2]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
- }
- else if(findpos(actuelposition,possibleposition[31])){
- adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);
- adjacentVertices[1]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
- }
- else if(findpos(actuelposition,possibleposition[32])){
- adjacentVertices[0]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);
- adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
- }
- else if(findpos(actuelposition,possibleposition[33])){
- adjacentVertices[0]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);
- adjacentVertices[1]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
- }
- else if(findpos(actuelposition,possibleposition[34])){
- adjacentVertices[0]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);
- adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);
- adjacentVertices[2]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
- adjacentVertices[3]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
-
- }
- else if(findpos(actuelposition,possibleposition[35])){
- adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
- adjacentVertices[1]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);
- adjacentVertices[2]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
- }
- else if(findpos(actuelposition,possibleposition[36])){
- adjacentVertices[0]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);
- adjacentVertices[1]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
- }
- else if(findpos(actuelposition,possibleposition[37])){
- adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);
- adjacentVertices[1]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
- }
- else if(findpos(actuelposition,possibleposition[38])){
- adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);
- adjacentVertices[1]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);
- adjacentVertices[2]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
- }
- else if(findpos(actuelposition,possibleposition[39])){
- adjacentVertices[0]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);
- adjacentVertices[1]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
- adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
- }
- else if(findpos(actuelposition,possibleposition[40])){
- adjacentVertices[0]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
- adjacentVertices[1]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
- }
- else if(findpos(actuelposition,possibleposition[41])){
- adjacentVertices[0]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);
- adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
- }
- else if(findpos(actuelposition,possibleposition[42])){
- adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);
- adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
- adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
- }
- else if(findpos(actuelposition,possibleposition[43])){
- adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);
- adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
- }
- else if(findpos(actuelposition,possibleposition[44])){
- adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);
- adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
- }
- else if(findpos(actuelposition,possibleposition[45])){
- adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);
- adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);
- adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
- }
- else if(findpos(actuelposition,possibleposition[46])){
- adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);
- adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
- }
- else if(findpos(actuelposition,possibleposition[47])){
- adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);
- adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
- adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
- }
- else if(findpos(actuelposition,possibleposition[48])){
- adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);
- adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
- adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);
- }
- else if(findpos(actuelposition,possibleposition[49])){
- adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);
- adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
- }
- else if(findpos(actuelposition,possibleposition[50])){
- adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);
- adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
- }
- else if(findpos(actuelposition,possibleposition[51])){
- adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
- adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
- }
- else if(findpos(actuelposition,possibleposition[52])){
- adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
- adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
- }
- else if(findpos(actuelposition,possibleposition[53])){
- adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);
- adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
- }
- else if(findpos(actuelposition,possibleposition[54])){
- adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);
- adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
- adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
- }
- else if(findpos(actuelposition,possibleposition[55])){
- adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
- adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
- }
- else if(findpos(actuelposition,possibleposition[56])){
- adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);
- adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
- adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
- }
- else if(findpos(actuelposition,possibleposition[57])){
- adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);
- adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
- adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
- adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
-
- }
- else if(findpos(actuelposition,possibleposition[58])){
- adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);
- adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
- adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
- }
- else if(findpos(actuelposition,possibleposition[59])){
- adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);
- adjacentVertices[1]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
- adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
- }
- else if(findpos(actuelposition,possibleposition[60])){
- adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
- adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);
- adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);
- }
- else if(findpos(actuelposition,possibleposition[61])){
- adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);
- adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);
- adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
- }
- else if(findpos(actuelposition,possibleposition[62])){
- adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);
- adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);
- }
- else if(findpos(actuelposition,possibleposition[63])){
- adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);
- adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
- }
- else if(findpos(actuelposition,possibleposition[64])){
- adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);
- adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);
- adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);
- }
- else if(findpos(actuelposition,possibleposition[65])){
- adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);
- adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);
- }
- else if(findpos(actuelposition,possibleposition[66])){
- adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
- adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
- }
- }*/
-
-
-
-
//functions taken from PacmanPink
-
-
-
Vector3 PacmanGhost::diffVector (Vector3 start, Vector3 goal){
Vector3 result;
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc 2019-04-25 12:45:27 UTC (rev 12323)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc 2019-04-27 14:49:54 UTC (rev 12324)
@@ -16,6 +16,7 @@
this->target_x=0;
this->target_z=15;
this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135);
+ this->pointInFrontOfPlayer=Vector3(0,0,0);
}
@@ -37,11 +38,15 @@
for(int u=0; u < 67; u++){//always check if player passed a point
- if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
- this->lastPlayerPassedPoint=possibleposition[u];
- }
+ if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
+ this->lastPlayerPassedPoint=possibleposition[u];
+ }
}
+ int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+ this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
+ /*std::cout<<this->pointInFrontOfPlayer<<endl;
+ std::cout<<this->lastPlayerPassedPoint<<endl;*/
//Stop, if target arrived
if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
@@ -67,6 +72,15 @@
this->ismoving=false;
}
+ else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){
+ std::cout<<"arheeuuuu"<<endl;
+
+ Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
+
+ setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint));
+
+
+ }
//Check on which position the ghost has arrived and set new target
else{
while(lockmove){};
@@ -73,65 +87,16 @@
lockmove = true;
Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
+
+ //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+ //this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
std::cout<<this->lastPlayerPassedPoint<<endl;
- int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
- this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
-
std::cout<<this->pointInFrontOfPlayer<<endl;
nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint);
-
- /*if(findPos(player.getPos(), player.lastPassedPoint)){
- // if player is on a point, for simplicity go to it
- Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint);
- setNewTargetPink(nextMove);
- }
-
- else{ //if player is not on a point either go to next neighboor, or if no
- //neighboor in player direction available, go to last point passed by player.
-
- int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos());
- //not in other sense!
-
- Vector3[] neighboors;
- findNeighboor(player.lastPassedPoint, neighboors);
- //we need to create function that finds neighboors of player last point
- //We can use and even should use the part of the tick random function
- // that determines the neighboors. But array neighboor should be in form
- // south-west-north-east respectively to array index.
-
- for(int s=0; s < 4; s++){
- //find next neighboor between player and player.lastPassedPoint
- if((neighboors[s]!=NULL)&&(s==dir)){
- if(dir==0){
- Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
- setNewTargetPink(nextMove);
- }
- else if(dir==1){
- Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
- setNewTargetPink(nextMove);
- }
- else if(dir==2){
- Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
- setNewTargetPink(nextMove);
- }
- else{//last is default
- Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);
- setNewTargetPink(nextMove);
- }
- }
- else{//if no further point after last player point possible
- //then simply go to this last point.
- Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint);
- setNewTargetPink(nextMove);
- }
-
- }
-
- }*/
lockmove=false;
}
@@ -148,7 +113,12 @@
Vector3 nextTarget;
- nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
+ if(playerPos==pointToAvoidP11){
+ nextTarget = getShortestPath(pinkPosP, playerPos);
+ }
+ else{
+ nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
+ }
setNewTargetGhost(nextTarget);
}
More information about the Orxonox-commit
mailing list