-
Notifications
You must be signed in to change notification settings - Fork 0
/
ant.hpp
79 lines (58 loc) · 1.35 KB
/
ant.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
#ifndef ANTVIEW_ANT_HPP_
#define ANTVIEW_ANT_HPP_
#include <set>
#include <utility>
#include <ostream>
using Coord = int;
using Pos = std::pair<Coord, Coord>;
using Trail = std::set<Pos>;
std::ostream& operator<<(std::ostream& os, const Trail& trail);
std::ostream& operator<<(std::ostream& os, const Pos& pos);
class Ant;
std::ostream& operator<<(std::ostream& os, const Ant& ant);
class Ant {
public:
enum Dir { N, E, S, W };
static Coord norm_x(Coord x);
static Coord norm_y(Coord y);
static const Coord MaxX = 32;
static const Coord MaxY = 32;
Ant();
Ant(const Trail& trail);
Ant(Dir dir, Coord x, Coord y, const Trail& trail);
void forward();
void left();
void right();
bool is_food_ahead() const;
Dir dir() const {
return dir_;
}
Coord x() const {
return x_;
}
Coord y() const {
return y_;
}
unsigned food_eaten() const {
return food_eaten_;
}
unsigned food_left() const {
return trail_.size();
}
unsigned action_num() const {
return action_num_;
}
const Trail& trail() const {
return trail_;
}
private:
bool is_food_at_pos(Coord x, Coord y) const;
void eat();
Dir dir_;
Coord x_;
Coord y_;
Trail trail_;
unsigned food_eaten_;
unsigned action_num_;
};
#endif