[Orxonox-commit 7726] r12319 - code/branches/3DPacman_FS19/src/modules/pacman
peterf at orxonox.net
peterf at orxonox.net
Sun Apr 21 23:30:42 CEST 2019
Author: peterf
Date: 2019-04-21 23:30:41 +0200 (Sun, 21 Apr 2019)
New Revision: 12319
Modified:
code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.h
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
Log:
PacmanPink implementation, but lots of SIGSEGV
Modified: code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt 2019-04-21 21:30:41 UTC (rev 12319)
@@ -7,6 +7,7 @@
PacmanHUDinfo.cc
PacmanRandom.cc
PacmanRed.cc
+ PacmanPink.cc
)
ORXONOX_ADD_LIBRARY(pacman
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-21 21:30:41 UTC (rev 12319)
@@ -246,8 +246,19 @@
}
+ bool PacmanGhost::jeanfindpos(Vector3 one, Vector3 other){
+ if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true;
+ return false;
+ }
+ void PacmanGhost::setNewTargetGhost(Vector3 goalToGo){
+ this->target_x = goalToGo.x;
+ this->target_z = goalToGo.z;
+ this->ismoving = true;
+ }
+
+
///
//// getShortestPath /////////
///
@@ -254,8 +265,492 @@
+ Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1){
+ //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
+
+ //(optional parameter) pointToAvoidP1 is a point that cannot be considered
- Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){
+
+ graphVertex listOfVerticesM[67]; //our list of all possible graphs
+ graphVertex* actualVertex; //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;
+ }
+ }
+
+ //graphVertex actualVertex= listOfVerticesM[an];
+
+ 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, pointToAvoidP1);
+ 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, Vector3 pointToAvoidP3){
+ //find nearest non visited neighboor of a given already visited vertex
+ //(optional parameter) pointToAvoidP3 is a point that cannot be considered
+ int shortestDistance = -1;
+ graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any.
+ //Also, if all neighboors are already visited, we return NULL, 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)&&(vertex.adjacentVertices[i]->position!=pointToAvoidP3)){
+ if(shortestDistance==-1){ //(concerns line above) we want a non visited neighboor //(optional) if the position of the neighboor is the one we want
+ //to avoid, then we ignore it
+
+ 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[], Vector3 pointToAvoidP2){ //find next, nearest from start, non visited vertex in our listOfVertices array
+ //(optional parameter) pointToAvoidP2 is a point that cannot be considered
+
+ 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], pointToAvoidP2); //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]);
+ }
+ }
+
+
+
+
+
+ /*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
@@ -726,7 +1221,7 @@
adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);
adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);
}
- }
+ }*/
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-21 21:30:41 UTC (rev 12319)
@@ -98,24 +98,28 @@
public: //HACK
- struct graphVertex;
- void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[]);
+ */
+
+ /*struct graphVertex;
+ void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]);
void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor);
void findNearestNonVisitedNeighboor (graphVertex &vertex);
int graphDistance(Vector3 start, Vector3 goal);
- graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]);*/
+ graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]);
+ Vector3 getShortestPath(Vector3 start, Vector3 goal);*/
struct graphVertex;
void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]);
void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor);
- void findNearestNonVisitedNeighboor (graphVertex &vertex);
+ void findNearestNonVisitedNeighboor (graphVertex &vertex, Vector3 pointToAvoidP3=Vector3(0,0,0));
int graphDistance(Vector3 start, Vector3 goal);
- graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]);
- Vector3 getShortestPath(Vector3 start, Vector3 goal);
+ graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[], Vector3 pointToAvoidP2=Vector3(0,0,0));
+ Vector3 getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1=Vector3(0,0,0));
+
//functions taken from PacmanPink
@@ -125,7 +129,11 @@
bool playerFindPos(Vector3 one, Vector3 other);
+ bool jeanfindpos(Vector3 one, Vector3 other);
+ void setNewTargetGhost(Vector3 goalToGo);
+
+
};
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc 2019-04-21 21:30:41 UTC (rev 12319)
@@ -12,6 +12,10 @@
PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){
RegisterObject(PacmanPink);
+
+ this->target_x=0;
+ this->target_z=15;
+ this->lastPlayerPassedPoint=Vector3(70,10,-135);
}
@@ -30,6 +34,14 @@
SUPER(PacmanGhost, tick, dt);
this->actuelposition = this->getPosition();
+
+
+ for(int u=0; u < 67; u++){//always check if player passed a point
+ if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){
+ this->lastPlayerPassedPoint=possibleposition[u];
+ }
+ }
+
//Stop, if target arrived
if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
@@ -52,7 +64,17 @@
while(lockmove){};
lockmove = true;
- if(findPos(player.getPos(), player.lastPassedPoint)){
+ Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z);
+
+ int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+ this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
+
+
+ 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);
@@ -99,441 +121,30 @@
}
- }
+ }*/
+ lockmove=false;
}
- /*
- Vector3 diffVector (Vector3 start, Vector3 goal){
- Vector3 result;
- result.x=goal.x-start.x;
- result.z=goal.z-start.z;
- return result;
+
}
- int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
- //return 0 for south, 1 for west, 2 for north, 3 for east
- Vector3 difference = diffVector(playerPosBefore, playerPos);
+ void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){
+
+ Vector3 nextTarget;
- if((difference.z < 0)&&(difference.z>difference.x)){ //move south
+ nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11);
+
+ setNewTargetGhost(nextTarget);
+ }
- return 0;
- }
- else if((difference.x < 0)&&(difference.x > difference.z )){//move west
+}
- return 1;
- }
-
- else if((difference.z>0)&&(difference.z>difference.x)){ //mouve north
-
- return 2;
- }
-
- else if((difference.x>0)&&(difference.x>difference.z)){ //move east
- return 3;
-
- }
-
- else { //default move west
-
- return 1;
- }
-
-
- Vector3 getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){
- //return the Vector3 point that Pinky should target to
- //be in front of pacman
-
- Vector3 listOfNeighboors[4];
- //first element is south, 2nd west, 3d north, 4th east
-
-
-
- if(findpos(pacLasVisPos,possibleposition[0])){
- //no south neighbor
- listOfNeighboors[1]=possibleposition[19]; // west neighbor
- listOfNeighboors[2]=possibleposition[17]; //north
- listOfNeighboors[3]=possibleposition[1]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[1])){
- listOfNeighboors[1]=possibleposition[0]; // west neighbor
- listOfNeighboors[2]=possibleposition[2]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[2])){
- listOfNeighboors[0]=possibleposition[1]; //south
- listOfNeighboors[1]=possibleposition[3]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[3])){
- listOfNeighboors[1]=possibleposition[4]; //west
- listOfNeighboors[2]=possibleposition[5]; //north
- listOfNeighboors[3]=possibleposition[2]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[4])){
- listOfNeighboors[2]=possibleposition[6]; //north
- listOfNeighboors[3]=possibleposition[3]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[5])){
- listOfNeighboors[0]=possibleposition[3]; //south
- listOfNeighboors[3]=possibleposition[7]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[6])){
- listOfNeighboors[0]=possibleposition[4]; //south
- listOfNeighboors[1]=possibleposition[26]; //west
- listOfNeighboors[2]=possibleposition[9]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[7])){
- listOfNeighboors[1]=possibleposition[5]; //west
- listOfNeighboors[2]=possibleposition[8]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[8])){
- listOfNeighboors[0]=possibleposition[7]; //south
- listOfNeighboors[1]=possibleposition[9]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[9])){
- listOfNeighboors[0]=possibleposition[6]; //south
- listOfNeighboors[1]=possibleposition[38]; //west
- listOfNeighboors[2]=possibleposition[10]; //north
- listOfNeighboors[3]=possibleposition[8]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[10])){
- listOfNeighboors[0]=possibleposition[9]; //south
- listOfNeighboors[1]=possibleposition[45]; //west
- listOfNeighboors[2]=possibleposition[11]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[11])){
- listOfNeighboors[0]=possibleposition[10]; //south
- listOfNeighboors[2]=possibleposition[13]; //north
- listOfNeighboors[3]=possibleposition[12]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[12])){
- listOfNeighboors[1]=possibleposition[11]; //west
- listOfNeighboors[2]=possibleposition[14]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[13])){
- listOfNeighboors[0]=possibleposition[11]; //south
- listOfNeighboors[1]=possibleposition[61]; //west
- listOfNeighboors[2]=possibleposition[16]; //north
- listOfNeighboors[3]=possibleposition[14]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[14])){
- listOfNeighboors[0]=possibleposition[12]; //south
- listOfNeighboors[1]=possibleposition[13]; //west
- listOfNeighboors[2]=possibleposition[15]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[15])){
- listOfNeighboors[0]=possibleposition[14]; //south
- listOfNeighboors[1]=possibleposition[16]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[16])){
- listOfNeighboors[0]=possibleposition[13]; //south
- listOfNeighboors[1]=possibleposition[62]; //west
- listOfNeighboors[2]=possibleposition[15]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[17])){
- listOfNeighboors[0]=possibleposition[0]; //south
- listOfNeighboors[3]=possibleposition[25]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[18])){
- listOfNeighboors[0]=possibleposition[19]; //south
- listOfNeighboors[1]=possibleposition[24]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[19])){
- listOfNeighboors[1]=possibleposition[20]; //west
- listOfNeighboors[2]=possibleposition[18]; //north
- listOfNeighboors[3]=possibleposition[0]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[20])){
- listOfNeighboors[2]=possibleposition[21]; //north
- listOfNeighboors[3]=possibleposition[19]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[21])){
- listOfNeighboors[0]=possibleposition[20]; //south
- listOfNeighboors[3]=possibleposition[22]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[22])){
- listOfNeighboors[1]=possibleposition[21]; //west
- listOfNeighboors[2]=possibleposition[31]; //north
- listOfNeighboors[3]=possibleposition[23]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[23])){
- listOfNeighboors[1]=possibleposition[22]; //west
- listOfNeighboors[2]=possibleposition[30]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[24])){
- listOfNeighboors[2]=possibleposition[29]; //north
- listOfNeighboors[3]=possibleposition[18]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[25])){
- listOfNeighboors[1]=possibleposition[17]; //west
- listOfNeighboors[2]=possibleposition[26]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[26])){
- listOfNeighboors[0]=possibleposition[25]; //south
- listOfNeighboors[1]=possibleposition[27]; //west
- listOfNeighboors[3]=possibleposition[6]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[27])){
- listOfNeighboors[1]=possibleposition[28]; //west
- listOfNeighboors[2]=possibleposition[37]; //north
- listOfNeighboors[3]=possibleposition[26]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[28])){
- listOfNeighboors[1]=possibleposition[29]; //west
- listOfNeighboors[2]=possibleposition[36]; //north
- listOfNeighboors[3]=possibleposition[27]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[29])){
- listOfNeighboors[0]=possibleposition[24]; //south
- listOfNeighboors[1]=possibleposition[30]; //west
- listOfNeighboors[3]=possibleposition[28]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[30])){
- listOfNeighboors[0]=possibleposition[23]; //south
- listOfNeighboors[2]=possibleposition[34]; //north
- listOfNeighboors[3]=possibleposition[29]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[31])){
- listOfNeighboors[0]=possibleposition[22]; //south
- listOfNeighboors[1]=possibleposition[32]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[32])){
- listOfNeighboors[2]=possibleposition[33]; //north
- listOfNeighboors[3]=possibleposition[31]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[33])){
- listOfNeighboors[0]=possibleposition[32]; //south
- listOfNeighboors[3]=possibleposition[34]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[34])){
- listOfNeighboors[0]=possibleposition[30]; //south
- listOfNeighboors[1]=possibleposition[33]; //west
- listOfNeighboors[2]=possibleposition[92]; //north
- listOfNeighboors[3]=possibleposition[35]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[35])){
- listOfNeighboors[1]=possibleposition[34]; //west
- listOfNeighboors[2]=possibleposition[91]; //north
- listOfNeighboors[3]=possibleposition[36]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[36])){
- listOfNeighboors[0]=possibleposition[28]; //south
- listOfNeighboors[1]=possibleposition[35]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[37])){
- listOfNeighboors[0]=possibleposition[27]; //south
- listOfNeighboors[3]=possibleposition[38]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[38])){
- listOfNeighboors[1]=possibleposition[37]; //west
- listOfNeighboors[2]=possibleposition[39]; //north
- listOfNeighboors[3]=possibleposition[9]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[39])){
- listOfNeighboors[0]=possibleposition[38]; //south
- listOfNeighboors[1]=possibleposition[40]; //west
- listOfNeighboors[2]=possibleposition[45]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[40])){
- listOfNeighboors[1]=possibleposition[41]; //west
- //Not return in center
- listOfNeighboors[3]=possibleposition[39]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[41])){
- listOfNeighboors[0]=possibleposition[35]; //south
- listOfNeighboors[2]=possibleposition[43]; //north
- listOfNeighboors[3]=possibleposition[40]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[42])){
- listOfNeighboors[0]=possibleposition[39]; //south
- listOfNeighboors[2]=possibleposition[59]; //north
- listOfNeighboors[3]=possibleposition[43]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[43])){
- listOfNeighboors[0]=possibleposition[41]; //south
- listOfNeighboors[1]=possibleposition[42]; //west
- listOfNeighboors[2]=possibleposition[46]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[44])){
- listOfNeighboors[0]=possibleposition[40]; //south
- listOfNeighboors[2]=possibleposition[66]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[45])){
- listOfNeighboors[0]=possibleposition[39]; //south
- listOfNeighboors[2]=possibleposition[49]; //north
- listOfNeighboors[3]=possibleposition[10]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[46])){
- listOfNeighboors[0]=possibleposition[43]; //south
- listOfNeighboors[3]=possibleposition[47]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[47])){
- listOfNeighboors[1]=possibleposition[46]; //west
- listOfNeighboors[2]=possibleposition[52]; //north
- listOfNeighboors[3]=possibleposition[66]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[48])){
- listOfNeighboors[1]=possibleposition[66]; //west
- listOfNeighboors[2]=possibleposition[51]; //north
- listOfNeighboors[3]=possibleposition[49]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[49])){
- listOfNeighboors[0]=possibleposition[45]; //south
- listOfNeighboors[1]=possibleposition[48]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[50])){
- listOfNeighboors[1]=possibleposition[51]; //west
- listOfNeighboors[2]=possibleposition[61]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[51])){
- listOfNeighboors[0]=possibleposition[48]; //south
- listOfNeighboors[3]=possibleposition[50]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[52])){
- listOfNeighboors[0]=possibleposition[47]; //south
- listOfNeighboors[1]=possibleposition[53]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[53])){
- listOfNeighboors[2]=possibleposition[58]; //north
- listOfNeighboors[3]=possibleposition[52]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[54])){
- listOfNeighboors[0]=possibleposition[42]; //south
- listOfNeighboors[1]=possibleposition[55]; //west
- listOfNeighboors[2]=possibleposition[57]; //north
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[55])){
- listOfNeighboors[2]=possibleposition[56]; //north
- listOfNeighboors[3]=possibleposition[54]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[56])){
- listOfNeighboors[0]=possibleposition[55]; //south
- listOfNeighboors[2]=possibleposition[65]; //north
- listOfNeighboors[3]=possibleposition[57]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[57])){
- listOfNeighboors[0]=possibleposition[54]; //south
- listOfNeighboors[1]=possibleposition[56]; //west
- listOfNeighboors[2]=possibleposition[64]; //north
- listOfNeighboors[3]=possibleposition[58]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[58])){
- listOfNeighboors[0]=possibleposition[53]; //south
- listOfNeighboors[1]=possibleposition[57]; //west
- listOfNeighboors[3]=possibleposition[59]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[59])){
- listOfNeighboors[1]=possibleposition[58]; //west
- listOfNeighboors[2]=possibleposition[63]; //north
- listOfNeighboors[3]=possibleposition[60]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[60])){
- listOfNeighboors[1]=possibleposition[59]; //west
- listOfNeighboors[2]=possibleposition[62]; //north
- listOfNeighboors[3]=possibleposition[61]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[61])){
- listOfNeighboors[0]=possibleposition[50]; //south
- listOfNeighboors[1]=possibleposition[60]; //west
- listOfNeighboors[3]=possibleposition[13]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[62])){
- listOfNeighboors[0]=possibleposition[60]; //south
- listOfNeighboors[3]=possibleposition[16]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[63])){
- listOfNeighboors[0]=possibleposition[59]; //south
- listOfNeighboors[1]=possibleposition[64]; //west
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[64])){
- listOfNeighboors[0]=possibleposition[57]; //south
- listOfNeighboors[1]=possibleposition[65]; //west
- listOfNeighboors[3]=possibleposition[63]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[65])){
- listOfNeighboors[0]=possibleposition[56]; //south
- listOfNeighboors[3]=possibleposition[64]; //east
- return listOfNeighboors[s];
- }
- else if(findpos(pacLasVisPos,possibleposition[66])){
- //Not back in center
- listOfNeighboors[1]=possibleposition[47]; //west
- listOfNeighboors[3]=possibleposition[48]; //east
- return listOfNeighboors[s];
- }
-*/
-
- }
-
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.h 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.h 2019-04-21 21:30:41 UTC (rev 12319)
@@ -17,9 +17,9 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
- void setNewTargetPink(Vector3 goalToGo);
+ //void setNewTargetPink(Vector3 goalToGo);
- void nextMove(Vector3 playerPos, Vector3 redPos);
+ //void nextMove(Vector3 playerPos, Vector3 redPos);
//int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos);
@@ -27,6 +27,10 @@
//Vector3 diffVector (Vector3 start, Vector3 goal);
+ Vector3 pinkPos;
+
+ void nextMove(Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11=Vector3(0,0,0));
+
};
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-21 21:30:41 UTC (rev 12319)
@@ -35,14 +35,10 @@
this->playerPos = _playerPos;
}*/
- bool PacmanRed::jeanfindpos(Vector3 one, Vector3 other){
- if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true;
- return false;
- }
void PacmanRed::tick(float dt)
{
- std::cout<<"LemanExpress5"<<endl;
+ //std::cout<<"LemanExpress5"<<endl;
SUPER(PacmanGhost, tick, dt);
this->actuelposition = this->getPosition();
@@ -68,13 +64,13 @@
//Stop, if target arrived
if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
- std::cout<<"LemanExpress1"<<endl;
+ //std::cout<<"LemanExpress1"<<endl;
this->ismoving = false;
}
//Move, if ghost hasn't arrived yet
if(this->ismoving){
- std::cout<<"LemanExpress2"<<endl;
+ //std::cout<<"LemanExpress2"<<endl;
if(!(abs(this->actuelposition.z-target_z)<0.5)) {
velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
move(dt, actuelposition, velocity);
@@ -83,7 +79,7 @@
velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0);
move(dt, actuelposition, velocity);
}
- std::cout<<"LemanExpress4"<<endl;
+ //std::cout<<"LemanExpress4"<<endl;
}
//Check on which position the ghost has arrived and set new target
@@ -105,20 +101,20 @@
if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
- std::cout<<this->getPlayerPos()<<endl;
+ /*std::cout<<this->getPlayerPos()<<endl;
std::cout<<this->lastPlayerPassedPoint<<endl;
std::cout<<this->pointInFrontOfPlayer<<endl;
- std::cout<<this->actuelposition<<endl;
+ std::cout<<this->actuelposition<<endl;*/
nextMove(redPos, lastPlayerPassedPoint);
std::cout<<"hiuddi"<<endl;
}
else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
- std::cout<<"dhdidjop"<<endl;
+ /*std::cout<<"dhdidjop"<<endl;
std::cout<<this->getPlayerPos()<<endl;
std::cout<<this->lastPlayerPassedPoint<<endl;
std::cout<<this->pointInFrontOfPlayer<<endl;
- std::cout<<this->actuelposition<<endl;
+ std::cout<<this->actuelposition<<endl;*/
nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer);
std::cout<<"ogslodm"<<endl;
@@ -131,14 +127,6 @@
}
- void PacmanRed::setNewTargetRed(Vector3 goalToGo){
-
- this->target_x = goalToGo.x;
- this->target_z = goalToGo.z;
- this->ismoving = true;
- }
-
-
void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
Vector3 nextTarget;
@@ -145,7 +133,7 @@
nextTarget = getShortestPath(redPosP, playerPos);
- setNewTargetRed(nextTarget);
+ setNewTargetGhost(nextTarget);
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-21 17:58:47 UTC (rev 12318)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-21 21:30:41 UTC (rev 12319)
@@ -17,14 +17,10 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
- void setNewTargetRed(Vector3 goalToGo);
-
void nextMove(Vector3 playerPos, Vector3 redPos);
void mainBehaviourRed();
- bool jeanfindpos(Vector3 one, Vector3 other);
-
bool isNearPlayer;
More information about the Orxonox-commit
mailing list