Changeset 12324 for code/branches/3DPacman_FS19/src/modules
- Timestamp:
- Apr 27, 2019, 4:49:54 PM (6 years ago)
- Location:
- code/branches/3DPacman_FS19/src/modules/pacman
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
r12323 r12324 224 224 } 225 225 226 /*Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){227 //given that the position of a pacman is generally not "neat",228 //we need to set it to the nearest point on the map229 // if the pacman is not moving anymore, i.e. has reached a point230 int i=0;231 while(!(findpos(possibleposition[i], posToSet))){232 i++;233 }234 return possibleposition[i];235 }*/236 237 226 Vector3 PacmanGhost::getPlayerPos() 238 227 { … … 747 736 } 748 737 749 750 751 752 753 /*Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){754 //this function should then somehow produce the algorithm and call all other functions755 //and finally return the best neighboor of the actual position of the pacman756 757 758 graphVertex listOfVerticesM[67]; //our list of all possible graphs759 graphVertex* actualVertex;// = new graphVertex(); //we will walk through the array with a pointer760 761 if(start==goal){ // basic case762 return start;763 }764 765 for(int an=0; an < 67; an++){766 listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file767 if(start==possibleposition[an]){768 actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array769 //cout<<an<<endl;770 }771 }772 773 actualVertex->alreadyVisited=true; //our start point is now visited774 actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0775 findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);776 // second parameter is an array ! //third is our global array777 778 while(actualVertex->position!=goal){779 for(int h=0;h < 4; h++){780 if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex781 782 //h=2 and 3 never reached783 updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]);784 } //we "update" the neighboors of our new visited vertex785 786 }787 788 actualVertex=findNextVertexToConsider(listOfVerticesM);789 actualVertex->alreadyVisited=true;790 //cout<<actualVertex->position<<endl;791 if(actualVertex->position!=goal){792 findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM);793 //we find the neighboors of our new visited vertex794 }795 }796 797 //cout<<"meuejeeke"<<endl; never reached798 799 //we should have reached our goal at this point800 801 while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor802 actualVertex=actualVertex->actuelPredecessor;803 }804 // the predecessor is our starting point, in other words we are now on an805 //adjacent vertex of the start806 807 return actualVertex->position; //we return the position of this - adjacent to start - vertex808 }809 810 //end of getShortestPath811 812 813 int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){814 //cout<<hgj++<<endl;815 Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z));816 817 return differenceVector.x+differenceVector.z;818 }819 820 void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){821 //apply this method to all non visited neighboors of a vertex.822 // This method should always be run on a vertex after we marked it as visited.823 if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors.824 if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&&825 (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart +826 graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case !827 828 neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart +829 graphDistance(vertex.position, neighboor.position);830 neighboor.actuelPredecessor = &vertex;831 }832 }833 }834 835 void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex){836 //find nearest non visited neighboor of a given already visited vertex837 int shortestDistance = -1;838 graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any.839 //Also, if all neighboors are already visited, we return nullptr, i.e. there is no840 //nearest non visited neighboor.841 for(int i=0; i < 4; i++){842 if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)){843 if(shortestDistance==-1){ //(concerns line above) we want a non visited neighboor844 shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);845 nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !846 //cout<<shortestDistance<<endl;847 }848 else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){849 shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position);850 nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses !851 //cout<<(hgj++)%4<<endl;852 }853 }854 }855 vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses !856 //cout<<hgj++<<endl;857 }858 859 860 PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[]){ //find next, nearest from start, non visited vertex in our listOfVertices array861 862 int shortestDistance = -1;863 graphVertex* nextVertexToConsider;864 865 for(int i=0; i < 67; i++){ //we loop over all possible positions866 867 if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited868 869 findNearestNonVisitedNeighboor(listOfVerticesP[i]); //we update nearest neighboor870 //of all visited vertices given that one of the nearest neighboor of a visited871 // vertex is now also visited because it was chosen as next optimal vertex872 873 if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate!874 if(shortestDistance==-1){ //our first possible candidate875 876 shortestDistance=graphDistance(listOfVerticesP[i].position,877 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +878 listOfVerticesP[i].shortestDistanceToStart;879 880 nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;881 //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor882 883 }884 else if(shortestDistance > graphDistance(listOfVerticesP[i].position,885 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +886 listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available887 888 shortestDistance=graphDistance(listOfVerticesP[i].position,889 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) +890 listOfVerticesP[i].shortestDistanceToStart;891 892 nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor;893 //we dont need the & because we are not giving the adress of the array element894 //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor895 }896 }897 }898 //we want after all to return the nearest non visited neighboor899 }900 901 return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array902 }903 904 //////////////////////////////////////////////////////////////////////////////////////////////905 906 //if vertex already visited, call function on it and reapeat until you reach non visited vertex907 // ---> not sure if a good idea because we risk infinite loop908 909 //-215 -185 -135 -70 -20 0 20 70 135 185 215910 911 //-195 -135 -85 -35 15 60 105 150 195 245912 913 void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){914 915 916 if(findpos(actuelposition,possibleposition[0])){917 // we should use listOfVerticesP2[i] instead of possibleposition[i] I think918 // so that all neighboors are "the same"919 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]); //need to do it everywhere !!!920 adjacentVertices[1]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);921 adjacentVertices[2]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ?922 }923 else if(findpos(actuelposition,possibleposition[1])){924 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);925 adjacentVertices[1]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);926 }927 else if(findpos(actuelposition,possibleposition[2])){928 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]);929 adjacentVertices[1]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);930 }931 else if(findpos(actuelposition,possibleposition[3])){932 adjacentVertices[0]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]);933 adjacentVertices[1]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);934 adjacentVertices[2]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);935 }936 else if(findpos(actuelposition,possibleposition[4])){937 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);938 adjacentVertices[1]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);939 }940 else if(findpos(actuelposition,possibleposition[5])){941 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]);942 adjacentVertices[1]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);943 }944 else if(findpos(actuelposition,possibleposition[6])){945 adjacentVertices[0]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]);946 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);947 adjacentVertices[2]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);948 }949 else if(findpos(actuelposition,possibleposition[7])){950 adjacentVertices[0]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]);951 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);952 }953 else if(findpos(actuelposition,possibleposition[8])){954 adjacentVertices[0]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]);955 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);956 }957 else if(findpos(actuelposition,possibleposition[9])){958 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);959 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]);960 adjacentVertices[2]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);961 adjacentVertices[3]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);962 }963 else if(findpos(actuelposition,possibleposition[10])){964 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);965 adjacentVertices[1]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);966 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);967 }968 else if(findpos(actuelposition,possibleposition[11])){969 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);970 adjacentVertices[1]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);971 adjacentVertices[2]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);972 }973 else if(findpos(actuelposition,possibleposition[12])){974 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);975 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);976 }977 else if(findpos(actuelposition,possibleposition[13])){978 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]);979 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);980 adjacentVertices[2]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);981 adjacentVertices[3]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);982 }983 else if(findpos(actuelposition,possibleposition[14])){984 adjacentVertices[0]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]);985 adjacentVertices[1]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);986 adjacentVertices[2]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);987 }988 else if(findpos(actuelposition,possibleposition[15])){989 adjacentVertices[0]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]);990 adjacentVertices[1]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);991 }992 else if(findpos(actuelposition,possibleposition[16])){993 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);994 adjacentVertices[1]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]);995 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);996 }997 else if(findpos(actuelposition,possibleposition[17])){998 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);999 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);1000 }1001 else if(findpos(actuelposition,possibleposition[18])){1002 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);1003 adjacentVertices[1]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);1004 }1005 else if(findpos(actuelposition,possibleposition[19])){1006 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]);1007 adjacentVertices[1]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);1008 adjacentVertices[2]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);1009 }1010 else if(findpos(actuelposition,possibleposition[20])){1011 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]);1012 adjacentVertices[1]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);1013 }1014 else if(findpos(actuelposition,possibleposition[21])){1015 adjacentVertices[0]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]);1016 adjacentVertices[1]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);1017 }1018 else if(findpos(actuelposition,possibleposition[22])){1019 adjacentVertices[0]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]);1020 adjacentVertices[1]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);1021 adjacentVertices[2]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);1022 }1023 else if(findpos(actuelposition,possibleposition[23])){1024 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);1025 adjacentVertices[1]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);1026 }1027 else if(findpos(actuelposition,possibleposition[24])){1028 adjacentVertices[0]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]);1029 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);1030 }1031 else if(findpos(actuelposition,possibleposition[25])){1032 adjacentVertices[0]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]);1033 adjacentVertices[1]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);1034 }1035 else if(findpos(actuelposition,possibleposition[26])){1036 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]);1037 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]);1038 adjacentVertices[2]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);1039 }1040 else if(findpos(actuelposition,possibleposition[27])){1041 adjacentVertices[0]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]);1042 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);1043 adjacentVertices[2]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);1044 }1045 else if(findpos(actuelposition,possibleposition[28])){1046 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);1047 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);1048 adjacentVertices[2]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);1049 }1050 else if(findpos(actuelposition,possibleposition[29])){1051 adjacentVertices[0]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]);1052 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);1053 adjacentVertices[2]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);1054 }1055 else if(findpos(actuelposition,possibleposition[30])){1056 adjacentVertices[0]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]);1057 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]);1058 adjacentVertices[2]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);1059 }1060 else if(findpos(actuelposition,possibleposition[31])){1061 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]);1062 adjacentVertices[1]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);1063 }1064 else if(findpos(actuelposition,possibleposition[32])){1065 adjacentVertices[0]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]);1066 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);1067 }1068 else if(findpos(actuelposition,possibleposition[33])){1069 adjacentVertices[0]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]);1070 adjacentVertices[1]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);1071 }1072 else if(findpos(actuelposition,possibleposition[34])){1073 adjacentVertices[0]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]);1074 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]);1075 adjacentVertices[2]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);1076 adjacentVertices[3]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);1077 1078 }1079 else if(findpos(actuelposition,possibleposition[35])){1080 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);1081 adjacentVertices[1]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]);1082 adjacentVertices[2]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);1083 }1084 else if(findpos(actuelposition,possibleposition[36])){1085 adjacentVertices[0]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]);1086 adjacentVertices[1]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);1087 }1088 else if(findpos(actuelposition,possibleposition[37])){1089 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]);1090 adjacentVertices[1]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);1091 }1092 else if(findpos(actuelposition,possibleposition[38])){1093 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]);1094 adjacentVertices[1]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]);1095 adjacentVertices[2]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);1096 }1097 else if(findpos(actuelposition,possibleposition[39])){1098 adjacentVertices[0]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]);1099 adjacentVertices[1]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);1100 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);1101 }1102 else if(findpos(actuelposition,possibleposition[40])){1103 adjacentVertices[0]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);1104 adjacentVertices[1]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);1105 }1106 else if(findpos(actuelposition,possibleposition[41])){1107 adjacentVertices[0]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]);1108 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);1109 }1110 else if(findpos(actuelposition,possibleposition[42])){1111 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]);1112 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);1113 adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);1114 }1115 else if(findpos(actuelposition,possibleposition[43])){1116 adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]);1117 adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);1118 }1119 else if(findpos(actuelposition,possibleposition[44])){1120 adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]);1121 adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);1122 }1123 else if(findpos(actuelposition,possibleposition[45])){1124 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]);1125 adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]);1126 adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);1127 }1128 else if(findpos(actuelposition,possibleposition[46])){1129 adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]);1130 adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);1131 }1132 else if(findpos(actuelposition,possibleposition[47])){1133 adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]);1134 adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);1135 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);1136 }1137 else if(findpos(actuelposition,possibleposition[48])){1138 adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]);1139 adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);1140 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]);1141 }1142 else if(findpos(actuelposition,possibleposition[49])){1143 adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]);1144 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);1145 }1146 else if(findpos(actuelposition,possibleposition[50])){1147 adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]);1148 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);1149 }1150 else if(findpos(actuelposition,possibleposition[51])){1151 adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);1152 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);1153 }1154 else if(findpos(actuelposition,possibleposition[52])){1155 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);1156 adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);1157 }1158 else if(findpos(actuelposition,possibleposition[53])){1159 adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]);1160 adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);1161 }1162 else if(findpos(actuelposition,possibleposition[54])){1163 adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]);1164 adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);1165 adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);1166 }1167 else if(findpos(actuelposition,possibleposition[55])){1168 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);1169 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);1170 }1171 else if(findpos(actuelposition,possibleposition[56])){1172 adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]);1173 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);1174 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);1175 }1176 else if(findpos(actuelposition,possibleposition[57])){1177 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]);1178 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);1179 adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);1180 adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);1181 1182 }1183 else if(findpos(actuelposition,possibleposition[58])){1184 adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]);1185 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);1186 adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);1187 }1188 else if(findpos(actuelposition,possibleposition[59])){1189 adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]);1190 adjacentVertices[1]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);1191 adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);1192 }1193 else if(findpos(actuelposition,possibleposition[60])){1194 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);1195 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]);1196 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]);1197 }1198 else if(findpos(actuelposition,possibleposition[61])){1199 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]);1200 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]);1201 adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);1202 }1203 else if(findpos(actuelposition,possibleposition[62])){1204 adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]);1205 adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]);1206 }1207 else if(findpos(actuelposition,possibleposition[63])){1208 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]);1209 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);1210 }1211 else if(findpos(actuelposition,possibleposition[64])){1212 adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]);1213 adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]);1214 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]);1215 }1216 else if(findpos(actuelposition,possibleposition[65])){1217 adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]);1218 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]);1219 }1220 else if(findpos(actuelposition,possibleposition[66])){1221 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]);1222 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]);1223 }1224 }*/1225 1226 1227 1228 1229 738 //functions taken from PacmanPink 1230 1231 1232 1233 739 1234 740 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
r12322 r12324 17 17 this->target_z=15; 18 18 this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); 19 this->pointInFrontOfPlayer=Vector3(0,0,0); 19 20 20 21 } … … 38 39 39 40 for(int u=0; u < 67; u++){//always check if player passed a point 40 if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ 41 this->lastPlayerPassedPoint=possibleposition[u];42 41 if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ 42 this->lastPlayerPassedPoint=possibleposition[u]; 43 } 43 44 } 44 45 46 int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); 47 this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); 48 /*std::cout<<this->pointInFrontOfPlayer<<endl; 49 std::cout<<this->lastPlayerPassedPoint<<endl;*/ 45 50 46 51 //Stop, if target arrived … … 68 73 this->ismoving=false; 69 74 } 75 else if(this->pointInFrontOfPlayer==Vector3(0,0,0)){ 76 std::cout<<"arheeuuuu"<<endl; 77 78 Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); 79 80 setNewTargetGhost(getShortestPath(pinkPos, this->lastPlayerPassedPoint)); 81 82 83 } 70 84 //Check on which position the ghost has arrived and set new target 71 85 else{ … … 74 88 75 89 Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); 90 91 //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); 92 //this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); 76 93 77 94 std::cout<<this->lastPlayerPassedPoint<<endl; 78 79 int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());80 this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);81 95 82 96 std::cout<<this->pointInFrontOfPlayer<<endl; … … 84 98 85 99 86 87 /*if(findPos(player.getPos(), player.lastPassedPoint)){88 // if player is on a point, for simplicity go to it89 Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint);90 setNewTargetPink(nextMove);91 }92 93 else{ //if player is not on a point either go to next neighboor, or if no94 //neighboor in player direction available, go to last point passed by player.95 96 int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos());97 //not in other sense!98 99 Vector3[] neighboors;100 findNeighboor(player.lastPassedPoint, neighboors);101 //we need to create function that finds neighboors of player last point102 //We can use and even should use the part of the tick random function103 // that determines the neighboors. But array neighboor should be in form104 // south-west-north-east respectively to array index.105 106 for(int s=0; s < 4; s++){107 //find next neighboor between player and player.lastPassedPoint108 if((neighboors[s]!=NULL)&&(s==dir)){109 if(dir==0){110 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);111 setNewTargetPink(nextMove);112 }113 else if(dir==1){114 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);115 setNewTargetPink(nextMove);116 }117 else if(dir==2){118 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);119 setNewTargetPink(nextMove);120 }121 else{//last is default122 Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]);123 setNewTargetPink(nextMove);124 }125 }126 else{//if no further point after last player point possible127 //then simply go to this last point.128 Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint);129 setNewTargetPink(nextMove);130 }131 132 }133 134 }*/135 100 lockmove=false; 136 101 … … 149 114 Vector3 nextTarget; 150 115 151 nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); 116 if(playerPos==pointToAvoidP11){ 117 nextTarget = getShortestPath(pinkPosP, playerPos); 118 } 119 else{ 120 nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); 121 } 152 122 153 123 setNewTargetGhost(nextTarget);
Note: See TracChangeset
for help on using the changeset viewer.