[Orxonox-commit 7696] r12289 - in code/trunk: data/gui/schemes src/modules/pacman
peterf at orxonox.net
peterf at orxonox.net
Thu Apr 11 13:56:32 CEST 2019
Author: peterf
Date: 2019-04-11 13:56:31 +0200 (Thu, 11 Apr 2019)
New Revision: 12289
Added:
code/trunk/src/modules/pacman/PacmanRed.cc
code/trunk/src/modules/pacman/getShortestPath.cc
code/trunk/src/modules/pacman/getShortestPath.h
Modified:
code/trunk/data/gui/schemes/TaharezGreenLook.scheme
code/trunk/src/modules/pacman/CMakeLists.txt
code/trunk/src/modules/pacman/PacmanGhost.h
Log:
Modified: code/trunk/data/gui/schemes/TaharezGreenLook.scheme
===================================================================
--- code/trunk/data/gui/schemes/TaharezGreenLook.scheme 2019-04-11 11:21:49 UTC (rev 12288)
+++ code/trunk/data/gui/schemes/TaharezGreenLook.scheme 2019-04-11 11:56:31 UTC (rev 12289)
@@ -47,4 +47,4 @@
<FalagardMapping lookNFeel="TaharezGreenLook/LargeVerticalScrollbar" renderer="Core/Scrollbar" targetType="CEGUI/Scrollbar" windowType="TaharezGreenLook/LargeVerticalScrollbar" />
<FalagardMapping lookNFeel="TaharezGreenLook/LargeVerticalScrollbarThumb" renderer="Core/Button" targetType="CEGUI/Thumb" windowType="TaharezGreenLook/LargeVerticalScrollbarThumb" />
<FalagardMapping lookNFeel="TaharezGreenLook/JuuButton" renderer="Core/Button" targetType="CEGUI/PushButton" windowType="TaharezGreenLook/JuuButton" />
-</GUIScheme>
\ No newline at end of file
+</GUIScheme>
Modified: code/trunk/src/modules/pacman/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/pacman/CMakeLists.txt 2019-04-11 11:21:49 UTC (rev 12288)
+++ code/trunk/src/modules/pacman/CMakeLists.txt 2019-04-11 11:56:31 UTC (rev 12289)
@@ -5,6 +5,8 @@
PacmanPointSphere.cc
PacmanPointAfraid.cc
PacmanHUDinfo.cc
+ getShortestPath.cc
+
)
ORXONOX_ADD_LIBRARY(pacman
Modified: code/trunk/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/trunk/src/modules/pacman/PacmanGhost.h 2019-04-11 11:21:49 UTC (rev 12288)
+++ code/trunk/src/modules/pacman/PacmanGhost.h 2019-04-11 11:56:31 UTC (rev 12289)
@@ -57,6 +57,7 @@
void changemovability();
bool dontmove = false;
+
private:
int decision = 0;
Vector3 resetposition = Vector3(0,10,15);
Added: code/trunk/src/modules/pacman/PacmanRed.cc
===================================================================
--- code/trunk/src/modules/pacman/PacmanRed.cc (rev 0)
+++ code/trunk/src/modules/pacman/PacmanRed.cc 2019-04-11 11:56:31 UTC (rev 12289)
@@ -0,0 +1,45 @@
+
+ #include "getShortestPath.h"
+ #include "PacmanGhost.h"
+
+
+
+
+ struct PacmanRed(){
+
+ Vector3 nextPos;
+
+ PacmanRed(){
+ nextPos=(0,0,0);
+ }
+
+
+ while(true){
+
+ if(findPos(nextPos, this->pos)){
+ moveToPlayer(this->pos, player->pos);
+ }
+ }
+
+
+ void PacmanRed::moveToPlayer (Vector3 redPos, Vector3 playerPos){
+ //this->pos
+
+ //while(playerPos!=this->pos){}
+
+
+ nextPos=getShortestPath(redPos, playerPos);
+ this->target_x = nextPos.x;
+ this->target_z = nextPos.z;
+ this->ismoving = true;
+
+ /* while(true){
+ if(findPos(this->pos, nextPos))
+ break;
+ }*/
+ }
+
+}
+
+
+
Added: code/trunk/src/modules/pacman/getShortestPath.cc
===================================================================
--- code/trunk/src/modules/pacman/getShortestPath.cc (rev 0)
+++ code/trunk/src/modules/pacman/getShortestPath.cc 2019-04-11 11:56:31 UTC (rev 12289)
@@ -0,0 +1,551 @@
+ #include "core/CoreIncludes.h"
+ #include "core/XMLPort.h"
+ #include "getShortestPath.h"
+
+
+ #include "worldentities/ControllableEntity.h"
+ using namespace std;
+
+ namespace orxonox{
+
+ //Check if there is a collision
+ bool jeanfindpos(Vector3 one, Vector3 other){
+ if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
+ return false;
+ }
+
+ struct graphVertex;
+ void findNeighboorVertices(Vector3 actuelposition, graphVertex adjacentVertices[]);
+ void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor);
+ graphVertex findNextVertexToConsider(graphVertex[]);
+ struct graphVertex {
+
+ Vector3 position;
+ graphVertex *adjacentVertices[4]; //neighbooring vertices
+
+ //would a vector of vector storing the neighboors not be more suitable ?
+
+ int shortestDistanceToStart; //actual shortest distance to start point
+ graphVertex* actuelPredecessor; //the predecessor giving the for now shortest
+ //path to start
+ graphVertex* currentNearestNonVisitedNeighboor;
+ bool alreadyVisited;
+ graphVertex(){ //default constructor
+ position=0;
+ shortestDistanceToStart= std::numeric_limits<int>::max();
+ actuelPredecessor=NULL;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=NULL; //first put all position in array listing neighboors to 0
+ }
+ }
+ graphVertex(Vector3 wantedPosition){ //normal constructor
+ position=wantedPosition;
+ shortestDistanceToStart= std::numeric_limits<int>::max(); //default distance is infinity
+ actuelPredecessor=NULL;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=NULL; //first put all position in array listing neighboors to 0
+ }
+ }
+ graphVertex* operator = (graphVertex *rightSide){
+ this->position=rightSide->position;
+ this->actuelPredecessor=rightSide->actuelPredecessor;
+ return this;
+ }
+
+ };
+
+
+ Vector3 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
+
+
+ if(start==goal){ // basic case
+ return start;
+ }
+
+ //All positions in the map, see documentation
+ Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
+ Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
+ Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
+ Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
+ Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
+ Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
+ Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
+ Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
+ Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
+ Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
+ Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
+ Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
+ Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
+ Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66
+
+ graphVertex listOfVertices[67]= { graphVertex()}; //list of all vertices in the map. // We need graphVertex()
+
+
+ for(int an=0; an < 67; an++){
+ listOfVertices[an]= graphVertex(possibleposition[an]); //same position order as in other file
+ }
+
+ graphVertex actualVertex;
+
+ actualVertex.alreadyVisited=true;
+ actualVertex.shortestDistanceToStart=0;
+ findNeighboorVertices(actualVertex.position, *actualVertex.adjacentVertices);
+ // second parameter is an array !
+
+ while(actualVertex.position!=goal){
+ for(int h=0;h < 4; h++){
+ if(actualVertex.adjacentVertices[h]!=NULL){
+ updateShortestDistanceToStart(actualVertex, *actualVertex.adjacentVertices[h]);
+ } //we "update" the neighboors of our new visited vertex
+ }
+
+
+ actualVertex=findNextVertexToConsider(listOfVertices);
+ actualVertex.alreadyVisited=true;
+ if(actualVertex.position!=goal){
+ findNeighboorVertices(actualVertex.position,*actualVertex.adjacentVertices);
+ //we find the neighboors of our new visited vertex
+ }
+ }
+
+ //we should have reached our goal at this point
+
+ while(actualVertex.actuelPredecessor->actuelPredecessor!=NULL){
+ 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 vertex
+ }
+
+ int graphDistance(Vector3 start, Vector3 goal){
+
+ Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));
+
+ return differenceVector.x+differenceVector.z;
+ }
+
+ void 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(neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart +
+ graphDistance(vertex.position, neighboor.position)){
+
+ neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart +
+ graphDistance(vertex.position, neighboor.position);
+ neighboor.actuelPredecessor = &vertex;
+ }
+ }
+
+ }
+
+ void findNearestNonVisitedNeighboor (graphVertex &vertex){
+ //find nearest non visited neighboor of a given already visited vertex
+ int shortestDistance = -1;
+ graphVertex nearestNonVisitedNeighboor=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]!=NULL)&&(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];
+ }
+ else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){
+ shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);
+ nearestNonVisitedNeighboor=vertex.adjacentVertices[i];
+ }
+ }
+ }
+ vertex.currentNearestNonVisitedNeighboor = &nearestNonVisitedNeighboor;
+ }
+
+
+ graphVertex findNextVertexToConsider(graphVertex listOfVertices[]){ //find next, nearest from start, non visited vertex
+
+ int shortestDistance = -1;
+ graphVertex nextVertexToConsider;
+
+ for(int i=0; i < 67; i++){ //we loop over all possible positions
+
+ if(listOfVertices[i].alreadyVisited==true){ //vertex should already be visited
+
+ findNearestNonVisitedNeighboor(listOfVertices[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(listOfVertices[i].currentNearestNonVisitedNeighboor!=NULL){ //we want a candidate!
+ if(shortestDistance==-1){ //our first possible candidate
+
+ shortestDistance=graphDistance(listOfVertices[i].position,
+ listOfVertices[i].currentNearestNonVisitedNeighboor->position) +
+ listOfVertices[i].shortestDistanceToStart;
+
+ nextVertexToConsider=listOfVertices[i].currentNearestNonVisitedNeighboor;
+
+ }
+ else if(shortestDistance > graphDistance(listOfVertices[i].position,
+ listOfVertices[i].currentNearestNonVisitedNeighboor->position) +
+ listOfVertices[i].shortestDistanceToStart){
+
+ shortestDistance=graphDistance(listOfVertices[i].position,
+ listOfVertices[i].currentNearestNonVisitedNeighboor->position) +
+ listOfVertices[i].shortestDistanceToStart;
+
+ nextVertexToConsider=listOfVertices[i].currentNearestNonVisitedNeighboor;
+ }
+ }
+ }
+ //we want after all to return the nearest non visited neighboor
+ }
+
+ return nextVertexToConsider;
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////
+
+ //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 findNeighboorVertices(Vector3 actuelposition, graphVertex adjacentVertices[]){
+
+ //All positions in the map, see documentation
+ Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4
+ Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9
+ Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14
+ Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19
+ Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24
+ Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29
+ Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34
+ Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39
+ Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44
+ Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49
+ Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54
+ Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59
+ Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64
+ Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66
+
+
+
+
+ if(jeanfindpos(actuelposition,possibleposition[0])){
+ // we should use listOfVertices[i] instead of possibleposition[i] I think
+ // so that all neighboors are "the same"
+ adjacentVertices[0]=graphVertex(possibleposition[1]); //need to do it everywhere !!!
+ adjacentVertices[1]=graphVertex(possibleposition[17]);
+ adjacentVertices[2]=possibleposition[19]; //maybe a vector would be more suitable ?
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[1])){
+ adjacentVertices[0]=possibleposition[0];
+ adjacentVertices[1]=possibleposition[2];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[2])){
+ adjacentVertices[0]=possibleposition[1];
+ adjacentVertices[1]=possibleposition[3];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[3])){
+ adjacentVertices[0]=possibleposition[2];
+ adjacentVertices[1]=possibleposition[4];
+ adjacentVertices[2]=possibleposition[5];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[4])){
+ adjacentVertices[0]=possibleposition[3];
+ adjacentVertices[1]=possibleposition[6];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[5])){
+ adjacentVertices[0]=possibleposition[3];
+ adjacentVertices[1]=possibleposition[7];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[6])){
+ adjacentVertices[0]=possibleposition[4];
+ adjacentVertices[1]=possibleposition[9];
+ adjacentVertices[2]=possibleposition[26];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[7])){
+ adjacentVertices[0]=possibleposition[5];
+ adjacentVertices[1]=possibleposition[8];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[8])){
+ adjacentVertices[0]=possibleposition[7];
+ adjacentVertices[1]=possibleposition[9];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[9])){
+ adjacentVertices[0]=possibleposition[6];
+ adjacentVertices[1]=possibleposition[8];
+ adjacentVertices[2]=possibleposition[10];
+ adjacentVertices[3]=possibleposition[38];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[10])){
+ adjacentVertices[0]=possibleposition[9];
+ adjacentVertices[1]=possibleposition[11];
+ adjacentVertices[2]=possibleposition[45];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[11])){
+ adjacentVertices[0]=possibleposition[10];
+ adjacentVertices[1]=possibleposition[12];
+ adjacentVertices[2]=possibleposition[13];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[12])){
+ adjacentVertices[0]=possibleposition[11];
+ adjacentVertices[1]=possibleposition[14];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[13])){
+ adjacentVertices[0]=possibleposition[11];
+ adjacentVertices[1]=possibleposition[14];
+ adjacentVertices[2]=possibleposition[16];
+ adjacentVertices[3]=possibleposition[61];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[14])){
+ adjacentVertices[0]=possibleposition[12];
+ adjacentVertices[1]=possibleposition[13];
+ adjacentVertices[2]=possibleposition[15];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[15])){
+ adjacentVertices[0]=possibleposition[14];
+ adjacentVertices[1]=possibleposition[16];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[16])){
+ adjacentVertices[0]=possibleposition[13];
+ adjacentVertices[1]=possibleposition[15];
+ adjacentVertices[2]=possibleposition[62];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[17])){
+ adjacentVertices[0]=possibleposition[0];
+ adjacentVertices[1]=possibleposition[25];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[18])){
+ adjacentVertices[0]=possibleposition[19];
+ adjacentVertices[1]=possibleposition[24];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[19])){
+ adjacentVertices[0]=possibleposition[0];
+ adjacentVertices[1]=possibleposition[18];
+ adjacentVertices[2]=possibleposition[20];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[20])){
+ adjacentVertices[0]=possibleposition[19];
+ adjacentVertices[1]=possibleposition[21];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[21])){
+ adjacentVertices[0]=possibleposition[20];
+ adjacentVertices[1]=possibleposition[22];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[22])){
+ adjacentVertices[0]=possibleposition[21];
+ adjacentVertices[1]=possibleposition[23];
+ adjacentVertices[2]=possibleposition[31];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[23])){
+ adjacentVertices[0]=possibleposition[22];
+ adjacentVertices[1]=possibleposition[30];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[24])){
+ adjacentVertices[0]=possibleposition[18];
+ adjacentVertices[1]=possibleposition[29];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[25])){
+ adjacentVertices[0]=possibleposition[17];
+ adjacentVertices[1]=possibleposition[26];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[26])){
+ adjacentVertices[0]=possibleposition[6];
+ adjacentVertices[1]=possibleposition[25];
+ adjacentVertices[2]=possibleposition[27];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[27])){
+ adjacentVertices[0]=possibleposition[26];
+ adjacentVertices[1]=possibleposition[28];
+ adjacentVertices[2]=possibleposition[37];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[28])){
+ adjacentVertices[0]=possibleposition[27];
+ adjacentVertices[1]=possibleposition[29];
+ adjacentVertices[2]=possibleposition[36];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[29])){
+ adjacentVertices[0]=possibleposition[24];
+ adjacentVertices[1]=possibleposition[28];
+ adjacentVertices[2]=possibleposition[30];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[30])){
+ adjacentVertices[0]=possibleposition[23];
+ adjacentVertices[1]=possibleposition[29];
+ adjacentVertices[2]=possibleposition[34];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[31])){
+ adjacentVertices[0]=possibleposition[22];
+ adjacentVertices[1]=possibleposition[32];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[32])){
+ adjacentVertices[0]=possibleposition[31];
+ adjacentVertices[1]=possibleposition[33];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[33])){
+ adjacentVertices[0]=possibleposition[32];
+ adjacentVertices[1]=possibleposition[34];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[34])){
+ adjacentVertices[0]=possibleposition[30];
+ adjacentVertices[1]=possibleposition[33];
+ adjacentVertices[2]=possibleposition[35];
+ adjacentVertices[3]=possibleposition[42];
+
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[35])){
+ adjacentVertices[0]=possibleposition[34];
+ adjacentVertices[1]=possibleposition[36];
+ adjacentVertices[2]=possibleposition[41];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[36])){
+ adjacentVertices[0]=possibleposition[28];
+ adjacentVertices[1]=possibleposition[35];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[37])){
+ adjacentVertices[0]=possibleposition[27];
+ adjacentVertices[1]=possibleposition[38];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[38])){
+ adjacentVertices[0]=possibleposition[9];
+ adjacentVertices[1]=possibleposition[37];
+ adjacentVertices[2]=possibleposition[39];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[39])){
+ adjacentVertices[0]=possibleposition[38];
+ adjacentVertices[1]=possibleposition[40];
+ adjacentVertices[2]=possibleposition[45];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[40])){
+ adjacentVertices[0]=possibleposition[39];
+ adjacentVertices[1]=possibleposition[41];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[41])){
+ adjacentVertices[0]=possibleposition[35];
+ adjacentVertices[1]=possibleposition[43];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[42])){
+ adjacentVertices[0]=possibleposition[34];
+ adjacentVertices[1]=possibleposition[43];
+ adjacentVertices[2]=possibleposition[54];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[43])){
+ adjacentVertices[0]=possibleposition[41];
+ adjacentVertices[1]=possibleposition[46];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[44])){
+ adjacentVertices[0]=possibleposition[40];
+ adjacentVertices[1]=possibleposition[66];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[45])){
+ adjacentVertices[0]=possibleposition[10];
+ adjacentVertices[1]=possibleposition[39];
+ adjacentVertices[2]=possibleposition[49];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[46])){
+ adjacentVertices[0]=possibleposition[43];
+ adjacentVertices[1]=possibleposition[47];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[47])){
+ adjacentVertices[0]=possibleposition[46];
+ adjacentVertices[1]=possibleposition[52];
+ adjacentVertices[2]=possibleposition[66];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[48])){
+ adjacentVertices[0]=possibleposition[49];
+ adjacentVertices[1]=possibleposition[51];
+ adjacentVertices[2]=possibleposition[66];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[49])){
+ adjacentVertices[0]=possibleposition[45];
+ adjacentVertices[1]=possibleposition[48];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[50])){
+ adjacentVertices[0]=possibleposition[51];
+ adjacentVertices[1]=possibleposition[61];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[51])){
+ adjacentVertices[0]=possibleposition[48];
+ adjacentVertices[1]=possibleposition[50];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[52])){
+ adjacentVertices[0]=possibleposition[47];
+ adjacentVertices[1]=possibleposition[53];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[53])){
+ adjacentVertices[0]=possibleposition[52];
+ adjacentVertices[1]=possibleposition[58];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[54])){
+ adjacentVertices[0]=possibleposition[42];
+ adjacentVertices[1]=possibleposition[55];
+ adjacentVertices[2]=possibleposition[57];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[55])){
+ adjacentVertices[0]=possibleposition[54];
+ adjacentVertices[1]=possibleposition[56];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[56])){
+ adjacentVertices[0]=possibleposition[55];
+ adjacentVertices[1]=possibleposition[57];
+ adjacentVertices[2]=possibleposition[65];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[57])){
+ adjacentVertices[0]=possibleposition[54];
+ adjacentVertices[1]=possibleposition[56];
+ adjacentVertices[2]=possibleposition[58];
+ adjacentVertices[3]=possibleposition[64];
+
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[58])){
+ adjacentVertices[0]=possibleposition[53];
+ adjacentVertices[1]=possibleposition[57];
+ adjacentVertices[2]=possibleposition[59];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[59])){
+ adjacentVertices[0]=possibleposition[58];
+ adjacentVertices[1]=possibleposition[59];
+ adjacentVertices[2]=possibleposition[63];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[60])){
+ adjacentVertices[0]=possibleposition[59];
+ adjacentVertices[1]=possibleposition[61];
+ adjacentVertices[2]=possibleposition[62];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[61])){
+ adjacentVertices[0]=possibleposition[13];
+ adjacentVertices[1]=possibleposition[50];
+ adjacentVertices[2]=possibleposition[60];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[62])){
+ adjacentVertices[0]=possibleposition[16];
+ adjacentVertices[1]=possibleposition[60];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[63])){
+ adjacentVertices[0]=possibleposition[59];
+ adjacentVertices[1]=possibleposition[64];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[64])){
+ adjacentVertices[0]=possibleposition[57];
+ adjacentVertices[1]=possibleposition[63];
+ adjacentVertices[2]=possibleposition[65];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[65])){
+ adjacentVertices[0]=possibleposition[56];
+ adjacentVertices[1]=possibleposition[64];
+ }
+ else if(jeanfindpos(actuelposition,possibleposition[66])){
+ adjacentVertices[0]=possibleposition[47];
+ adjacentVertices[1]=possibleposition[48];
+ }
+ }
+
+}
\ No newline at end of file
Added: code/trunk/src/modules/pacman/getShortestPath.h
===================================================================
--- code/trunk/src/modules/pacman/getShortestPath.h (rev 0)
+++ code/trunk/src/modules/pacman/getShortestPath.h 2019-04-11 11:56:31 UTC (rev 12289)
@@ -0,0 +1,64 @@
+ #include "core/CoreIncludes.h"
+ #include "core/XMLPort.h"
+ #include "PacmanGhost.h"
+
+ #include "worldentities/ControllableEntity.h"
+ using namespace std;
+
+namespace orxonox
+{
+
+ class getShortestPath
+ {
+
+ public:
+
+ //Check if there is a collision
+ bool jeanfindpos(Vector3 one, Vector3 other){
+ if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true;
+ return false;
+ }
+
+
+ private:
+
+ struct graphVertex;
+
+ void findNeighboorVertices(Vector3 actuelposition, graphVertex adjacentVertices[]);
+
+ struct graphVertex {
+
+ Vector3 position;
+ graphVertex *adjacentVertices[4]; //neighbooring vertices
+
+ //would a vector of vector storing the neighboors not be more suitable ?
+
+ int shortestDistanceToStart; //actual shortest distance to start point
+ graphVertex* actuelPredecessor; //the predecessor giving the for now shortest
+ //path to start
+ graphVertex* currentNearestNonVisitedNeighboor;
+ bool alreadyVisited;
+ graphVertex(){ //default constructor
+ position=0;
+ shortestDistanceToStart= std::numeric_limits<int>::max();
+ actuelPredecessor=NULL;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=NULL; //first put all position in array listing neighboors to 0
+ }
+ }
+ graphVertex(Vector3 wantedPosition){ //normal constructor
+ position=wantedPosition;
+ shortestDistanceToStart= std::numeric_limits<int>::max(); //default distance is infinity
+ actuelPredecessor=NULL;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=NULL; //first put all position in array listing neighboors to 0
+ }
+ }
+ };
+
+ };
+
+}
+
More information about the Orxonox-commit
mailing list