Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (60 loc) · 2.13 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "maze.h"
#include "agent.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <thread>
#include <chrono>
using namespace std;
int main()
{
// Initialise aleatoire pour des chemins differents
srand(time(0));
// Crée l'objet labyrinthe (charge source.mz)
maze m("source.mz");
int pas_actuels = 0;
long long pas_total = 0;
int pas_min = 999999;
int pas_max = 0;
//100 tests
for (int i = 0; i < 100; ++i)
{
bool en_cours = true; // flag pour la boucle interne
pas_actuels = 0; // reset le compteur de pas
// boucle while jusqu'à la fin du labyrinthe
while (en_cours)
{
pas_actuels++; // compte le pas
char direction_choisie = m.move_random_agent();
m.update_agent(direction_choisie);
if (m.isFinished())
{
en_cours = false; // arrete la boucle
}
system("clear"); // nettoie l'écran
m.refresh_map_char(); // Met a jour la position de lagent
cout << m; //dessine la carte
cout << "Test: " << i + 1 << " / " << 100 << " | Pas: " << pas_actuels << endl;
//pause
this_thread::sleep_for(chrono::milliseconds(50));
}
// Affiche la carte finale
system("clear");
m.refresh_map_char();
cout << m;
cout << "Test " << i + 1 << " termine en " << pas_actuels << " pas." << endl;
this_thread::sleep_for(chrono::milliseconds(2000)); // Pause de 2 secondes avant le prochain test
pas_total += pas_actuels;
if (pas_min > pas_actuels) pas_min = pas_actuels;
if (pas_max < pas_actuels) pas_max = pas_actuels;
m.resetMaze();
}
//affichage
double pas_moyen = (double)pas_total / 100;
cout << "\n--- Resultats FINAUX de la Simulation ---" << endl;
cout << "Nombre de tests: " << 100 << endl;
cout << "Pas minimum: " << pas_min << endl;
cout << "Pas maximum: " << pas_max << endl;
cout << "Moyenne des pas: " << pas_moyen << endl;
return 0;
}