-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmode.cpp
108 lines (91 loc) · 2.93 KB
/
cmode.cpp
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
#include "cmode.h"
namespace planet{
CMode::CMode(size_t id,
size_t idxInCollectors,
data& server) : id(id),
idxInCollectors(idxInCollectors),
server(server) {}
bool CMode::isUnknownArea(){
return server.isUnknownPoint(id, Direction::UP) ||
server.isUnknownPoint(id, Direction::DOWN) ||
server.isUnknownPoint(id, Direction::LEFT) ||
server.isUnknownPoint(id, Direction::RIGHT);
}
CMode::~CMode() = default;
Direction CMode::randWay(){
Direction where;
u_char randCount = rand() % 4;
switch (randCount)
{
case 0:
return Direction::UP;
case 1:
return Direction::DOWN;
case 2:
return Direction::LEFT;
case 3:
return Direction::RIGHT;
default:
return Direction::NONE;
}
}
void CMode::goInRandWay(){
Direction where = randWay();
for(u_char i = 0; i < 4; ++i)
if(server.availibleToGo(id, where)){
server.addInAccumulator(id, toDoType::MOVE, where);
break;
}
else
where = randWay();
}
void CMode::scan(){
server.addInAccumulator(idxInCollectors, toDoType::SCAN);
}
ManualMode::ManualMode(size_t id,
size_t idxInCollectors,
data& server)
: CMode(id, idxInCollectors ,server){
server.setFocus(id);
}
ManualMode::~ManualMode() = default;
void ManualMode::func(){
server.setFocus(id);
}
ScanMode::ScanMode(size_t id,
size_t idxInCollectors,
data& server)
: CMode(id, idxInCollectors, server){}
ScanMode::~ScanMode() = default;
void ScanMode::func(){
if(isUnknownArea())
scan();
else
goInRandWay();
}
AutoMode::AutoMode(size_t id,
size_t idxInCollectors,
data& server)
: CMode(id, idxInCollectors, server){
way.resize(4);
}
AutoMode::~AutoMode() = default;
void AutoMode::collectNearest(Item item){
if(way[item].size()){
server.addInAccumulator(idxInCollectors, toDoType::MOVE, server.ways[id][item].back());
server.ways[id][item].pop_back();
}
}
bool AutoMode::standingOnApple(){
return server.updatedMap[server.xyRobots[id].first]
[server.xyRobots[id].second] == APPLE;
}
void AutoMode::func(){
if(standingOnApple())
server.addInAccumulator(id, toDoType::GRAB);
else if(isUnknownArea())
scan();
else
goInRandWay();
}
}