Changeset 12319 for code/branches/3DPacman_FS19
- Timestamp:
- Apr 21, 2019, 11:30:41 PM (6 years ago)
- Location:
- code/branches/3DPacman_FS19/src/modules/pacman
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
r12316 r12319 8 8 PacmanRandom.cc 9 9 PacmanRed.cc 10 PacmanPink.cc 10 11 ) 11 12 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
r12318 r12319 247 247 248 248 249 bool PacmanGhost::jeanfindpos(Vector3 one, Vector3 other){ 250 if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true; 251 return false; 252 } 253 254 void PacmanGhost::setNewTargetGhost(Vector3 goalToGo){ 255 256 this->target_x = goalToGo.x; 257 this->target_z = goalToGo.z; 258 this->ismoving = true; 259 } 249 260 250 261 … … 255 266 256 267 257 258 Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){ 268 Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1){ 269 //this function should then somehow produce the algorithm and call all other functions 270 //and finally return the best neighboor of the actual position of the pacman 271 272 //(optional parameter) pointToAvoidP1 is a point that cannot be considered 273 274 275 graphVertex listOfVerticesM[67]; //our list of all possible graphs 276 graphVertex* actualVertex; //we will walk through the array with a pointer 277 278 if(start==goal){ // basic case 279 return start; 280 } 281 282 for(int an=0; an < 67; an++){ 283 listOfVerticesM[an]= graphVertex(possibleposition[an]); //same position order as in other file 284 if(start==possibleposition[an]){ 285 actualVertex= &listOfVerticesM[an]; //our pointer points to the graph with position start in array 286 //cout<<an<<endl; 287 } 288 } 289 290 //graphVertex actualVertex= listOfVerticesM[an]; 291 292 actualVertex->alreadyVisited=true; //our start point is now visited 293 actualVertex->shortestDistanceToStart=0; //At our start point, distance from start is 0 294 findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); 295 // second parameter is an array ! //third is our global array 296 297 while(actualVertex->position!=goal){ 298 for(int h=0;h < 4; h++){ 299 if(actualVertex->adjacentVertices[h]!=nullptr){ //check all neighboors of our current graphVertex 300 301 //h=2 and 3 never reached 302 updateShortestDistanceToStart(*actualVertex, *actualVertex->adjacentVertices[h]); 303 } //we "update" the neighboors of our new visited vertex 304 305 } 306 307 actualVertex=findNextVertexToConsider(listOfVerticesM, pointToAvoidP1); 308 actualVertex->alreadyVisited=true; 309 //cout<<actualVertex->position<<endl; 310 if(actualVertex->position!=goal){ 311 findNeighboorVertices(actualVertex->position, actualVertex->adjacentVertices, listOfVerticesM); 312 //we find the neighboors of our new visited vertex 313 } 314 } 315 316 //cout<<"meuejeeke"<<endl; never reached 317 318 //we should have reached our goal at this point 319 320 while(actualVertex->actuelPredecessor->actuelPredecessor!=nullptr){ //the predecessor of our predecessor 321 actualVertex=actualVertex->actuelPredecessor; 322 } 323 // the predecessor is our starting point, in other words we are now on an 324 //adjacent vertex of the start 325 326 return actualVertex->position; //we return the position of this - adjacent to start - vertex 327 } 328 329 //end of getShortestPath 330 331 332 int PacmanGhost::graphDistance(Vector3 start, Vector3 goal){ 333 //cout<<hgj++<<endl; 334 Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z)); 335 336 return differenceVector.x+differenceVector.z; 337 } 338 339 void PacmanGhost::updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor){ 340 //apply this method to all non visited neighboors of a vertex. 341 // This method should always be run on a vertex after we marked it as visited. 342 if(neighboor.alreadyVisited==false){ //we only consider non visited neighboors. 343 if((vertex.shortestDistanceToStart!=std::numeric_limits<int>::max())&& 344 (neighboor.shortestDistanceToStart > vertex.shortestDistanceToStart + 345 graphDistance(vertex.position, neighboor.position))){ //need to consider overflow case ! 346 347 neighboor.shortestDistanceToStart= vertex.shortestDistanceToStart + 348 graphDistance(vertex.position, neighboor.position); 349 neighboor.actuelPredecessor = &vertex; 350 } 351 } 352 } 353 354 void PacmanGhost::findNearestNonVisitedNeighboor (graphVertex &vertex, Vector3 pointToAvoidP3){ 355 //find nearest non visited neighboor of a given already visited vertex 356 //(optional parameter) pointToAvoidP3 is a point that cannot be considered 357 int shortestDistance = -1; 358 graphVertex* nearestNonVisitedNeighboor=nullptr;//=graphVertex(); //by default there is not any. 359 //Also, if all neighboors are already visited, we return NULL, i.e. there is no 360 //nearest non visited neighboor. 361 for(int i=0; i < 4; i++){ 362 if((vertex.adjacentVertices[i]!=nullptr)&&(vertex.adjacentVertices[i]->alreadyVisited==false)&&(vertex.adjacentVertices[i]->position!=pointToAvoidP3)){ 363 if(shortestDistance==-1){ //(concerns line above) we want a non visited neighboor //(optional) if the position of the neighboor is the one we want 364 //to avoid, then we ignore it 365 366 shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position); 367 nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses ! 368 //cout<<shortestDistance<<endl; 369 } 370 else if(graphDistance(vertex.position, vertex.adjacentVertices[i]->position)<shortestDistance){ 371 shortestDistance= graphDistance(vertex.position, vertex.adjacentVertices[i]->position); 372 nearestNonVisitedNeighboor=vertex.adjacentVertices[i]; //warning, both sides are pointer adresses ! 373 //cout<<(hgj++)%4<<endl; 374 } 375 } 376 } 377 vertex.currentNearestNonVisitedNeighboor = nearestNonVisitedNeighboor; //warning, both sides are pointer adresses ! 378 //cout<<hgj++<<endl; 379 } 380 381 382 PacmanGhost::graphVertex* PacmanGhost::findNextVertexToConsider(graphVertex listOfVerticesP[], Vector3 pointToAvoidP2){ //find next, nearest from start, non visited vertex in our listOfVertices array 383 //(optional parameter) pointToAvoidP2 is a point that cannot be considered 384 385 int shortestDistance = -1; 386 graphVertex* nextVertexToConsider; 387 388 for(int i=0; i < 67; i++){ //we loop over all possible positions 389 390 if(listOfVerticesP[i].alreadyVisited==true){ //vertex should already be visited 391 392 findNearestNonVisitedNeighboor(listOfVerticesP[i], pointToAvoidP2); //we update nearest neighboor 393 //of all visited vertices given that one of the nearest neighboor of a visited 394 // vertex is now also visited because it was chosen as next optimal vertex 395 396 if(listOfVerticesP[i].currentNearestNonVisitedNeighboor!=nullptr){ //we want a candidate! 397 if(shortestDistance==-1){ //our first possible candidate 398 399 shortestDistance=graphDistance(listOfVerticesP[i].position, 400 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 401 listOfVerticesP[i].shortestDistanceToStart; 402 403 nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor; 404 //adress of nextVertexToConsider is that of pointer currentNearestNonVisitedNeighboor 405 406 } 407 else if(shortestDistance > graphDistance(listOfVerticesP[i].position, 408 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 409 listOfVerticesP[i].shortestDistanceToStart){//if better candidate than our first candidate available 410 411 shortestDistance=graphDistance(listOfVerticesP[i].position, 412 listOfVerticesP[i].currentNearestNonVisitedNeighboor->position) + 413 listOfVerticesP[i].shortestDistanceToStart; 414 415 nextVertexToConsider=listOfVerticesP[i].currentNearestNonVisitedNeighboor; 416 //we dont need the & because we are not giving the adress of the array element 417 //listOfVerticesP[i] but that of the pointer currentNearestNonVisitedNeighboor 418 } 419 } 420 } 421 //we want after all to return the nearest non visited neighboor 422 } 423 424 return nextVertexToConsider; //returns adress nextVertexToConsider is pointing to in array 425 } 426 427 ////////////////////////////////////////////////////////////////////////////////////////////// 428 429 //if vertex already visited, call function on it and reapeat until you reach non visited vertex 430 // ---> not sure if a good idea because we risk infinite loop 431 432 //-215 -185 -135 -70 -20 0 20 70 135 185 215 433 434 //-195 -135 -85 -35 15 60 105 150 195 245 435 436 void PacmanGhost::findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]){ 437 438 439 if(findpos(actuelposition,possibleposition[0])){ 440 // we should use listOfVerticesP2[i] instead of possibleposition[i] I think 441 // so that all neighboors are "the same" 442 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]); //need to do it everywhere !!! 443 adjacentVertices[1]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]); 444 adjacentVertices[2]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ? 445 } 446 else if(findpos(actuelposition,possibleposition[1])){ 447 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]); 448 adjacentVertices[1]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]); 449 } 450 else if(findpos(actuelposition,possibleposition[2])){ 451 adjacentVertices[0]=&listOfVerticesP2[1]; //graphVertex(possibleposition[1]); 452 adjacentVertices[1]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]); 453 } 454 else if(findpos(actuelposition,possibleposition[3])){ 455 adjacentVertices[0]=&listOfVerticesP2[2]; //graphVertex(possibleposition[2]); 456 adjacentVertices[1]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]); 457 adjacentVertices[2]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]); 458 } 459 else if(findpos(actuelposition,possibleposition[4])){ 460 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]); 461 adjacentVertices[1]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]); 462 } 463 else if(findpos(actuelposition,possibleposition[5])){ 464 adjacentVertices[0]=&listOfVerticesP2[3]; //graphVertex(possibleposition[3]); 465 adjacentVertices[1]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]); 466 } 467 else if(findpos(actuelposition,possibleposition[6])){ 468 adjacentVertices[0]=&listOfVerticesP2[4]; //graphVertex(possibleposition[4]); 469 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]); 470 adjacentVertices[2]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]); 471 } 472 else if(findpos(actuelposition,possibleposition[7])){ 473 adjacentVertices[0]=&listOfVerticesP2[5]; //graphVertex(possibleposition[5]); 474 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]); 475 } 476 else if(findpos(actuelposition,possibleposition[8])){ 477 adjacentVertices[0]=&listOfVerticesP2[7]; //graphVertex(possibleposition[7]); 478 adjacentVertices[1]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]); 479 } 480 else if(findpos(actuelposition,possibleposition[9])){ 481 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]); 482 adjacentVertices[1]=&listOfVerticesP2[8]; //graphVertex(possibleposition[8]); 483 adjacentVertices[2]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]); 484 adjacentVertices[3]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]); 485 } 486 else if(findpos(actuelposition,possibleposition[10])){ 487 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]); 488 adjacentVertices[1]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]); 489 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]); 490 } 491 else if(findpos(actuelposition,possibleposition[11])){ 492 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]); 493 adjacentVertices[1]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]); 494 adjacentVertices[2]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]); 495 } 496 else if(findpos(actuelposition,possibleposition[12])){ 497 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]); 498 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]); 499 } 500 else if(findpos(actuelposition,possibleposition[13])){ 501 adjacentVertices[0]=&listOfVerticesP2[11]; //graphVertex(possibleposition[11]); 502 adjacentVertices[1]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]); 503 adjacentVertices[2]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]); 504 adjacentVertices[3]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]); 505 } 506 else if(findpos(actuelposition,possibleposition[14])){ 507 adjacentVertices[0]=&listOfVerticesP2[12]; //graphVertex(possibleposition[12]); 508 adjacentVertices[1]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]); 509 adjacentVertices[2]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]); 510 } 511 else if(findpos(actuelposition,possibleposition[15])){ 512 adjacentVertices[0]=&listOfVerticesP2[14]; //graphVertex(possibleposition[14]); 513 adjacentVertices[1]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]); 514 } 515 else if(findpos(actuelposition,possibleposition[16])){ 516 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]); 517 adjacentVertices[1]=&listOfVerticesP2[15]; //graphVertex(possibleposition[15]); 518 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]); 519 } 520 else if(findpos(actuelposition,possibleposition[17])){ 521 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]); 522 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]); 523 } 524 else if(findpos(actuelposition,possibleposition[18])){ 525 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); 526 adjacentVertices[1]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]); 527 } 528 else if(findpos(actuelposition,possibleposition[19])){ 529 adjacentVertices[0]=&listOfVerticesP2[0]; //graphVertex(possibleposition[0]); 530 adjacentVertices[1]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]); 531 adjacentVertices[2]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]); 532 } 533 else if(findpos(actuelposition,possibleposition[20])){ 534 adjacentVertices[0]=&listOfVerticesP2[19]; //graphVertex(possibleposition[19]); 535 adjacentVertices[1]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]); 536 } 537 else if(findpos(actuelposition,possibleposition[21])){ 538 adjacentVertices[0]=&listOfVerticesP2[20]; //graphVertex(possibleposition[20]); 539 adjacentVertices[1]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]); 540 } 541 else if(findpos(actuelposition,possibleposition[22])){ 542 adjacentVertices[0]=&listOfVerticesP2[21]; //graphVertex(possibleposition[21]); 543 adjacentVertices[1]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]); 544 adjacentVertices[2]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]); 545 } 546 else if(findpos(actuelposition,possibleposition[23])){ 547 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]); 548 adjacentVertices[1]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]); 549 } 550 else if(findpos(actuelposition,possibleposition[24])){ 551 adjacentVertices[0]=&listOfVerticesP2[18]; //graphVertex(possibleposition[18]); 552 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]); 553 } 554 else if(findpos(actuelposition,possibleposition[25])){ 555 adjacentVertices[0]=&listOfVerticesP2[17]; //graphVertex(possibleposition[17]); 556 adjacentVertices[1]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]); 557 } 558 else if(findpos(actuelposition,possibleposition[26])){ 559 adjacentVertices[0]=&listOfVerticesP2[6]; //graphVertex(possibleposition[6]); 560 adjacentVertices[1]=&listOfVerticesP2[25]; //graphVertex(possibleposition[25]); 561 adjacentVertices[2]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]); 562 } 563 else if(findpos(actuelposition,possibleposition[27])){ 564 adjacentVertices[0]=&listOfVerticesP2[26]; //graphVertex(possibleposition[26]); 565 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]); 566 adjacentVertices[2]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]); 567 } 568 else if(findpos(actuelposition,possibleposition[28])){ 569 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]); 570 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]); 571 adjacentVertices[2]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]); 572 } 573 else if(findpos(actuelposition,possibleposition[29])){ 574 adjacentVertices[0]=&listOfVerticesP2[24]; //graphVertex(possibleposition[24]); 575 adjacentVertices[1]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]); 576 adjacentVertices[2]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]); 577 } 578 else if(findpos(actuelposition,possibleposition[30])){ 579 adjacentVertices[0]=&listOfVerticesP2[23]; //graphVertex(possibleposition[23]); 580 adjacentVertices[1]=&listOfVerticesP2[29]; //graphVertex(possibleposition[29]); 581 adjacentVertices[2]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]); 582 } 583 else if(findpos(actuelposition,possibleposition[31])){ 584 adjacentVertices[0]=&listOfVerticesP2[22]; //graphVertex(possibleposition[22]); 585 adjacentVertices[1]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]); 586 } 587 else if(findpos(actuelposition,possibleposition[32])){ 588 adjacentVertices[0]=&listOfVerticesP2[31]; //graphVertex(possibleposition[31]); 589 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]); 590 } 591 else if(findpos(actuelposition,possibleposition[33])){ 592 adjacentVertices[0]=&listOfVerticesP2[32]; //graphVertex(possibleposition[32]); 593 adjacentVertices[1]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]); 594 } 595 else if(findpos(actuelposition,possibleposition[34])){ 596 adjacentVertices[0]=&listOfVerticesP2[30]; //graphVertex(possibleposition[30]); 597 adjacentVertices[1]=&listOfVerticesP2[33]; //graphVertex(possibleposition[33]); 598 adjacentVertices[2]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]); 599 adjacentVertices[3]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]); 600 601 } 602 else if(findpos(actuelposition,possibleposition[35])){ 603 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]); 604 adjacentVertices[1]=&listOfVerticesP2[36]; //graphVertex(possibleposition[36]); 605 adjacentVertices[2]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]); 606 } 607 else if(findpos(actuelposition,possibleposition[36])){ 608 adjacentVertices[0]=&listOfVerticesP2[28]; //graphVertex(possibleposition[28]); 609 adjacentVertices[1]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]); 610 } 611 else if(findpos(actuelposition,possibleposition[37])){ 612 adjacentVertices[0]=&listOfVerticesP2[27]; //graphVertex(possibleposition[27]); 613 adjacentVertices[1]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]); 614 } 615 else if(findpos(actuelposition,possibleposition[38])){ 616 adjacentVertices[0]=&listOfVerticesP2[9]; //graphVertex(possibleposition[9]); 617 adjacentVertices[1]=&listOfVerticesP2[37]; //graphVertex(possibleposition[37]); 618 adjacentVertices[2]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]); 619 } 620 else if(findpos(actuelposition,possibleposition[39])){ 621 adjacentVertices[0]=&listOfVerticesP2[38]; //graphVertex(possibleposition[38]); 622 adjacentVertices[1]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]); 623 adjacentVertices[2]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]); 624 } 625 else if(findpos(actuelposition,possibleposition[40])){ 626 adjacentVertices[0]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]); 627 adjacentVertices[1]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]); 628 } 629 else if(findpos(actuelposition,possibleposition[41])){ 630 adjacentVertices[0]=&listOfVerticesP2[35]; //graphVertex(possibleposition[35]); 631 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]); 632 } 633 else if(findpos(actuelposition,possibleposition[42])){ 634 adjacentVertices[0]=&listOfVerticesP2[34]; //graphVertex(possibleposition[34]); 635 adjacentVertices[1]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]); 636 adjacentVertices[2]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]); 637 } 638 else if(findpos(actuelposition,possibleposition[43])){ 639 adjacentVertices[0]=&listOfVerticesP2[41]; //graphVertex(possibleposition[41]); 640 adjacentVertices[1]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]); 641 } 642 else if(findpos(actuelposition,possibleposition[44])){ 643 adjacentVertices[0]=&listOfVerticesP2[40]; //graphVertex(possibleposition[40]); 644 adjacentVertices[1]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]); 645 } 646 else if(findpos(actuelposition,possibleposition[45])){ 647 adjacentVertices[0]=&listOfVerticesP2[10]; //graphVertex(possibleposition[10]); 648 adjacentVertices[1]=&listOfVerticesP2[39]; //graphVertex(possibleposition[39]); 649 adjacentVertices[2]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]); 650 } 651 else if(findpos(actuelposition,possibleposition[46])){ 652 adjacentVertices[0]=&listOfVerticesP2[43]; //graphVertex(possibleposition[43]); 653 adjacentVertices[1]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]); 654 } 655 else if(findpos(actuelposition,possibleposition[47])){ 656 adjacentVertices[0]=&listOfVerticesP2[46]; //graphVertex(possibleposition[46]); 657 adjacentVertices[1]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]); 658 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]); 659 } 660 else if(findpos(actuelposition,possibleposition[48])){ 661 adjacentVertices[0]=&listOfVerticesP2[49]; //graphVertex(possibleposition[49]); 662 adjacentVertices[1]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]); 663 adjacentVertices[2]=&listOfVerticesP2[66]; //graphVertex(possibleposition[66]); 664 } 665 else if(findpos(actuelposition,possibleposition[49])){ 666 adjacentVertices[0]=&listOfVerticesP2[45]; //graphVertex(possibleposition[45]); 667 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]); 668 } 669 else if(findpos(actuelposition,possibleposition[50])){ 670 adjacentVertices[0]=&listOfVerticesP2[51]; //graphVertex(possibleposition[51]); 671 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]); 672 } 673 else if(findpos(actuelposition,possibleposition[51])){ 674 adjacentVertices[0]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]); 675 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]); 676 } 677 else if(findpos(actuelposition,possibleposition[52])){ 678 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]); 679 adjacentVertices[1]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]); 680 } 681 else if(findpos(actuelposition,possibleposition[53])){ 682 adjacentVertices[0]=&listOfVerticesP2[52]; //graphVertex(possibleposition[52]); 683 adjacentVertices[1]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]); 684 } 685 else if(findpos(actuelposition,possibleposition[54])){ 686 adjacentVertices[0]=&listOfVerticesP2[42]; //graphVertex(possibleposition[42]); 687 adjacentVertices[1]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]); 688 adjacentVertices[2]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]); 689 } 690 else if(findpos(actuelposition,possibleposition[55])){ 691 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]); 692 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]); 693 } 694 else if(findpos(actuelposition,possibleposition[56])){ 695 adjacentVertices[0]=&listOfVerticesP2[55]; //graphVertex(possibleposition[55]); 696 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]); 697 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]); 698 } 699 else if(findpos(actuelposition,possibleposition[57])){ 700 adjacentVertices[0]=&listOfVerticesP2[54]; //graphVertex(possibleposition[54]); 701 adjacentVertices[1]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]); 702 adjacentVertices[2]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]); 703 adjacentVertices[3]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]); 704 705 } 706 else if(findpos(actuelposition,possibleposition[58])){ 707 adjacentVertices[0]=&listOfVerticesP2[53]; //graphVertex(possibleposition[53]); 708 adjacentVertices[1]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]); 709 adjacentVertices[2]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]); 710 } 711 else if(findpos(actuelposition,possibleposition[59])){ 712 adjacentVertices[0]=&listOfVerticesP2[58]; //graphVertex(possibleposition[58]); 713 adjacentVertices[1]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]); 714 adjacentVertices[2]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]); 715 } 716 else if(findpos(actuelposition,possibleposition[60])){ 717 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]); 718 adjacentVertices[1]=&listOfVerticesP2[61]; //graphVertex(possibleposition[61]); 719 adjacentVertices[2]=&listOfVerticesP2[62]; //graphVertex(possibleposition[62]); 720 } 721 else if(findpos(actuelposition,possibleposition[61])){ 722 adjacentVertices[0]=&listOfVerticesP2[13]; //graphVertex(possibleposition[13]); 723 adjacentVertices[1]=&listOfVerticesP2[50]; //graphVertex(possibleposition[50]); 724 adjacentVertices[2]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]); 725 } 726 else if(findpos(actuelposition,possibleposition[62])){ 727 adjacentVertices[0]=&listOfVerticesP2[16]; //graphVertex(possibleposition[16]); 728 adjacentVertices[1]=&listOfVerticesP2[60]; //graphVertex(possibleposition[60]); 729 } 730 else if(findpos(actuelposition,possibleposition[63])){ 731 adjacentVertices[0]=&listOfVerticesP2[59]; //graphVertex(possibleposition[59]); 732 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]); 733 } 734 else if(findpos(actuelposition,possibleposition[64])){ 735 adjacentVertices[0]=&listOfVerticesP2[57]; //graphVertex(possibleposition[57]); 736 adjacentVertices[1]=&listOfVerticesP2[63]; //graphVertex(possibleposition[63]); 737 adjacentVertices[2]=&listOfVerticesP2[65]; //graphVertex(possibleposition[65]); 738 } 739 else if(findpos(actuelposition,possibleposition[65])){ 740 adjacentVertices[0]=&listOfVerticesP2[56]; //graphVertex(possibleposition[56]); 741 adjacentVertices[1]=&listOfVerticesP2[64]; //graphVertex(possibleposition[64]); 742 } 743 else if(findpos(actuelposition,possibleposition[66])){ 744 adjacentVertices[0]=&listOfVerticesP2[47]; //graphVertex(possibleposition[47]); 745 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]); 746 } 747 } 748 749 750 751 752 753 /*Vector3 PacmanGhost::getShortestPath(Vector3 start, Vector3 goal){ 259 754 //this function should then somehow produce the algorithm and call all other functions 260 755 //and finally return the best neighboor of the actual position of the pacman … … 727 1222 adjacentVertices[1]=&listOfVerticesP2[48]; //graphVertex(possibleposition[48]); 728 1223 } 729 } 1224 }*/ 730 1225 731 1226 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
r12318 r12319 99 99 public: //HACK 100 100 101 struct graphVertex; 102 void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[]); 103 void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor); 104 void findNearestNonVisitedNeighboor (graphVertex &vertex); 105 int graphDistance(Vector3 start, Vector3 goal); 101 */ 106 102 107 graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]);*/ 108 109 struct graphVertex; 103 /*struct graphVertex; 110 104 void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]); 111 105 void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor); … … 114 108 115 109 graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[]); 116 Vector3 getShortestPath(Vector3 start, Vector3 goal); 110 Vector3 getShortestPath(Vector3 start, Vector3 goal);*/ 111 112 struct graphVertex; 113 void findNeighboorVertices(Vector3 actuelposition, graphVertex* adjacentVertices[], graphVertex listOfVerticesP2[]); 114 void updateShortestDistanceToStart(graphVertex &vertex, graphVertex &neighboor); 115 void findNearestNonVisitedNeighboor (graphVertex &vertex, Vector3 pointToAvoidP3=Vector3(0,0,0)); 116 int graphDistance(Vector3 start, Vector3 goal); 117 118 graphVertex* findNextVertexToConsider(graphVertex listOfVerticesP[], Vector3 pointToAvoidP2=Vector3(0,0,0)); 119 Vector3 getShortestPath(Vector3 start, Vector3 goal, Vector3 pointToAvoidP1=Vector3(0,0,0)); 120 117 121 118 122 … … 126 130 bool playerFindPos(Vector3 one, Vector3 other); 127 131 132 bool jeanfindpos(Vector3 one, Vector3 other); 133 134 void setNewTargetGhost(Vector3 goalToGo); 135 128 136 129 137 }; -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.cc
r12317 r12319 13 13 14 14 RegisterObject(PacmanPink); 15 16 this->target_x=0; 17 this->target_z=15; 18 this->lastPlayerPassedPoint=Vector3(70,10,-135); 15 19 16 20 } … … 31 35 32 36 this->actuelposition = this->getPosition(); 37 38 39 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 } 43 } 44 33 45 34 46 //Stop, if target arrived … … 53 65 lockmove = true; 54 66 55 if(findPos(player.getPos(), player.lastPassedPoint)){ 67 Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); 68 69 int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); 70 this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); 71 72 73 nextMove(pinkPos, pointInFrontOfPlayer, lastPlayerPassedPoint); 74 75 76 77 /*if(findPos(player.getPos(), player.lastPassedPoint)){ 56 78 // if player is on a point, for simplicity go to it 57 79 Vector3 nextMove = getShortestPath(this->actuelposition, player.lastPassedPoint); … … 100 122 } 101 123 102 } 124 }*/ 125 lockmove=false; 103 126 104 127 } … … 106 129 107 130 108 /*109 Vector3 diffVector (Vector3 start, Vector3 goal){110 131 111 Vector3 result; 112 result.x=goal.x-start.x; 113 result.z=goal.z-start.z; 114 return result; 132 115 133 } 116 134 117 int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){118 //return 0 for south, 1 for west, 2 for north, 3 for east119 120 Vector3 difference = diffVector(playerPosBefore, playerPos);121 135 122 136 123 if((difference.z < 0)&&(difference.z>difference.x)){ //move south 137 void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){ 138 139 Vector3 nextTarget; 124 140 125 return 0; 126 } 127 else if((difference.x < 0)&&(difference.x > difference.z )){//move west 141 nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); 142 143 setNewTargetGhost(nextTarget); 144 } 128 145 129 return 1; 130 } 131 132 else if((difference.z>0)&&(difference.z>difference.x)){ //mouve north 133 134 return 2; 135 } 136 137 else if((difference.x>0)&&(difference.x>difference.z)){ //move east 138 return 3; 139 140 } 141 142 else { //default move west 143 144 return 1; 145 } 146 147 148 Vector3 getPointInFrontOfPacman(Vector3 pacLasVisPos,int indexForSWNE){ 149 //return the Vector3 point that Pinky should target to 150 //be in front of pacman 151 152 Vector3 listOfNeighboors[4]; 153 //first element is south, 2nd west, 3d north, 4th east 154 155 156 157 if(findpos(pacLasVisPos,possibleposition[0])){ 158 //no south neighbor 159 listOfNeighboors[1]=possibleposition[19]; // west neighbor 160 listOfNeighboors[2]=possibleposition[17]; //north 161 listOfNeighboors[3]=possibleposition[1]; //east 162 return listOfNeighboors[s]; 163 } 164 else if(findpos(pacLasVisPos,possibleposition[1])){ 165 listOfNeighboors[1]=possibleposition[0]; // west neighbor 166 listOfNeighboors[2]=possibleposition[2]; //north 167 return listOfNeighboors[s]; 168 } 169 else if(findpos(pacLasVisPos,possibleposition[2])){ 170 listOfNeighboors[0]=possibleposition[1]; //south 171 listOfNeighboors[1]=possibleposition[3]; //west 172 return listOfNeighboors[s]; 173 } 174 else if(findpos(pacLasVisPos,possibleposition[3])){ 175 listOfNeighboors[1]=possibleposition[4]; //west 176 listOfNeighboors[2]=possibleposition[5]; //north 177 listOfNeighboors[3]=possibleposition[2]; //east 178 return listOfNeighboors[s]; 179 } 180 else if(findpos(pacLasVisPos,possibleposition[4])){ 181 listOfNeighboors[2]=possibleposition[6]; //north 182 listOfNeighboors[3]=possibleposition[3]; //east 183 return listOfNeighboors[s]; 184 } 185 else if(findpos(pacLasVisPos,possibleposition[5])){ 186 listOfNeighboors[0]=possibleposition[3]; //south 187 listOfNeighboors[3]=possibleposition[7]; //east 188 return listOfNeighboors[s]; 189 } 190 else if(findpos(pacLasVisPos,possibleposition[6])){ 191 listOfNeighboors[0]=possibleposition[4]; //south 192 listOfNeighboors[1]=possibleposition[26]; //west 193 listOfNeighboors[2]=possibleposition[9]; //north 194 return listOfNeighboors[s]; 195 } 196 else if(findpos(pacLasVisPos,possibleposition[7])){ 197 listOfNeighboors[1]=possibleposition[5]; //west 198 listOfNeighboors[2]=possibleposition[8]; //north 199 return listOfNeighboors[s]; 200 } 201 else if(findpos(pacLasVisPos,possibleposition[8])){ 202 listOfNeighboors[0]=possibleposition[7]; //south 203 listOfNeighboors[1]=possibleposition[9]; //west 204 return listOfNeighboors[s]; 205 } 206 else if(findpos(pacLasVisPos,possibleposition[9])){ 207 listOfNeighboors[0]=possibleposition[6]; //south 208 listOfNeighboors[1]=possibleposition[38]; //west 209 listOfNeighboors[2]=possibleposition[10]; //north 210 listOfNeighboors[3]=possibleposition[8]; //east 211 return listOfNeighboors[s]; 212 } 213 else if(findpos(pacLasVisPos,possibleposition[10])){ 214 listOfNeighboors[0]=possibleposition[9]; //south 215 listOfNeighboors[1]=possibleposition[45]; //west 216 listOfNeighboors[2]=possibleposition[11]; //north 217 return listOfNeighboors[s]; 218 } 219 else if(findpos(pacLasVisPos,possibleposition[11])){ 220 listOfNeighboors[0]=possibleposition[10]; //south 221 listOfNeighboors[2]=possibleposition[13]; //north 222 listOfNeighboors[3]=possibleposition[12]; //east 223 return listOfNeighboors[s]; 224 } 225 else if(findpos(pacLasVisPos,possibleposition[12])){ 226 listOfNeighboors[1]=possibleposition[11]; //west 227 listOfNeighboors[2]=possibleposition[14]; //north 228 return listOfNeighboors[s]; 229 } 230 else if(findpos(pacLasVisPos,possibleposition[13])){ 231 listOfNeighboors[0]=possibleposition[11]; //south 232 listOfNeighboors[1]=possibleposition[61]; //west 233 listOfNeighboors[2]=possibleposition[16]; //north 234 listOfNeighboors[3]=possibleposition[14]; //east 235 return listOfNeighboors[s]; 236 } 237 else if(findpos(pacLasVisPos,possibleposition[14])){ 238 listOfNeighboors[0]=possibleposition[12]; //south 239 listOfNeighboors[1]=possibleposition[13]; //west 240 listOfNeighboors[2]=possibleposition[15]; //north 241 return listOfNeighboors[s]; 242 } 243 else if(findpos(pacLasVisPos,possibleposition[15])){ 244 listOfNeighboors[0]=possibleposition[14]; //south 245 listOfNeighboors[1]=possibleposition[16]; //west 246 return listOfNeighboors[s]; 247 } 248 else if(findpos(pacLasVisPos,possibleposition[16])){ 249 listOfNeighboors[0]=possibleposition[13]; //south 250 listOfNeighboors[1]=possibleposition[62]; //west 251 listOfNeighboors[2]=possibleposition[15]; //north 252 return listOfNeighboors[s]; 253 } 254 else if(findpos(pacLasVisPos,possibleposition[17])){ 255 listOfNeighboors[0]=possibleposition[0]; //south 256 listOfNeighboors[3]=possibleposition[25]; //east 257 return listOfNeighboors[s]; 258 } 259 else if(findpos(pacLasVisPos,possibleposition[18])){ 260 listOfNeighboors[0]=possibleposition[19]; //south 261 listOfNeighboors[1]=possibleposition[24]; //west 262 return listOfNeighboors[s]; 263 } 264 else if(findpos(pacLasVisPos,possibleposition[19])){ 265 listOfNeighboors[1]=possibleposition[20]; //west 266 listOfNeighboors[2]=possibleposition[18]; //north 267 listOfNeighboors[3]=possibleposition[0]; //east 268 return listOfNeighboors[s]; 269 } 270 else if(findpos(pacLasVisPos,possibleposition[20])){ 271 listOfNeighboors[2]=possibleposition[21]; //north 272 listOfNeighboors[3]=possibleposition[19]; //east 273 return listOfNeighboors[s]; 274 } 275 else if(findpos(pacLasVisPos,possibleposition[21])){ 276 listOfNeighboors[0]=possibleposition[20]; //south 277 listOfNeighboors[3]=possibleposition[22]; //east 278 return listOfNeighboors[s]; 279 } 280 else if(findpos(pacLasVisPos,possibleposition[22])){ 281 listOfNeighboors[1]=possibleposition[21]; //west 282 listOfNeighboors[2]=possibleposition[31]; //north 283 listOfNeighboors[3]=possibleposition[23]; //east 284 return listOfNeighboors[s]; 285 } 286 else if(findpos(pacLasVisPos,possibleposition[23])){ 287 listOfNeighboors[1]=possibleposition[22]; //west 288 listOfNeighboors[2]=possibleposition[30]; //north 289 return listOfNeighboors[s]; 290 } 291 else if(findpos(pacLasVisPos,possibleposition[24])){ 292 listOfNeighboors[2]=possibleposition[29]; //north 293 listOfNeighboors[3]=possibleposition[18]; //east 294 return listOfNeighboors[s]; 295 } 296 else if(findpos(pacLasVisPos,possibleposition[25])){ 297 listOfNeighboors[1]=possibleposition[17]; //west 298 listOfNeighboors[2]=possibleposition[26]; //north 299 return listOfNeighboors[s]; 300 } 301 else if(findpos(pacLasVisPos,possibleposition[26])){ 302 listOfNeighboors[0]=possibleposition[25]; //south 303 listOfNeighboors[1]=possibleposition[27]; //west 304 listOfNeighboors[3]=possibleposition[6]; //east 305 return listOfNeighboors[s]; 306 } 307 else if(findpos(pacLasVisPos,possibleposition[27])){ 308 listOfNeighboors[1]=possibleposition[28]; //west 309 listOfNeighboors[2]=possibleposition[37]; //north 310 listOfNeighboors[3]=possibleposition[26]; //east 311 return listOfNeighboors[s]; 312 } 313 else if(findpos(pacLasVisPos,possibleposition[28])){ 314 listOfNeighboors[1]=possibleposition[29]; //west 315 listOfNeighboors[2]=possibleposition[36]; //north 316 listOfNeighboors[3]=possibleposition[27]; //east 317 return listOfNeighboors[s]; 318 } 319 else if(findpos(pacLasVisPos,possibleposition[29])){ 320 listOfNeighboors[0]=possibleposition[24]; //south 321 listOfNeighboors[1]=possibleposition[30]; //west 322 listOfNeighboors[3]=possibleposition[28]; //east 323 return listOfNeighboors[s]; 324 } 325 else if(findpos(pacLasVisPos,possibleposition[30])){ 326 listOfNeighboors[0]=possibleposition[23]; //south 327 listOfNeighboors[2]=possibleposition[34]; //north 328 listOfNeighboors[3]=possibleposition[29]; //east 329 return listOfNeighboors[s]; 330 } 331 else if(findpos(pacLasVisPos,possibleposition[31])){ 332 listOfNeighboors[0]=possibleposition[22]; //south 333 listOfNeighboors[1]=possibleposition[32]; //west 334 return listOfNeighboors[s]; 335 } 336 else if(findpos(pacLasVisPos,possibleposition[32])){ 337 listOfNeighboors[2]=possibleposition[33]; //north 338 listOfNeighboors[3]=possibleposition[31]; //east 339 return listOfNeighboors[s]; 340 } 341 else if(findpos(pacLasVisPos,possibleposition[33])){ 342 listOfNeighboors[0]=possibleposition[32]; //south 343 listOfNeighboors[3]=possibleposition[34]; //east 344 return listOfNeighboors[s]; 345 } 346 else if(findpos(pacLasVisPos,possibleposition[34])){ 347 listOfNeighboors[0]=possibleposition[30]; //south 348 listOfNeighboors[1]=possibleposition[33]; //west 349 listOfNeighboors[2]=possibleposition[92]; //north 350 listOfNeighboors[3]=possibleposition[35]; //east 351 return listOfNeighboors[s]; 352 } 353 else if(findpos(pacLasVisPos,possibleposition[35])){ 354 listOfNeighboors[1]=possibleposition[34]; //west 355 listOfNeighboors[2]=possibleposition[91]; //north 356 listOfNeighboors[3]=possibleposition[36]; //east 357 return listOfNeighboors[s]; 358 } 359 else if(findpos(pacLasVisPos,possibleposition[36])){ 360 listOfNeighboors[0]=possibleposition[28]; //south 361 listOfNeighboors[1]=possibleposition[35]; //west 362 return listOfNeighboors[s]; 363 } 364 else if(findpos(pacLasVisPos,possibleposition[37])){ 365 listOfNeighboors[0]=possibleposition[27]; //south 366 listOfNeighboors[3]=possibleposition[38]; //east 367 return listOfNeighboors[s]; 368 } 369 else if(findpos(pacLasVisPos,possibleposition[38])){ 370 listOfNeighboors[1]=possibleposition[37]; //west 371 listOfNeighboors[2]=possibleposition[39]; //north 372 listOfNeighboors[3]=possibleposition[9]; //east 373 return listOfNeighboors[s]; 374 } 375 else if(findpos(pacLasVisPos,possibleposition[39])){ 376 listOfNeighboors[0]=possibleposition[38]; //south 377 listOfNeighboors[1]=possibleposition[40]; //west 378 listOfNeighboors[2]=possibleposition[45]; //north 379 return listOfNeighboors[s]; 380 } 381 else if(findpos(pacLasVisPos,possibleposition[40])){ 382 listOfNeighboors[1]=possibleposition[41]; //west 383 //Not return in center 384 listOfNeighboors[3]=possibleposition[39]; //east 385 return listOfNeighboors[s]; 386 } 387 else if(findpos(pacLasVisPos,possibleposition[41])){ 388 listOfNeighboors[0]=possibleposition[35]; //south 389 listOfNeighboors[2]=possibleposition[43]; //north 390 listOfNeighboors[3]=possibleposition[40]; //east 391 return listOfNeighboors[s]; 392 } 393 else if(findpos(pacLasVisPos,possibleposition[42])){ 394 listOfNeighboors[0]=possibleposition[39]; //south 395 listOfNeighboors[2]=possibleposition[59]; //north 396 listOfNeighboors[3]=possibleposition[43]; //east 397 return listOfNeighboors[s]; 398 } 399 else if(findpos(pacLasVisPos,possibleposition[43])){ 400 listOfNeighboors[0]=possibleposition[41]; //south 401 listOfNeighboors[1]=possibleposition[42]; //west 402 listOfNeighboors[2]=possibleposition[46]; //north 403 return listOfNeighboors[s]; 404 } 405 else if(findpos(pacLasVisPos,possibleposition[44])){ 406 listOfNeighboors[0]=possibleposition[40]; //south 407 listOfNeighboors[2]=possibleposition[66]; //north 408 return listOfNeighboors[s]; 409 } 410 else if(findpos(pacLasVisPos,possibleposition[45])){ 411 listOfNeighboors[0]=possibleposition[39]; //south 412 listOfNeighboors[2]=possibleposition[49]; //north 413 listOfNeighboors[3]=possibleposition[10]; //east 414 return listOfNeighboors[s]; 415 } 416 else if(findpos(pacLasVisPos,possibleposition[46])){ 417 listOfNeighboors[0]=possibleposition[43]; //south 418 listOfNeighboors[3]=possibleposition[47]; //east 419 return listOfNeighboors[s]; 420 } 421 else if(findpos(pacLasVisPos,possibleposition[47])){ 422 listOfNeighboors[1]=possibleposition[46]; //west 423 listOfNeighboors[2]=possibleposition[52]; //north 424 listOfNeighboors[3]=possibleposition[66]; //east 425 return listOfNeighboors[s]; 426 } 427 else if(findpos(pacLasVisPos,possibleposition[48])){ 428 listOfNeighboors[1]=possibleposition[66]; //west 429 listOfNeighboors[2]=possibleposition[51]; //north 430 listOfNeighboors[3]=possibleposition[49]; //east 431 return listOfNeighboors[s]; 432 } 433 else if(findpos(pacLasVisPos,possibleposition[49])){ 434 listOfNeighboors[0]=possibleposition[45]; //south 435 listOfNeighboors[1]=possibleposition[48]; //west 436 return listOfNeighboors[s]; 437 } 438 else if(findpos(pacLasVisPos,possibleposition[50])){ 439 listOfNeighboors[1]=possibleposition[51]; //west 440 listOfNeighboors[2]=possibleposition[61]; //north 441 return listOfNeighboors[s]; 442 } 443 else if(findpos(pacLasVisPos,possibleposition[51])){ 444 listOfNeighboors[0]=possibleposition[48]; //south 445 listOfNeighboors[3]=possibleposition[50]; //east 446 return listOfNeighboors[s]; 447 } 448 else if(findpos(pacLasVisPos,possibleposition[52])){ 449 listOfNeighboors[0]=possibleposition[47]; //south 450 listOfNeighboors[1]=possibleposition[53]; //west 451 return listOfNeighboors[s]; 452 } 453 else if(findpos(pacLasVisPos,possibleposition[53])){ 454 listOfNeighboors[2]=possibleposition[58]; //north 455 listOfNeighboors[3]=possibleposition[52]; //east 456 return listOfNeighboors[s]; 457 } 458 else if(findpos(pacLasVisPos,possibleposition[54])){ 459 listOfNeighboors[0]=possibleposition[42]; //south 460 listOfNeighboors[1]=possibleposition[55]; //west 461 listOfNeighboors[2]=possibleposition[57]; //north 462 return listOfNeighboors[s]; 463 } 464 else if(findpos(pacLasVisPos,possibleposition[55])){ 465 listOfNeighboors[2]=possibleposition[56]; //north 466 listOfNeighboors[3]=possibleposition[54]; //east 467 return listOfNeighboors[s]; 468 } 469 else if(findpos(pacLasVisPos,possibleposition[56])){ 470 listOfNeighboors[0]=possibleposition[55]; //south 471 listOfNeighboors[2]=possibleposition[65]; //north 472 listOfNeighboors[3]=possibleposition[57]; //east 473 return listOfNeighboors[s]; 474 } 475 else if(findpos(pacLasVisPos,possibleposition[57])){ 476 listOfNeighboors[0]=possibleposition[54]; //south 477 listOfNeighboors[1]=possibleposition[56]; //west 478 listOfNeighboors[2]=possibleposition[64]; //north 479 listOfNeighboors[3]=possibleposition[58]; //east 480 return listOfNeighboors[s]; 481 } 482 else if(findpos(pacLasVisPos,possibleposition[58])){ 483 listOfNeighboors[0]=possibleposition[53]; //south 484 listOfNeighboors[1]=possibleposition[57]; //west 485 listOfNeighboors[3]=possibleposition[59]; //east 486 return listOfNeighboors[s]; 487 } 488 else if(findpos(pacLasVisPos,possibleposition[59])){ 489 listOfNeighboors[1]=possibleposition[58]; //west 490 listOfNeighboors[2]=possibleposition[63]; //north 491 listOfNeighboors[3]=possibleposition[60]; //east 492 return listOfNeighboors[s]; 493 } 494 else if(findpos(pacLasVisPos,possibleposition[60])){ 495 listOfNeighboors[1]=possibleposition[59]; //west 496 listOfNeighboors[2]=possibleposition[62]; //north 497 listOfNeighboors[3]=possibleposition[61]; //east 498 return listOfNeighboors[s]; 499 } 500 else if(findpos(pacLasVisPos,possibleposition[61])){ 501 listOfNeighboors[0]=possibleposition[50]; //south 502 listOfNeighboors[1]=possibleposition[60]; //west 503 listOfNeighboors[3]=possibleposition[13]; //east 504 return listOfNeighboors[s]; 505 } 506 else if(findpos(pacLasVisPos,possibleposition[62])){ 507 listOfNeighboors[0]=possibleposition[60]; //south 508 listOfNeighboors[3]=possibleposition[16]; //east 509 return listOfNeighboors[s]; 510 } 511 else if(findpos(pacLasVisPos,possibleposition[63])){ 512 listOfNeighboors[0]=possibleposition[59]; //south 513 listOfNeighboors[1]=possibleposition[64]; //west 514 return listOfNeighboors[s]; 515 } 516 else if(findpos(pacLasVisPos,possibleposition[64])){ 517 listOfNeighboors[0]=possibleposition[57]; //south 518 listOfNeighboors[1]=possibleposition[65]; //west 519 listOfNeighboors[3]=possibleposition[63]; //east 520 return listOfNeighboors[s]; 521 } 522 else if(findpos(pacLasVisPos,possibleposition[65])){ 523 listOfNeighboors[0]=possibleposition[56]; //south 524 listOfNeighboors[3]=possibleposition[64]; //east 525 return listOfNeighboors[s]; 526 } 527 else if(findpos(pacLasVisPos,possibleposition[66])){ 528 //Not back in center 529 listOfNeighboors[1]=possibleposition[47]; //west 530 listOfNeighboors[3]=possibleposition[48]; //east 531 return listOfNeighboors[s]; 532 } 533 */ 534 535 } 146 } 536 147 537 148 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanPink.h
r12317 r12319 18 18 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 19 19 20 void setNewTargetPink(Vector3 goalToGo);20 //void setNewTargetPink(Vector3 goalToGo); 21 21 22 void nextMove(Vector3 playerPos, Vector3 redPos);22 //void nextMove(Vector3 playerPos, Vector3 redPos); 23 23 24 24 //int findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos); … … 28 28 //Vector3 diffVector (Vector3 start, Vector3 goal); 29 29 30 Vector3 pinkPos; 31 32 void nextMove(Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11=Vector3(0,0,0)); 33 30 34 }; 31 35 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
r12318 r12319 36 36 }*/ 37 37 38 bool PacmanRed::jeanfindpos(Vector3 one, Vector3 other){39 if((abs(one.x - other.x)<15) && (abs(one.y - other.y)<15) && (abs(one.z - other.z)<15)) return true;40 return false;41 }42 38 43 39 void PacmanRed::tick(float dt) 44 40 { 45 std::cout<<"LemanExpress5"<<endl;41 //std::cout<<"LemanExpress5"<<endl; 46 42 SUPER(PacmanGhost, tick, dt); 47 43 … … 69 65 //Stop, if target arrived 70 66 if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ 71 std::cout<<"LemanExpress1"<<endl;67 //std::cout<<"LemanExpress1"<<endl; 72 68 this->ismoving = false; 73 69 } … … 75 71 //Move, if ghost hasn't arrived yet 76 72 if(this->ismoving){ 77 std::cout<<"LemanExpress2"<<endl;73 //std::cout<<"LemanExpress2"<<endl; 78 74 if(!(abs(this->actuelposition.z-target_z)<0.5)) { 79 75 velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); … … 84 80 move(dt, actuelposition, velocity); 85 81 } 86 std::cout<<"LemanExpress4"<<endl;82 //std::cout<<"LemanExpress4"<<endl; 87 83 } 88 84 … … 106 102 if(!findpos(this->actuelposition, lastPlayerPassedPoint)){ 107 103 108 std::cout<<this->getPlayerPos()<<endl;104 /*std::cout<<this->getPlayerPos()<<endl; 109 105 std::cout<<this->lastPlayerPassedPoint<<endl; 110 106 std::cout<<this->pointInFrontOfPlayer<<endl; 111 std::cout<<this->actuelposition<<endl; 107 std::cout<<this->actuelposition<<endl;*/ 112 108 nextMove(redPos, lastPlayerPassedPoint); 113 109 std::cout<<"hiuddi"<<endl; … … 115 111 else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint 116 112 117 std::cout<<"dhdidjop"<<endl;113 /*std::cout<<"dhdidjop"<<endl; 118 114 std::cout<<this->getPlayerPos()<<endl; 119 115 std::cout<<this->lastPlayerPassedPoint<<endl; 120 116 std::cout<<this->pointInFrontOfPlayer<<endl; 121 std::cout<<this->actuelposition<<endl; 117 std::cout<<this->actuelposition<<endl;*/ 122 118 123 119 nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer); … … 132 128 133 129 134 void PacmanRed::setNewTargetRed(Vector3 goalToGo){135 136 this->target_x = goalToGo.x;137 this->target_z = goalToGo.z;138 this->ismoving = true;139 }140 141 142 130 void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){ 143 131 … … 146 134 nextTarget = getShortestPath(redPosP, playerPos); 147 135 148 setNewTarget Red(nextTarget);136 setNewTargetGhost(nextTarget); 149 137 } 150 138 -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
r12318 r12319 18 18 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 19 19 20 void setNewTargetRed(Vector3 goalToGo);21 22 20 void nextMove(Vector3 playerPos, Vector3 redPos); 23 21 24 22 void mainBehaviourRed(); 25 26 bool jeanfindpos(Vector3 one, Vector3 other);27 23 28 24 bool isNearPlayer;
Note: See TracChangeset
for help on using the changeset viewer.