-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.cpp
90 lines (77 loc) · 2.06 KB
/
Controller.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
#include "Controller.h"
#include "API.h"
spat::turn Controller::Goto() {
m_target_way = m_way[m_current_position.y][m_current_position.x];
uint8_t my_mapdata = m_mapdata[m_current_position.y][m_current_position.x];
if(!(my_mapdata & m_target_way)) {
SetPush(m_current_position);
Update();
m_target_way = m_way[m_current_position.y][m_current_position.x];
}
Path();
return Turn();
}
void Controller::Path() {
spat::vec2<int16_t> vec = m_current_position;
while (!m_queue_way.empty()) {
m_queue_way.pop();
}
while(m_map.Know(vec)) {
m_queue_way.push(vec);
API::setColor((spat::vec2<int16_t>)vec,'c');
// Sleep(1);
switch (m_way[vec.y][vec.x])
{
case spat::way::n:
vec.y ++;
break;
case spat::way::e:
vec.x ++;
break;
case spat::way::s:
vec.y --;
break;
case spat::way::w:
vec.x --;
break;
}
if(m_weight[vec.y][vec.x] == 0) {
// m_find_shortest_way = true;
break;
}
// else m_find_shortest_way = false;
}
// m_unkown_target = vec;
}
spat::turn Controller::Turn() {
spat::turn result = spat::turn::stop;
uint8_t way = m_current_way + (m_current_way << 4);
m_current_way = m_target_way;
switch (m_target_way)
{
case spat::way::n:
m_current_position.y += 1;
break;
case spat::way::e:
m_current_position.x += 1;
break;
case spat::way::s:
m_current_position.y -= 1;
break;
case spat::way::w:
m_current_position.x -= 1;
break;
default:
break;
}
if(way & m_target_way) {
result = spat::turn::forward;
} else if(way & (m_target_way << 1)){
result = spat::turn::right;
} else if(way & (m_target_way << 3)) {
result = spat::turn::left;
} else if(way & (m_target_way << 2)) {
result = spat::turn::back;
}
return result;
}