-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath.h
More file actions
71 lines (65 loc) · 2.36 KB
/
Path.h
File metadata and controls
71 lines (65 loc) · 2.36 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
#pragma once
#include "Move.h"
class Path {
public:
Path(vector<Move> p, int o = 0) {
path = p;
pickup = vector<string>{};
steps = p.size();
corners = 0;
order = o;
for (int i = 0; i < p.size() - 1; i++) {
if (isCorner(p.at(i), p.at(i + 1))) corners++;
}
}
bool operator>(const Path a) {
if (this->corners == a.corners) return this->steps > a.steps;
return this->corners > a.corners;
}
vector<Move> operator+(const Path a) const {
vector<Move> returnThis = this->path;
returnThis.insert(returnThis.end(), a.getMoves().begin(), a.getMoves().end());
}
vector<Move> getMoves() const { return path; }
vector<string> getPickup() { return pickup; }
void setPickup(vector<string> s) { pickup = s; }
int getOrder() { return order; }
void setOrder(int o) { order = o; }
private:
vector<Move> path;
vector<string> pickup;
int corners;
int steps;
int order;
};
void setOrder(int &order, int a, int b, int c, int d = 0) {
order = d * 1000 + c * 100 + b * 10 + a;
}
void printMoves(Path path, int missionNum, char color) {
vector<Move> v = path.getMoves();
vector<string> s = path.getPickup();
cout << "const char " << ((color == 'r') ? "RED_MISSION_" : "NEUTRAL_MISSION_") << missionNum << "[] = { ";
cout << "FORWARD, ";
dir curr;
dir next;
for (int i = 0; i < v.size() - 2; i++) {
curr = v.at(i).getMoveDir();
next = v.at(i + 1).getMoveDir();
if (curr == next) cout << "FORWARD, ";
else if (curr - next == -1 || curr - next == 3) cout << "RIGHT, ";
else if (curr - next == 1 || curr - next == -3) cout << "LEFT, ";
else cout << "BACK, ";
}
curr = v.at(v.size() - 2).getMoveDir();
next = v.at(v.size() - 1).getMoveDir();
if (curr == next) cout << "FORWARD }" << endl;
else if (curr - next == -1 || curr - next == 3) cout << "RIGHT }" << endl;
else if (curr - next == 1 || curr - next == -3) cout << "LEFT }" << endl;
else cout << "BACK }" << endl;
cout << "const char " << ((color == 'r') ? "RED_PICKUP_" : "NEUTRAL_PICKUP_") << missionNum << "[] = { ";
for (int i = 0; i < v.size() - 1; i++) {
cout << s.at(i) << ", ";
}
cout << s.at(s.size() - 1) << " };" << endl;
cout << "const int " << ((color == 'r') ? "RED_STEPS_" : "NEUTRAL_STEPS_") << missionNum << " = " << v.size() << ";" << endl;
}