[12304] | 1 | |
---|
| 2 | #include "PacmanBrown.h" |
---|
| 3 | |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
| 5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | namespace orxonox{ |
---|
| 9 | |
---|
| 10 | RegisterClass(PacmanBrown); |
---|
| 11 | |
---|
| 12 | PacmanBrown::PacmanBrown(Context* context) : PacmanGhost(context){ |
---|
| 13 | |
---|
| 14 | RegisterObject(PacmanBrown); |
---|
[12322] | 15 | |
---|
| 16 | this->target_x=0; |
---|
| 17 | this->target_z=15; |
---|
| 18 | this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); |
---|
[12304] | 19 | |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | /** |
---|
| 23 | @brief |
---|
| 24 | Method for creating a ghost through XML. |
---|
| 25 | */ |
---|
| 26 | void PacmanBrown::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 27 | { |
---|
| 28 | SUPER(PacmanBrown, XMLPort, xmlelement, mode); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | |
---|
[12320] | 32 | int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){ |
---|
[12304] | 33 | |
---|
[12320] | 34 | |
---|
[12322] | 35 | Vector3 diffVector; |
---|
[12320] | 36 | diffVector.x=pos2.x-pos1.x; |
---|
| 37 | diffVector.y=pos2.y-pos1.y; //should always be 0 |
---|
| 38 | diffVector.z=pos2.z-pos1.z; |
---|
| 39 | int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z)); |
---|
| 40 | return result; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
[12304] | 44 | void PacmanBrown::tick(float dt) |
---|
| 45 | { |
---|
| 46 | SUPER(PacmanGhost, tick, dt); |
---|
| 47 | |
---|
| 48 | this->actuelposition = this->getPosition(); |
---|
[12322] | 49 | |
---|
| 50 | |
---|
| 51 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
| 52 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
| 53 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
[12304] | 57 | |
---|
| 58 | //Stop, if target arrived |
---|
| 59 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
| 60 | this->ismoving = false; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | //Move, if ghost hasn't arrived yet |
---|
| 64 | if(this->ismoving){ |
---|
| 65 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
| 66 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
| 67 | move(dt, actuelposition, velocity); |
---|
| 68 | } |
---|
| 69 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
| 70 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
| 71 | move(dt, actuelposition, velocity); |
---|
| 72 | } |
---|
| 73 | } |
---|
[12322] | 74 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
| 75 | //as long as the player has not started the game, |
---|
| 76 | //i.e. lastPlayerPastPoint is (0,0,0), brown pacman |
---|
| 77 | //cannot possibly move, because it needs the position |
---|
| 78 | //of the player to move accordingly |
---|
| 79 | |
---|
| 80 | this->ismoving=false; |
---|
| 81 | std::cout<<"weie"<<endl; |
---|
| 82 | } |
---|
[12304] | 83 | |
---|
| 84 | //Check on which position the ghost has arrived and set new target |
---|
| 85 | else{ |
---|
[12322] | 86 | std::cout<<"naye"<<endl; |
---|
[12304] | 87 | while(lockmove){}; |
---|
| 88 | lockmove = true; |
---|
| 89 | |
---|
| 90 | //do brown behavior |
---|
| 91 | //put everything needed here |
---|
| 92 | |
---|
[12320] | 93 | Vector3 brownPos=Vector3(this->target_x, 10, this->target_z); |
---|
[12323] | 94 | std::cout<<brownPos<<endl; |
---|
[12320] | 95 | |
---|
[12323] | 96 | |
---|
| 97 | if(this->isFleeing==true){ |
---|
| 98 | if(findpos(brownPos, Vector3(-215,10,-195))){ |
---|
| 99 | this->isFleeing=false; |
---|
| 100 | //Vector3 nextMoveP = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
| 101 | //this->setNewTargetGhost(nextMoveP); |
---|
| 102 | } |
---|
| 103 | else{ |
---|
| 104 | Vector3 nextMoveP = getShortestPath(brownPos, Vector3(-215,10,-195)); |
---|
| 105 | this->setNewTargetGhost(nextMoveP); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | else { |
---|
| 110 | Vector3 arrayPlaNeig[4]; |
---|
| 111 | |
---|
| 112 | findNeighboorPositions(this->lastPlayerPassedPoint, arrayPlaNeig, possibleposition); |
---|
| 113 | if(isAdjacentToPlayerLastPastPoint(brownPos, arrayPlaNeig)){ |
---|
| 114 | this->isFleeing=true; |
---|
| 115 | } |
---|
| 116 | else{ |
---|
| 117 | Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
| 118 | setNewTargetGhost(nextMove); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | } |
---|
| 122 | std::cout<<this->isFleeing<<endl; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | /*if(absoluteDistance(this->lastPlayerPassedPoint, this->actuelposition)<50){ |
---|
[12320] | 126 | //no idea if 50 is large enough |
---|
| 127 | |
---|
| 128 | //if near player, flee |
---|
| 129 | |
---|
| 130 | this->isFleeing=true; |
---|
| 131 | Vector3 nextMove=getShortestPath( brownPos,Vector3(-215, 10, -195)); |
---|
| 132 | setNewTargetGhost(nextMove); |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | |
---|
[12322] | 136 | else if((this->isFleeing==true)&&(!findpos(brownPos,Vector3(-215,10,-195)))){ |
---|
[12320] | 137 | //if fleeing, continue to flee |
---|
| 138 | Vector3 nextMove = getShortestPath(brownPos, Vector3(-215, 10, -195)); |
---|
| 139 | setNewTargetGhost(nextMove); |
---|
| 140 | } |
---|
[12322] | 141 | else if ((this->isFleeing==true)&&(findpos(brownPos,Vector3(-215,10,-195)))){ |
---|
[12320] | 142 | //if fleeing and reached flee point, go back near player |
---|
| 143 | this->isFleeing=false; |
---|
| 144 | Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
| 145 | setNewTargetGhost(nextMove); |
---|
| 146 | } |
---|
| 147 | else{ |
---|
| 148 | //if not fleeing and not near player, go near player |
---|
| 149 | Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
| 150 | setNewTargetGhost(nextMove); |
---|
| 151 | } |
---|
[12322] | 152 | if(this->isFleeing){ |
---|
| 153 | std::cout<<"fleeing"<<endl; |
---|
| 154 | } |
---|
[12323] | 155 | }*/ |
---|
[12320] | 156 | |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | /*if((this->fleeing==true)&&(this->actuelposition!=(-215,10,-195))){ |
---|
[12304] | 161 | //if fleeing, then go to corner map if not already there |
---|
| 162 | fleeMode(); |
---|
| 163 | } |
---|
| 164 | else{ // else go next to pacman |
---|
| 165 | |
---|
| 166 | if(absoluteDistance(this->pos, player.pos)<10){//no idea if 10 ok |
---|
| 167 | //if near player, flee away |
---|
| 168 | fleemode(); |
---|
| 169 | } |
---|
| 170 | else{ //go to neighboor of player nearest to brown pacman |
---|
| 171 | |
---|
| 172 | //first find nearest neighboor point of player to brown pacman |
---|
| 173 | //we can maybe call getShortestPath recursively to do so |
---|
| 174 | |
---|
| 175 | player.pos.nearestneighboor=findPlayerNeighboorNearestToPacman(player.neighboors); |
---|
| 176 | //btw the array player.neighboor can be defined with a big list as we |
---|
| 177 | //already did several times for similar things |
---|
| 178 | |
---|
| 179 | Vector3 nextMove = getShortestPath(this->actuelposition, player.pos.nearestneighboor); |
---|
| 180 | setNewTargetBrown(nextMove); |
---|
| 181 | } |
---|
| 182 | |
---|
[12320] | 183 | }*/ |
---|
| 184 | lockmove=false; //NEVER FORGET THIS ONE !!! |
---|
[12304] | 185 | |
---|
| 186 | } |
---|
[12323] | 187 | } |
---|
[12304] | 188 | |
---|
| 189 | |
---|
[12322] | 190 | bool PacmanBrown::isAdjacentToPlayerLastPastPoint(Vector3 pacmanBrownPos, Vector3 arrayForNeighborPositions[]){ |
---|
| 191 | //return true if brownPacman is on an adjacent position to the last |
---|
| 192 | //point visited by the player. return false otherwise. |
---|
[12304] | 193 | |
---|
[12322] | 194 | for(int i =0; i < 4; i++){ |
---|
| 195 | if(arrayForNeighborPositions[i]!=Vector3(0,0,0)){ |
---|
| 196 | if(findpos(pacmanBrownPos, arrayForNeighborPositions[i])){ |
---|
| 197 | return true; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | return false; |
---|
| 202 | } |
---|
[12304] | 203 | |
---|
| 204 | |
---|
| 205 | |
---|
[12322] | 206 | void PacmanBrown::findNeighboorPositions(Vector3 actuelposition, Vector3 adjacentPositions[], Vector3 positionArray[]){ |
---|
| 207 | //this function should put in adjacentPosition[] the neighboors of lastPlayerPastPoint |
---|
[12304] | 208 | |
---|
[12322] | 209 | if(findpos(actuelposition,possibleposition[0])){ |
---|
| 210 | |
---|
[12304] | 211 | |
---|
[12322] | 212 | adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]); //need to do it everywhere !!! |
---|
| 213 | adjacentPositions[1]=positionArray[17]; //graphVertex(possibleposition[17]); |
---|
| 214 | adjacentPositions[2]=positionArray[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ? |
---|
| 215 | } |
---|
| 216 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
| 217 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
| 218 | adjacentPositions[1]=positionArray[2]; //graphVertex(possibleposition[2]); |
---|
| 219 | } |
---|
| 220 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
| 221 | adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]); |
---|
| 222 | adjacentPositions[1]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
| 223 | } |
---|
| 224 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
| 225 | adjacentPositions[0]=positionArray[2]; //graphVertex(possibleposition[2]); |
---|
| 226 | adjacentPositions[1]=positionArray[4]; //graphVertex(possibleposition[4]); |
---|
| 227 | adjacentPositions[2]=positionArray[5]; //graphVertex(possibleposition[5]); |
---|
| 228 | } |
---|
| 229 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
| 230 | adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
| 231 | adjacentPositions[1]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
| 232 | } |
---|
| 233 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
| 234 | adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
| 235 | adjacentPositions[1]=positionArray[7]; //graphVertex(possibleposition[7]); |
---|
| 236 | } |
---|
| 237 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
| 238 | adjacentPositions[0]=positionArray[4]; //graphVertex(possibleposition[4]); |
---|
| 239 | adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
| 240 | adjacentPositions[2]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
| 241 | } |
---|
| 242 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
| 243 | adjacentPositions[0]=positionArray[5]; //graphVertex(possibleposition[5]); |
---|
| 244 | adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]); |
---|
| 245 | } |
---|
| 246 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
| 247 | adjacentPositions[0]=positionArray[7]; //graphVertex(possibleposition[7]); |
---|
| 248 | adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
| 249 | } |
---|
| 250 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
| 251 | adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
| 252 | adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]); |
---|
| 253 | adjacentPositions[2]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
| 254 | adjacentPositions[3]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
| 255 | } |
---|
| 256 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
| 257 | adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
| 258 | adjacentPositions[1]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
| 259 | adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
| 260 | } |
---|
| 261 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
| 262 | adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
| 263 | adjacentPositions[1]=positionArray[12]; //graphVertex(possibleposition[12]); |
---|
| 264 | adjacentPositions[2]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
| 265 | } |
---|
| 266 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
| 267 | adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
| 268 | adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
| 269 | } |
---|
| 270 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
| 271 | adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
| 272 | adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
| 273 | adjacentPositions[2]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
| 274 | adjacentPositions[3]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
| 275 | } |
---|
| 276 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
| 277 | adjacentPositions[0]=positionArray[12]; //graphVertex(possibleposition[12]); |
---|
| 278 | adjacentPositions[1]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
| 279 | adjacentPositions[2]=positionArray[15]; //graphVertex(possibleposition[15]); |
---|
| 280 | } |
---|
| 281 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
| 282 | adjacentPositions[0]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
| 283 | adjacentPositions[1]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
| 284 | } |
---|
| 285 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
| 286 | adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
| 287 | adjacentPositions[1]=positionArray[15]; //graphVertex(possibleposition[15]); |
---|
| 288 | adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]); |
---|
| 289 | } |
---|
| 290 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
| 291 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
| 292 | adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]); |
---|
| 293 | } |
---|
| 294 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
| 295 | adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]); |
---|
| 296 | adjacentPositions[1]=positionArray[24]; //graphVertex(possibleposition[24]); |
---|
| 297 | } |
---|
| 298 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
| 299 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
| 300 | adjacentPositions[1]=positionArray[18]; //graphVertex(possibleposition[18]); |
---|
| 301 | adjacentPositions[2]=positionArray[20]; //graphVertex(possibleposition[20]); |
---|
| 302 | } |
---|
| 303 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
| 304 | adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]); |
---|
| 305 | adjacentPositions[1]=positionArray[21]; //graphVertex(possibleposition[21]); |
---|
| 306 | } |
---|
| 307 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
| 308 | adjacentPositions[0]=positionArray[20]; //graphVertex(possibleposition[20]); |
---|
| 309 | adjacentPositions[1]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
| 310 | } |
---|
| 311 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
| 312 | adjacentPositions[0]=positionArray[21]; //graphVertex(possibleposition[21]); |
---|
| 313 | adjacentPositions[1]=positionArray[23]; //graphVertex(possibleposition[23]); |
---|
| 314 | adjacentPositions[2]=positionArray[31]; //graphVertex(possibleposition[31]); |
---|
| 315 | } |
---|
| 316 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
| 317 | adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
| 318 | adjacentPositions[1]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
| 319 | } |
---|
| 320 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
| 321 | adjacentPositions[0]=positionArray[18]; //graphVertex(possibleposition[18]); |
---|
| 322 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
| 323 | } |
---|
| 324 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
| 325 | adjacentPositions[0]=positionArray[17]; //graphVertex(possibleposition[17]); |
---|
| 326 | adjacentPositions[1]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
| 327 | } |
---|
| 328 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
| 329 | adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
| 330 | adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]); |
---|
| 331 | adjacentPositions[2]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
| 332 | } |
---|
| 333 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
| 334 | adjacentPositions[0]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
| 335 | adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
| 336 | adjacentPositions[2]=positionArray[37]; //graphVertex(possibleposition[37]); |
---|
| 337 | } |
---|
| 338 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
| 339 | adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
| 340 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
| 341 | adjacentPositions[2]=positionArray[36]; //graphVertex(possibleposition[36]); |
---|
| 342 | } |
---|
| 343 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
| 344 | adjacentPositions[0]=positionArray[24]; //graphVertex(possibleposition[24]); |
---|
| 345 | adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
| 346 | adjacentPositions[2]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
| 347 | } |
---|
| 348 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
| 349 | adjacentPositions[0]=positionArray[23]; //graphVertex(possibleposition[23]); |
---|
| 350 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
| 351 | adjacentPositions[2]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
| 352 | } |
---|
| 353 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
| 354 | adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
| 355 | adjacentPositions[1]=positionArray[32]; //graphVertex(possibleposition[32]); |
---|
| 356 | } |
---|
| 357 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
| 358 | adjacentPositions[0]=positionArray[31]; //graphVertex(possibleposition[31]); |
---|
| 359 | adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]); |
---|
| 360 | } |
---|
| 361 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
| 362 | adjacentPositions[0]=positionArray[32]; //graphVertex(possibleposition[32]); |
---|
| 363 | adjacentPositions[1]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
| 364 | } |
---|
| 365 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
| 366 | adjacentPositions[0]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
| 367 | adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]); |
---|
| 368 | adjacentPositions[2]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
| 369 | adjacentPositions[3]=positionArray[42]; //graphVertex(possibleposition[42]); |
---|
| 370 | |
---|
| 371 | } |
---|
| 372 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
| 373 | adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
| 374 | adjacentPositions[1]=positionArray[36]; //graphVertex(possibleposition[36]); |
---|
| 375 | adjacentPositions[2]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
| 376 | } |
---|
| 377 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
| 378 | adjacentPositions[0]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
| 379 | adjacentPositions[1]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
| 380 | } |
---|
| 381 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
| 382 | adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
| 383 | adjacentPositions[1]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
| 384 | } |
---|
| 385 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
| 386 | adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
| 387 | adjacentPositions[1]=positionArray[37]; //graphVertex(possibleposition[37]); |
---|
| 388 | adjacentPositions[2]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
| 389 | } |
---|
| 390 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
| 391 | adjacentPositions[0]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
| 392 | adjacentPositions[1]=positionArray[40]; //graphVertex(possibleposition[40]); |
---|
| 393 | adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
| 394 | } |
---|
| 395 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
| 396 | adjacentPositions[0]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
| 397 | adjacentPositions[1]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
| 398 | } |
---|
| 399 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
| 400 | adjacentPositions[0]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
| 401 | adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
| 402 | } |
---|
| 403 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
| 404 | adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
| 405 | adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
| 406 | adjacentPositions[2]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
| 407 | } |
---|
| 408 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
| 409 | adjacentPositions[0]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
| 410 | adjacentPositions[1]=positionArray[46]; //graphVertex(possibleposition[46]); |
---|
| 411 | } |
---|
| 412 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
| 413 | adjacentPositions[0]=positionArray[40]; //graphVertex(possibleposition[40]); |
---|
| 414 | adjacentPositions[1]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
| 415 | } |
---|
| 416 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
| 417 | adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
| 418 | adjacentPositions[1]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
| 419 | adjacentPositions[2]=positionArray[49]; //graphVertex(possibleposition[49]); |
---|
| 420 | } |
---|
| 421 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
| 422 | adjacentPositions[0]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
| 423 | adjacentPositions[1]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
| 424 | } |
---|
| 425 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
| 426 | adjacentPositions[0]=positionArray[46]; //graphVertex(possibleposition[46]); |
---|
| 427 | adjacentPositions[1]=positionArray[52]; //graphVertex(possibleposition[52]); |
---|
| 428 | adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
| 429 | } |
---|
| 430 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
| 431 | adjacentPositions[0]=positionArray[49]; //graphVertex(possibleposition[49]); |
---|
| 432 | adjacentPositions[1]=positionArray[51]; //graphVertex(possibleposition[51]); |
---|
| 433 | adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
| 434 | } |
---|
| 435 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
| 436 | adjacentPositions[0]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
| 437 | adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
| 438 | } |
---|
| 439 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
| 440 | adjacentPositions[0]=positionArray[51]; //graphVertex(possibleposition[51]); |
---|
| 441 | adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
| 442 | } |
---|
| 443 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
| 444 | adjacentPositions[0]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
| 445 | adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]); |
---|
| 446 | } |
---|
| 447 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
| 448 | adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
| 449 | adjacentPositions[1]=positionArray[53]; //graphVertex(possibleposition[53]); |
---|
| 450 | } |
---|
| 451 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
| 452 | adjacentPositions[0]=positionArray[52]; //graphVertex(possibleposition[52]); |
---|
| 453 | adjacentPositions[1]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
| 454 | } |
---|
| 455 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
| 456 | adjacentPositions[0]=positionArray[42]; //graphVertex(possibleposition[42]); |
---|
| 457 | adjacentPositions[1]=positionArray[55]; //graphVertex(possibleposition[55]); |
---|
| 458 | adjacentPositions[2]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
| 459 | } |
---|
| 460 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
| 461 | adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
| 462 | adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
| 463 | } |
---|
| 464 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
| 465 | adjacentPositions[0]=positionArray[55]; //graphVertex(possibleposition[55]); |
---|
| 466 | adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
| 467 | adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]); |
---|
| 468 | } |
---|
| 469 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
| 470 | adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
| 471 | adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
| 472 | adjacentPositions[2]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
| 473 | adjacentPositions[3]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
| 474 | |
---|
| 475 | } |
---|
| 476 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
| 477 | adjacentPositions[0]=positionArray[53]; //graphVertex(possibleposition[53]); |
---|
| 478 | adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
| 479 | adjacentPositions[2]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
| 480 | } |
---|
| 481 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
| 482 | adjacentPositions[0]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
| 483 | adjacentPositions[1]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
| 484 | adjacentPositions[2]=positionArray[63]; //graphVertex(possibleposition[63]); |
---|
| 485 | } |
---|
| 486 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
| 487 | adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
| 488 | adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
| 489 | adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]); |
---|
| 490 | } |
---|
| 491 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
| 492 | adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
| 493 | adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]); |
---|
| 494 | adjacentPositions[2]=positionArray[60]; //graphVertex(possibleposition[60]); |
---|
| 495 | } |
---|
| 496 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
| 497 | adjacentPositions[0]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
| 498 | adjacentPositions[1]=positionArray[60]; //graphVertex(possibleposition[60]); |
---|
| 499 | } |
---|
| 500 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
| 501 | adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
| 502 | adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
| 503 | } |
---|
| 504 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
| 505 | adjacentPositions[0]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
| 506 | adjacentPositions[1]=positionArray[63]; //graphVertex(possibleposition[63]); |
---|
| 507 | adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]); |
---|
| 508 | } |
---|
| 509 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
| 510 | adjacentPositions[0]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
| 511 | adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
| 512 | } |
---|
| 513 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
| 514 | adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
| 515 | adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
| 516 | } |
---|
| 517 | } |
---|
[12304] | 518 | |
---|
| 519 | |
---|
[12320] | 520 | |
---|
[12322] | 521 | } |
---|
[12320] | 522 | |
---|
| 523 | |
---|
| 524 | |
---|
| 525 | |
---|
[12322] | 526 | |
---|
| 527 | |
---|
| 528 | |
---|
| 529 | |
---|
| 530 | |
---|
[12320] | 531 | /*int graphDistance(Vector3 start, Vector3 goal){ |
---|
| 532 | |
---|
[12304] | 533 | Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z)); |
---|
| 534 | |
---|
| 535 | return differenceVector.x+differenceVector.z; |
---|
[12320] | 536 | }*/ |
---|
[12304] | 537 | |
---|
[12320] | 538 | /*void setNewTargetBrown(Vector3 goalToGo){ |
---|
[12304] | 539 | |
---|
| 540 | this->target_x = goalToGo.x; |
---|
| 541 | this->target_z = goalToGo.z; |
---|
| 542 | this->ismoving = true; |
---|
[12320] | 543 | }*/ |
---|
[12304] | 544 | |
---|
| 545 | |
---|
| 546 | |
---|
[12320] | 547 | /*int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){ |
---|
[12304] | 548 | |
---|
| 549 | |
---|
| 550 | Vector3 diffVector; |
---|
| 551 | diffVector.x=pos2-pos1; |
---|
| 552 | diffVector.y=pos2-pos1; //should always be 0 |
---|
| 553 | diffVector.z=pos2-pos1; |
---|
[12320] | 554 | int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z)); |
---|
[12304] | 555 | return result; |
---|
[12320] | 556 | }*/ |
---|
[12304] | 557 | |
---|
| 558 | |
---|
[12320] | 559 | /*void fleeMode(){ //flees to corner of the map |
---|
[12304] | 560 | |
---|
| 561 | Vector3 cornerPos = Vector3(-215,10,-195); //let's take this. We can still change |
---|
| 562 | Vector3 nextMove = getShortestPath(this->actuelposition, cornerPos); |
---|
[12320] | 563 | setNewTargetGhost(nextMove); |
---|
[12304] | 564 | |
---|
[12320] | 565 | //while(this->actuelposition!=cornerPos){ |
---|
[12304] | 566 | |
---|
| 567 | continue moving and each time find next point to go until |
---|
| 568 | we reach the corner |
---|
[12320] | 569 | } |
---|
| 570 | }*/ |
---|
[12304] | 571 | |
---|
| 572 | |
---|
[12320] | 573 | /*Vector3 goAdjacentOfPlayer(Vector neighboorsOfPlayer[]){ |
---|
[12304] | 574 | //find ,nearest to brown, player neighboor |
---|
| 575 | |
---|
| 576 | int besTotDist=-1; |
---|
| 577 | Vector3 curPos=this->pos; |
---|
| 578 | Vector3 predPos; |
---|
| 579 | Vector3 chosenNeighbor; |
---|
| 580 | |
---|
| 581 | for(int i=0; i < 4; i++){ |
---|
| 582 | int totDist=0; |
---|
| 583 | |
---|
| 584 | if(neighboorsOfPlayer[i]!=0){ |
---|
| 585 | while(curPos!=neighboorsOfPlayer[i]){ |
---|
| 586 | |
---|
| 587 | predPos=curPos; |
---|
| 588 | curPos = getShortestPath(curPos, neighboorsOfPlayer[i]); |
---|
| 589 | totDist+=graphDistance(curPos,predPos); |
---|
| 590 | |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | if(besTotDist==-1){ |
---|
| 595 | besTotDist=totDist; |
---|
| 596 | chosenNeighbor=neighboorsOfPlayer[i]; |
---|
| 597 | } |
---|
| 598 | else if(besTotDist>totDist){ |
---|
| 599 | besTotDist=totDist; |
---|
| 600 | chosenNeighbor=neighboorsOfPlayer[i]; |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | return chosenNeighbor; |
---|
| 604 | |
---|
[12320] | 605 | }*/ |
---|
[12304] | 606 | |
---|
| 607 | |
---|
[12320] | 608 | /*Vector3 findPlayerNeighboorNearestToPacman(Vector3 neighboorArray[]){ |
---|
[12304] | 609 | //uh, i think it does the same think as the function above |
---|
| 610 | |
---|
| 611 | Vector3 nextMove; |
---|
| 612 | int distCost=-1; |
---|
| 613 | for(int i=0; i < 4; i++){ |
---|
| 614 | int totDist=0; |
---|
| 615 | Vector3 newCandidate=this->actuelposition; |
---|
| 616 | Vector3 predPos; |
---|
| 617 | |
---|
| 618 | if(neighboorArray[i]!=NULL){ |
---|
| 619 | while(nextMove!=neighboorArray[i]){ |
---|
| 620 | predPos=newCandidate; |
---|
| 621 | newCandidate=getShortestPath(newCandidate, neighboorArray[i]); |
---|
| 622 | totDist+=graphDistance(predPos, newCandidate); |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | if(distCost==-1){ |
---|
| 626 | distCost=totDist; |
---|
| 627 | nextMove=gneighboorArray[i]; |
---|
| 628 | } |
---|
| 629 | else if(totDist<distCost){ |
---|
| 630 | distCost=totDist; |
---|
| 631 | nextMove=neighboorArray[i]; |
---|
| 632 | } |
---|
| 633 | } |
---|
| 634 | } |
---|
| 635 | return nextMove; |
---|
| 636 | |
---|
[12320] | 637 | }*/ |
---|
[12304] | 638 | |
---|
| 639 | |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | |
---|
[12320] | 643 | |
---|