[Orxonox-commit 7723] r12316 - code/branches/3DPacman_FS19/src/modules/pacman
peterf at orxonox.net
peterf at orxonox.net
Sat Apr 20 17:22:52 CEST 2019
Author: peterf
Date: 2019-04-20 17:22:51 +0200 (Sat, 20 Apr 2019)
New Revision: 12316
Modified:
code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc
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/PacmanRandom.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
Log:
Red Pacman seems to work partially
Modified: code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt 2019-04-20 15:22:51 UTC (rev 12316)
@@ -7,7 +7,6 @@
PacmanHUDinfo.cc
PacmanRandom.cc
PacmanRed.cc
- getShortestPath.cc
)
ORXONOX_ADD_LIBRARY(pacman
Modified: code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc 2019-04-20 15:22:51 UTC (rev 12316)
@@ -74,13 +74,15 @@
}
- PacmanGhost* ghosts[4];
+ PacmanGhost* ghosts[8];
void Pacman::tick(float dt)
{
+
SUPER(Pacman, tick, dt);
+
//Needed for gameover
if(deathtime != 0){
dead(dt);
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc 2019-04-20 15:22:51 UTC (rev 12316)
@@ -34,6 +34,54 @@
namespace orxonox
{
+
+ struct PacmanGhost::graphVertex {
+
+ public:
+
+ 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=nullptr;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=nullptr; //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=nullptr;
+ alreadyVisited=false;
+ for(int kl =0; kl <4;kl++){
+ adjacentVertices[kl]=nullptr; //first put all position in array listing neighboors to 0
+ }
+ }
+ graphVertex& operator = (const graphVertex &rightSide){
+ this->position=rightSide.position;
+ this->shortestDistanceToStart=rightSide.shortestDistanceToStart;
+ this->actuelPredecessor=rightSide.actuelPredecessor;
+ this->currentNearestNonVisitedNeighboor=rightSide.currentNearestNonVisitedNeighboor;
+ this->alreadyVisited=rightSide.alreadyVisited;
+
+ return *this;
+ }
+
+ };
+
+
+ static PacmanGhost::graphVertex listOfVertices[67];
+
//Check if there is a collision
bool findpos(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;
@@ -68,6 +116,9 @@
{
RegisterObject(PacmanGhost);
+ //this->pathAlgorithm = new GetShortestPathAlgorithm;
+
+
this->velocity = Vector3(0, 0, 0);
this->setCollisionType(CollisionType::Dynamic);
@@ -80,6 +131,8 @@
this->target_x = actuelposition.x;
this->target_z = actuelposition.z;
+ //this->lastPlayerPassedPoint=Vector3(185,10,150); //no idea what to put
+
}
/**
@@ -88,7 +141,7 @@
*/
PacmanGhost::~PacmanGhost()
{
- // Deletes the controller if the object was initialized and the pointer to the controller is not NULL.
+ // Deletes the controller if the object was initialized and the pointer to the controller is not nullptr.
}
/**
@@ -170,7 +223,7 @@
speed ++;
}
- Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){
+ /*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
@@ -179,7 +232,500 @@
i++;
}
return possibleposition[i];
+ }*/
+
+ Vector3 PacmanGhost::getPlayerPos()
+ {
+ for (PacmanGelb* player : ObjectList<PacmanGelb>())
+ {
+ return player->getWorldPosition();
+ }
+ return Vector3(0,0,0); //default, should not be used
+
}
+
+
+ ///
+ //// getShortestPath /////////
+ ///
+
+
+
+
+ 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]);
+ }
+ }
+
+
}
\ No newline at end of file
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h 2019-04-20 15:22:51 UTC (rev 12316)
@@ -35,6 +35,9 @@
#include "worldentities/ControllableEntity.h"
+#include "Pacman.h"
+#include "GetShortestPathAlgorithm.h"
+
namespace orxonox {
extern Vector3 possibleposition[67];
@@ -42,12 +45,7 @@
extern bool findpos(Vector3 one, Vector3 other);
- struct graphVertex;
- void findNeighboorVertices(Vector3 actuelposition, graphVertex adjacentVertices[]);
- void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor);
- graphVertex findNextVertexToConsider(graphVertex[]);
- extern graphVertex listOfVertices[];
class _OrxonoxExport PacmanGhost : public ControllableEntity
@@ -82,11 +80,38 @@
int target_z = 0;
bool lockmove = false;
- Vector3 getShortestPath(Vector3 start, Vector3 goal);
+ /*Vector3 getShortestPath(Vector3 start, Vector3 goal);
Vector3 setPureArrayPos(Vector3 &posToSet);
- private:
+ */Vector3 getPlayerPos();
+
+ Vector3 playerPos;
+
+ Vector3 lastPlayerPassedPoint;/*
+
+ //Vector3 pathAlgorithm;
+
+ public: //HACK
+
+ struct graphVertex;
+ void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[]);
+ void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor);
+ void findNearestNonVisitedNeighboor (graphVertex &vertex);
+ int graphDistance(Vector3 start, Vector3 goal);
+
+ graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]);*/
+
+ 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[]);
+ Vector3 getShortestPath(Vector3 start, Vector3 goal);
+
+
};
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRandom.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRandom.cc 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRandom.cc 2019-04-20 15:22:51 UTC (rev 12316)
@@ -261,7 +261,7 @@
else{
this->resetGhost(); //Shouldn't happen...
} //End of Position table
- lockmove = false;
+ lockmove = false; //never forget this one !!!!
}
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc 2019-04-20 15:22:51 UTC (rev 12316)
@@ -4,6 +4,8 @@
#include "core/CoreIncludes.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
+
+
namespace orxonox{
RegisterClass(PacmanRed);
@@ -11,6 +13,9 @@
PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){
RegisterObject(PacmanRed);
+ this->target_x=0;
+ this->target_z=15;
+ this->lastPlayerPassedPoint=Vector3(70,10,-135);
}
@@ -24,11 +29,28 @@
SUPER(PacmanRed, XMLPort, xmlelement, mode);
}
+ /*void PacmanRed::setPlayerPos(Vector3 _playerPos)
+ {
+ 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)
{
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)){
@@ -54,16 +76,30 @@
lockmove = true;
//do red behavior
+ //Use target_x and target_z for position of red pacman
- Vector3 purePos = setPureArrayPos(this->actuelposition);
- //find nearest position on the map to red pos if pacman does not move,
- //i.e. reached a point on the map
- //Why not simply use target_x and target_z ??????
+ Vector3 redPos=Vector3(this->target_x, 10, this->target_z);
+ //nextMove(this->getPlayerPos(), redPos);
- nextMove(purePos, player.actuelposition);
- //how do we access the PLAYER variable ??????
- //also, player.lastPassedPoint is maybe better
+ if(this->actuelposition!=lastPlayerPassedPoint){
+ //std::cout<<this->target_x<<" "<<this->target_z<<endl;
+ std::cout<<redPos<<endl;
+ std::cout<<this->lastPlayerPassedPoint<<endl;
+ //getShortestPath(Vector3(-215,10,-195),Vector3(70,10,-135));
+ //getShortestPath(redPos, lastPlayerPassedPoint);
+ nextMove(redPos, lastPlayerPassedPoint);
+ }/*
+ else{// red pacman is at lastPlayerPassedPoint
+ nextMove(this->getPlayerPos(), redPos);
+ }*/
+
+ //setNewTargetRed(Vector3(70,10,-85));
+ //std::cout<<this->target_x<<" "<<target_z<<endl;
+ //std::cout<<"meuh"<<endl;
+ //std::cout<<this->actuelposition;
+
+ lockmove=false; //NEVER FORGET THIS ONE !!!!!!!
}
}
@@ -77,12 +113,13 @@
}
- void PacmanRed::nextMove(Vector3 playerPos, Vector3 redPos){
- Vector3 nextTarget;
+ void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){
+
+ Vector3 nextTarget;
- nextTarget = getShortestPath(playerPos, redPos);
+ nextTarget = getShortestPath(redPosP, playerPos);
- setNewTargetRed(nextTarget);
+ setNewTargetRed(nextTarget);
}
Modified: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-18 14:26:49 UTC (rev 12315)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h 2019-04-20 15:22:51 UTC (rev 12316)
@@ -23,8 +23,10 @@
void mainBehaviourRed();
+ bool jeanfindpos(Vector3 one, Vector3 other);
+
};
}
More information about the Orxonox-commit
mailing list