-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummy.cpp
More file actions
119 lines (109 loc) · 4.39 KB
/
Copy pathDummy.cpp
File metadata and controls
119 lines (109 loc) · 4.39 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
114
115
116
117
118
119
//! \addtogroup 0007 Pathfinding
//! \brief A pathfinding module
//!
//! A pathfinding module that can be used in the R2D2 project.
//! The module is currently based on the A star algorithm.
//!
//! \file Dummy.cpp
//! \author Jasper Schoenmaker 1661818
//! \author Chiel Douwes 1666311
//! \date Created: 05-04-2016
//! \date Last Modified: 15-4-2016
//! \brief Dummy map for pathfinding
//!
//! A dummy implementation of the map, without it the pathfinding module could
//! not be tested.
//!
//! \copyright Copyright © 2016, HU University of Applied Sciences Utrecht.
//! All rights reserved.
//!
//! License: newBSD
//!
//! Redistribution and use in source and binary forms,
//! with or without modification, are permitted provided that
//! the following conditions are met:
//! - Redistributions of source code must retain the above copyright notice,
//! this list of conditions and the following disclaimer.
//! - Redistributions in binary form must reproduce the above copyright notice,
//! this list of conditions and the following disclaimer in the documentation
//! and/or other materials provided with the distribution.
//! - Neither the name of the HU University of Applied Sciences Utrecht
//! nor the names of its contributors may be used to endorse or promote
//! products derived from this software without specific prior written
//! permission.
//!
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
//! BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
//! AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//! IN NO EVENT SHALL THE HU UNIVERSITY OF APPLIED SCIENCES UTRECHT
//! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
//! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
//! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//! EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ~< HEADER_VERSION 2016 04 12 >~
#include "../include/Dummy.hpp"
namespace r2d2 {
std::mt19937_64 Map::mersenne = std::mt19937_64{
(unsigned long) (time(0))};
Map::Map(int x, int y, float obstacles) :
map{} {
map.reserve((unsigned long) (x));
sizeX = x, sizeY = y;
for (int i1 = 0; i1 < x; i1++) {
map.emplace_back();
map[i1].reserve((unsigned long) (y));
for (int i2 = 0; i2 < y; i2++) {
map[i1].emplace_back();
map[i1][i2] = std::uniform_real_distribution<float>{}(mersenne)
< obstacles ? 1 : 0;
}
}
}
Map::Map(std::vector<std::vector<int>> map) :
map{map},
sizeX{int(map.size())},
sizeY{int(map[0].size())} {
}
void Map::print_map() {
for (int i1 = 0; i1 < sizeX; i1++) {
for (int i2 = 0; i2 < sizeY; i2++) {
std::cout << map[i1][i2];
}
std::cout << std::endl;
}
}
bool Map::has_obstacle(Coordinate coord, Translation size) {
for (int i1 = int(coord.get_x() / Length::METER);
i1 <= int((coord.get_x() + size.get_x()) / Length::METER); i1++) {
for (int i2 = int(coord.get_y() / Length::METER);
i2 <=
int((coord.get_y() + size.get_y()) / Length::METER); i2++) {
if (i1 < 0 || i1 >= sizeX ||
i2 < 0 || i2 >= sizeY ||
map[i1][i2] == 1 || map[i1][i2] == 2) {
return true;
}
}
}
return false;
}
bool Map::has_passable(Coordinate coord, Translation size) {
for (int i1 = int(coord.get_x() / Length::METER);
i1 <= int((coord.get_x() + size.get_x()) / Length::METER); i1++) {
for (int i2 = int(coord.get_y() / Length::METER);
i2 <=
int((coord.get_y() + size.get_y()) / Length::METER); i2++) {
if (i1 < 0 && i1 >= sizeX &&
i2 < 0 && i2 >= sizeY &&
map[i1][i2] == 0) {
return true;
}
}
}
return false;
}
}