-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathcar.hpp
253 lines (197 loc) · 4.68 KB
/
car.hpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef ROBOCAR_CAR_HPP
#define ROBOCAR_CAR_HPP
/**
* @brief Justine - this is a rapid prototype for development of Robocar City Emulator
*
* @file car.hpp
* @author Norbert Bátfai <[email protected]>
* @version 0.0.10
*
* @section LICENSE
*
* Copyright (C) 2014 Norbert Bátfai, [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
* Robocar City Emulator and Robocar World Championship
*
* desc
*
*/
#include <osmium/osm/types.hpp>
#include <iostream>
#include <vector>
#include <osmreader.hpp>
#include <algorithm>
namespace justine
{
namespace robocar
{
enum class CarType: unsigned int
{
NORMAL=0, POLICE, GANGSTER, CAUGHT
};
class Traffic;
class Car
{
public:
Car ( Traffic & traffic , CarType type = CarType::NORMAL );
virtual void init();
virtual void step();
osmium::unsigned_object_id_type from() const
{
return m_from;
}
osmium::unsigned_object_id_type to() const
{
return m_to;
}
osmium::unsigned_object_id_type get_step() const
{
return m_step;
}
CarType get_type() const
{
return m_type;
}
void set_type ( CarType type )
{
m_type = type;
}
osmium::unsigned_object_id_type to_node() const;
osmium::unsigned_object_id_type get_max_steps() const;
virtual void nextEdge ( void );
virtual void nextSmarterEdge ( void );
virtual void print ( std::ostream & os ) const
{
os << m_from
<< " "
<< to_node()
<< " "
<< get_max_steps()
<< " "
<< get_step()
<< " "
<< static_cast<unsigned int> ( get_type() );
}
friend std::ostream & operator<< ( std::ostream & os, Car & c )
{
c.print ( os );
return os;
}
protected:
Traffic & traffic;
CarType m_type {CarType::NORMAL};
osmium::unsigned_object_id_type m_from {3130863972};
osmium::unsigned_object_id_type m_to {0};
osmium::unsigned_object_id_type m_step {0};
private:
};
class AntCar : public Car
{
public:
AntCar ( Traffic & traffic );
virtual void nextSmarterEdge ( void );
virtual void print ( std::ostream & os ) const
{
os << m_from
<< " "
<< to_node()
<< " "
<< get_max_steps()
<< " "
<< get_step()
<< " "
<< static_cast<unsigned int> ( get_type() );
}
osmium::unsigned_object_id_type ant ( void );
osmium::unsigned_object_id_type ant_rnd ( void );
osmium::unsigned_object_id_type ant_rernd ( void );
osmium::unsigned_object_id_type ant_mrernd ( void );
static AdjacencyList alist;
static AdjacencyList alist_evaporate;
private:
bool rnd {true};
};
class SmartCar : public Car
{
public:
SmartCar ( Traffic & traffic, CarType type, bool guided );
virtual void step();
virtual void init();
virtual void print ( std::ostream & os ) const
{
os << m_from
<< " "
<< to_node()
<< " "
<< get_max_steps()
<< " "
<< get_step()
<< " "
<< static_cast<unsigned int> ( get_type() );
}
bool get_guided() const
{
return m_guided;
}
bool set_route ( std::vector<unsigned int> & route );
virtual void nextEdge ( void );
virtual void nextGuidedEdge ( void );
bool set_fromto ( unsigned int from, unsigned int to );
private:
bool m_guided {false};
bool m_routed {false};
std::vector<unsigned int> route;
};
class CopCar : public SmartCar
{
public:
CopCar ( Traffic & traffic, bool guided, const char *name );
virtual void print ( std::ostream & os ) const
{
os << m_from
<< " "
<< to_node()
<< " "
<< get_max_steps()
<< " "
<< get_step()
<< " "
<< static_cast<unsigned int> ( get_type() )
<< " "
<< get_num_captured_gangsters()
<< " "
<< m_name;
}
std::string get_name() const
{
return m_name;
}
int get_num_captured_gangsters() const
{
return m_num_captured_gangsters;
}
void captured_gangster ( void )
{
++m_num_captured_gangsters;
}
protected:
int m_num_captured_gangsters {0};
std::string m_name;
};
}
} // justine::robocar::
#endif // ROBOCAR_CAR_HPP