-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.cpp
More file actions
113 lines (105 loc) · 3.66 KB
/
Copy pathfunctions.cpp
File metadata and controls
113 lines (105 loc) · 3.66 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
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
#include "classes.h"
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
vector<int> parseIntegers(const string &input) {
vector<int> integers;
stringstream ss(input);
string token;
while (getline(ss, token, ',')) {
integers.push_back(stoi(token));
}
return integers;
}
vector<pair<int, int>> parseGoalPos(const string &input) {
stringstream ss(input);
string token;
vector<pair<int, int>> goalPositions;
while (getline(ss, token, '|')) {
vector<int> pos = parseIntegers(token);
if (pos.size() == 2) {
goalPositions.emplace_back(pos[0], pos[1]);
}
}
return goalPositions;
}
tuple<int, int, int, int> parseLine(const string &line) {
stringstream ss(line);
int a, b, c, d;
char comma;
ss >> a >> comma >> b >> comma >> c >> comma >> d;
return make_tuple(a, b, c, d);
}
void printGoals(const vector<pair<int, int>> &goalPositions) {
for (const auto &pair : goalPositions) {
std::cout << "(" << pair.first << ", " << pair.second << ")"
<< std::endl;
}
}
void printWalls(const vector<tuple<int, int, int, int>> &Walls) {
cout << "Walls read from file:" << endl;
for (const auto &tuple : Walls) {
cout << "(" << get<0>(tuple) << ", " << get<1>(tuple) << ", "
<< get<2>(tuple) << ", " << get<3>(tuple) << ")" << endl;
}
}
void printData(const vector<int> &gridSize, const vector<int> &startingPos) {
cout << "Grid Size: " << gridSize[0] << " rows x " << gridSize[1]
<< " columns" << endl;
cout << "Starting Position: (" << startingPos[0] << ", " << startingPos[1]
<< ")" << endl;
}
void markBlockGoals(matrix &Matrix,
const vector<pair<int, int>> &goalPositions) {
for (const auto &pair : goalPositions) {
Matrix.blocks[pair.second][pair.first].color = "green";
}
}
void markWalls(matrix &Matrix, const vector<tuple<int, int, int, int>> &walls) {
for (const auto &tuple : walls) {
for (int i = get<1>(tuple); i < get<1>(tuple) + get<3>(tuple); i++) {
for (int j = get<0>(tuple); j < get<0>(tuple) + get<2>(tuple);
j++) {
Matrix.blocks[i][j].color = "black";
}
}
}
}
int getNearestGoalX(const vector<pair<int, int>> &goalPositions) {
// Initialize the minimum x-coordinate and its index with the first goal
// position
int min_x = goalPositions[0].first;
// Iterate through the goal positions starting from the second one
for (size_t i = 1; i < goalPositions.size(); ++i) {
// If the current x-coordinate is lower than the minimum x-coordinate
// encountered so far, update the minimum x-coordinate
if (goalPositions[i].first < min_x) {
min_x = goalPositions[i].first;
}
}
return min_x;
}
int getFarthestGoalX(const vector<pair<int, int>> &goalPositions) {
int max_x = goalPositions[0].first;
// Iterate through the goal positions starting from the second one
for (size_t i = 1; i < goalPositions.size(); ++i) {
// If the current x-coordinate is higher than the maximum x-coordinate
// encountered so far, update the maximum x-coordinate
if (goalPositions[i].first > max_x) {
max_x = goalPositions[i].first;
}
}
return max_x;
}
string getBestOption(const vector<pair<int, int>> &goalPositions, int start_x) {
int min_x = getNearestGoalX(goalPositions);
int max_x = getNearestGoalX(goalPositions);
if (min_x < start_x && max_x < start_x) {
return "anitClockWise";
} else {
return "clockWise";
}
}