-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParcour.cpp
More file actions
116 lines (104 loc) · 3.14 KB
/
Parcour.cpp
File metadata and controls
116 lines (104 loc) · 3.14 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "DefVal.hpp"
#include "Parcour.hpp"
using namespace std;
Parcour::Parcour() {
steps = rand() % 30 + 10;
//cout << "Parcour steps: " << steps << endl;
Phases.push_back(0);
for (int i = 0; i < steps-2; i++) {Phases.push_back((rand()%(PARC_SIZE/2-1))+(rand()%(PARC_SIZE/2-1))+1);}
Phases.push_back(PARC_SIZE);
sort (Phases.begin(), Phases.end());
for (int i = 0; i < steps - 1; i++){
Slopes.push_back(rand() % 80 - 40);
}
for (int i = 1; i < 9; i++){
WaterSup.push_back((PARC_SIZE/9)*i+(rand()%(PARC_SIZE/20)-(PARC_SIZE/40)));
}
WdSpeed = (float)(rand() % 7000)/360.f; //pour avoir un vent entre 0 et 70 Km/h
//mais avec beaucoup plus entre 10 et 30 Km/h
if (WdSpeed < 2.777f) {WdSpeed += (float)(rand() % 20)/3.6f;}
if (WdSpeed > 13.888f) {WdSpeed -= (float)(rand() % 20)/3.6f;} //et beaucoup moins > 50 Km/h
if (WdSpeed > 8.333f) {WdSpeed -= (float)(rand() % 20)/3.6f;}
//WdSpeed est en m/s
WdAng = (float)rand()/((float)RAND_MAX/360.f);
TurnSteps = rand() % 30 + 10;
TurnsPhases.push_back(0);
for (int i = 0; i < TurnSteps-2; i++) {TurnsPhases.push_back((rand()%(PARC_SIZE/2-1))+(rand()%(PARC_SIZE/2-1))+1);}
TurnsPhases.push_back(PARC_SIZE);
sort (TurnsPhases.begin(), TurnsPhases.end());
for (int i = 0; i < TurnSteps - 1; i++){
Turns.push_back((float)rand()/((float)RAND_MAX/200.f) - 100);
}
};
Parcour::Parcour(const std::string& file) {
ifstream OpenFile (file);
if(!OpenFile.is_open()) {
cout << "Error opening file" << endl;
exit (EXIT_FAILURE);
}
string line;
istringstream Proline;
getline(OpenFile, line);
steps = stoi(line);
getline(OpenFile, line);
Proline.str(line);
while (Proline >> line){Phases.push_back(stoi(line));}
getline(OpenFile, line);
Proline.clear();
Proline.str(line);
while (Proline >> line){Slopes.push_back(stoi(line));}
getline(OpenFile, line);
Proline.clear();
Proline.str(line);
while (Proline >> line){WaterSup.push_back(stoi(line));}
getline(OpenFile, line);
WdSpeed = stoi(line);
getline(OpenFile, line);
WdAng = stoi(line);
getline(OpenFile, line);
TurnSteps = stoi(line);
getline(OpenFile, line);
Proline.clear();
Proline.str(line);
while (Proline >> line){TurnsPhases.push_back(stoi(line));}
getline(OpenFile, line);
Proline.clear();
Proline.str(line);
while (Proline >> line){Turns.push_back(stoi(line));}
OpenFile.close();
}
const void Parcour::MakeTxt(const std::string& file){
ofstream OpenFile (file);
if(!OpenFile.is_open()) {
cout << "Error opening file" << endl;
exit (EXIT_FAILURE);
}
ostringstream out;
out << steps << "\n";
for (int i = 0; i < steps; i++){
out << " ";
out << Phases[i];
}
out << "\n";
for (int i = 0; i < steps; i++){
out << " ";
out << Slopes[i];
}
out << "\n";
for (int i = 0; i < 8; i++){
out << " ";
out << WaterSup[i];
}
out << "\n" << WdSpeed << "\n" << WdAng << "\n" << TurnSteps << "\n";
for (int i = 0; i < TurnsPhases.size(); i++){
out << " ";
out << TurnsPhases[i];
}
out << "\n";
for (int i = 0; i < Turns.size(); i++){
out << " ";
out << Turns[i];
}
OpenFile << out.str();
OpenFile.close();
}