int find_path_not_ricochet (int x_dep, int y_dep, int x_goal, int y_goal, repr* reper,Robot* robot) { Case courant; courant.x = x_dep; courant.y = y_dep; courant.G = 0; courant.H = 0; courant.F = 0; ferme.push_back(courant); return_ouvert_not_ricochet (&courant,x_goal,y_goal,reper); cout << "debut boucle " << endl; while(1) { cout << "le courant " << courant.x << " " << courant.y << endl; courant = lowest_node(); ferme.push_back(courant); if(courant.x == x_goal && courant.y == y_goal) { cout << "Chemin trouvée ! " << endl; affiche_chemin (&courant,x_dep, y_dep); envoi_chemin(robot); return 0; break; } cout << "retourne ouvert" << endl; return_ouvert_not_ricochet (&courant,x_goal,y_goal,reper); if(ouvert.size() == 0) { cout << "Pas de solution ... " << endl; break; } } return -1; }
/** * Handles the processing of any active actors to allow for handling movement */ void processAnimation() { objectParamsQuery params; MovementEntry moveInfo; actorStruct *currentActor = actorHead.next; actorStruct *nextActor; while (currentActor) { nextActor = currentActor->next; if (!currentActor->freeze && ((currentActor->type == ATP_MOUSE) || (currentActor->type == 1))) { getMultipleObjectParam(currentActor->overlayNumber, currentActor->idx, ¶ms); if (((animationStart && !currentActor->flag) || (!animationStart && currentActor->x_dest != -1 && currentActor->y_dest != -1)) && (currentActor->type == ATP_MOUSE)) { // mouse animation if (!animationStart) { aniX = currentActor->x_dest; aniY = currentActor->y_dest; currentActor->x_dest = -1; currentActor->y_dest = -1; currentActor->flag = 1; } currentActor->pathId = computePathfinding(moveInfo, params.X, params.Y, aniX, aniY, currentActor->stepX, currentActor->stepY, currentActor->pathId); if (currentActor->pathId == ANIM_WAIT) { if ((currentActor->endDirection != -1) && (currentActor->endDirection != currentActor->startDirection)) { currentActor->phase = ANIM_PHASE_STATIC_END; currentActor->nextDirection = currentActor->endDirection; currentActor->endDirection = -1; currentActor->counter = 0; } else { currentActor->pathId = ANIM_FINISH; currentActor->flag = 0; currentActor->endDirection = -1; currentActor->phase = ANIM_PHASE_WAIT; } } else { currentActor->phase = ANIM_PHASE_STATIC; currentActor->counter = -1; } } else if ((currentActor->type == 1) && (currentActor->x_dest != -1) && (currentActor->y_dest != -1)) { // track animation currentActor->pathId = computePathfinding(moveInfo, params.X, params.Y, currentActor->x_dest, currentActor->y_dest, currentActor->stepX, currentActor->stepY, currentActor->pathId); currentActor->x_dest = -1; currentActor->y_dest = -1; if (currentActor->pathId == ANIM_WAIT) { if ((currentActor->endDirection != -1) && (currentActor->endDirection != currentActor->startDirection)) { currentActor->phase = ANIM_PHASE_STATIC_END; currentActor->nextDirection = currentActor->endDirection; currentActor->endDirection = -1; currentActor->counter = 0; } else { currentActor->pathId = -2; currentActor->flag = 0; currentActor->endDirection = -1; currentActor->phase = ANIM_PHASE_WAIT; } } else { currentActor->phase = ANIM_PHASE_STATIC; currentActor->counter = -1; } } animationStart = false; if ((currentActor->pathId >= 0) || (currentActor->phase == ANIM_PHASE_STATIC_END)) { // Main switch statement for handling various phases of movement // IMPORTANT: This switch relies on falling through cases in certain circumstances // , so 'break' statements should *not* be used at the end of case areas switch (currentActor->phase) { case ANIM_PHASE_STATIC_END: case ANIM_PHASE_STATIC: { // In-place (on the spot) animationos if ((currentActor->counter == -1) && (currentActor->phase == ANIM_PHASE_STATIC)) { affiche_chemin(currentActor->pathId, moveInfo); if (moveInfo.x == -1) { currentActor->pathId = ANIM_FINISH; currentActor->flag = 0; currentActor->endDirection = -1; currentActor->phase = ANIM_PHASE_WAIT; break; } currentActor->x = moveInfo.x; currentActor->y = moveInfo.y; currentActor->nextDirection = moveInfo.direction; currentActor->poly = moveInfo.poly; currentActor->counter = 0; if (currentActor->startDirection == currentActor->nextDirection) currentActor->phase = ANIM_PHASE_MOVE; } if ((currentActor->counter >= 0) && ((currentActor->phase == ANIM_PHASE_STATIC_END) || (currentActor->phase == ANIM_PHASE_STATIC))) { int newA; int inc = 1; int t_inc = currentActor->startDirection - 1; if (t_inc < 0) t_inc = 3; if (currentActor->nextDirection == t_inc) inc = -1; if (inc > 0) newA = actor_stat[currentActor->startDirection][currentActor->counter++]; else newA = actor_invstat[currentActor->startDirection][currentActor->counter++]; if (newA == 0) { currentActor->startDirection = currentActor->startDirection + inc; if (currentActor->startDirection > 3) currentActor->startDirection = 0; if (currentActor->startDirection < 0) currentActor-> startDirection = 3; currentActor->counter = 0; if (currentActor->startDirection == currentActor->nextDirection) { if (currentActor->phase == ANIM_PHASE_STATIC) currentActor->phase = ANIM_PHASE_MOVE; else currentActor->phase = ANIM_PHASE_END; } else { newA = actor_stat[currentActor->startDirection][currentActor->counter++]; if (inc == -1) newA = -newA; set_anim(currentActor->overlayNumber, currentActor->idx, currentActor->start, params.X, params.Y, newA, currentActor->poly); break; } } else { set_anim(currentActor->overlayNumber,currentActor->idx, currentActor->start, params.X, params.Y, newA, currentActor->poly); break; } } } case ANIM_PHASE_MOVE: { // Walk animations if (currentActor->counter >= 1) { affiche_chemin(currentActor->pathId, moveInfo); if (moveInfo.x == -1) { if ((currentActor->endDirection == -1) || (currentActor->endDirection == currentActor->nextDirection)) { currentActor->phase = ANIM_PHASE_END; } else { currentActor->phase = ANIM_PHASE_STATIC_END; currentActor->nextDirection = currentActor->endDirection; } currentActor->counter = 0; break; } else { currentActor->x = moveInfo.x; currentActor->y = moveInfo.y; currentActor->nextDirection = moveInfo.direction; currentActor->poly = moveInfo.poly; } } if (currentActor->phase == ANIM_PHASE_MOVE) { int newA; currentActor->startDirection = currentActor->nextDirection; newA = actor_move[currentActor->startDirection][currentActor->counter++]; if (!newA) { currentActor->counter = 0; newA = actor_move[currentActor->startDirection][currentActor->counter++]; } set_anim(currentActor->overlayNumber, currentActor->idx, currentActor->start, currentActor->x, currentActor->y, newA, currentActor->poly); break; } } case ANIM_PHASE_END: { // End of walk animation int newA = actor_end[currentActor->startDirection][0]; set_anim(currentActor->overlayNumber, currentActor->idx, currentActor->start, currentActor->x, currentActor->y, newA, currentActor->poly); currentActor->pathId = ANIM_FINISH; currentActor->phase = ANIM_PHASE_WAIT; currentActor->flag = 0; currentActor->endDirection = -1; break; } default: { warning("Unimplemented currentActor->phase=%d in processAnimation()", currentActor->phase); // exit(1); } } } } currentActor = nextActor; } }
int main(int argc, char const *argv[]) { int point_depart = NON_TROUVE ; int point_arrivee = NON_TROUVE ; int choix_mode = 0 ; int choix_menu = NON_TROUVE ; int itineraire_de_base_calcule = NON_TROUVE ; int retour_checked = NON_TROUVE ; int alternatif_checked = NON_TROUVE ; if (init_jonction() != NON_TROUVE) { printf("\nBienvenue dans le programme de calcul du chemin le plus court.\nCe programme vous donnera le trajet le plus court entre 2 intersections de rues du 11e arrondissement de Paris.\n"); while (choix_menu != 0) { choix_menu = NON_TROUVE ; // on réinitialise la variable pour le cas où on a bouclé printf("\n************** Menu ************** \n") ; printf("1 - Calculer un itinéraire principal\n") ; if (itineraire_de_base_calcule != NON_TROUVE){ printf("2 - Calculer le trajet de retour\n") ; printf("3 - Recalculer l'itinéraire principal avec l'autre mode de transport\n") ; } printf("\n0 - Quitter le programme\n") ; printf("\nVotre choix : ") ; scanf("%d", &choix_menu) ; printf("\n") ; switch (choix_menu) { case 0 : // quitter printf("\nMerci d'avoir utilisé ce programme.\nAu revoir et à bientôt.\n"); break ; case 1 : // calcul itinéraire choix_mode = mode_transport() ; if (init_rues_distances(choix_mode) != NON_TROUVE) { if (itineraire_de_base_calcule == 1) { reinit_jonctions() ; } point_depart = recherche_nom_rue("de départ") ; // numéro du point de départ point_arrivee = recherche_nom_rue("d'arrivée") ; // numéro du point d'arrivée tab_jonctions[point_depart].longueur = 0 ; // initialisation de la longueur de la rue du point de départ à 0 dijkstra(point_arrivee) ; // fonction qui utilise l'algo de Dijkstra affiche_chemin(point_depart, point_arrivee, choix_mode) ; // affichage itineraire_de_base_calcule = 1 ; choix_menu = NON_TROUVE ; // remise à état initial de la variable choix_menu retour_checked = NON_TROUVE ; // ré-init de la variable pour faire le retour sur nouvel itinéraire alternatif_checked = NON_TROUVE ; // ré-init de la variable pour faire alternatif sur nouvel itinéraire } break ; case 2 : // trajet retour suite au choix 1 if (itineraire_de_base_calcule == NON_TROUVE) { printf("Merci de saisir un choix valide\n") ; } else if (retour_checked == 1) { printf("Vous avez déjà calculé l'itinéraire de retour pour ce trajet.\n"); } else { // on inverse les points de départ et arrivée pour recalculer l'itinéraire de retour reinit_jonctions() ; // ré-initialisation du tableau des jonctions pour repartir du point d'arrivée du calcul d'itinéraire précédent tab_jonctions[point_arrivee].longueur = 0 ; // initialisation de la longueur de la rue du point d'arrivée à 0 dijkstra(point_depart) ; // fonction qui utilise l'algo de Dijkstra affiche_chemin(point_arrivee, point_depart, choix_mode) ; // affichage retour_checked = 1 ; choix_menu = NON_TROUVE ; // remise à état initial de la variable choix_menu } break ; case 3 : // mode de transport alternatif avec itinéraire du choix 1 if (itineraire_de_base_calcule == NON_TROUVE) { printf("Merci de saisir un choix valide\n") ; } else if (alternatif_checked == 1) { printf("Vous avez déjà visualisé l'itinéraire alternatif pour ce trajet.\n"); } else { if (choix_mode == 1) { choix_mode = 2 ; } else { choix_mode = 1 ; } //printf("mode --> %d\n", choix_mode); if (init_rues_distances(choix_mode) != NON_TROUVE) { reinit_jonctions() ; // ré-initialisation du tableau des jonctions pour recalculer l'itinéraire précédent tab_jonctions[point_depart].longueur = 0 ; // initialisation de la longueur de la rue du point de départ à 0 dijkstra(point_arrivee) ; // fonction qui utilise l'algo de Dijkstra affiche_chemin(point_depart, point_arrivee, choix_mode) ; // affichage alternatif_checked = 1 ; choix_menu = NON_TROUVE ; // remise à état initial de la variable choix_menu } } break ; default : printf("Merci de saisir un choix valide\n") ; purge() ; } } } }