chingu-pathfinding 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/chingu_pathfinding/chingu_pathfinding.cpp +16 -8
- data/lib/chingu_pathfinding.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8858650c171257bdd67fb05a33dd949d39571085
|
4
|
+
data.tar.gz: d4752cef76413e77f5eed22aa64826688c90b222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec0100d0ac4eb14e8e76121b3c2949310971a6bf9ce825580c0e6d12300c667a29f3c20750436d97212b71342b918db2f22e5689283c2e8da061320cabbb2856
|
7
|
+
data.tar.gz: 16617428a3c769015618d6b89579a525f15dc65db5ad0a73a10b64257489807ed0e6b80a3aa896058ca4539fd96b32856244775a694d2cbe356993c0a337be8b
|
@@ -9,6 +9,7 @@
|
|
9
9
|
#include <functional>
|
10
10
|
#include <stdexcept>
|
11
11
|
#include <sstream>
|
12
|
+
#include <limits>
|
12
13
|
|
13
14
|
static void Init_pathfinding();
|
14
15
|
|
@@ -37,16 +38,16 @@ struct point_t {
|
|
37
38
|
};
|
38
39
|
typedef std::pair<long int, long int> location_t;
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
return std::
|
41
|
+
float dist(const location_t& a, const location_t& b) {
|
42
|
+
float dx = a.first-b.first;
|
43
|
+
float dy = a.second-b.second;
|
44
|
+
return std::sqrt(dx*dx + dy*dy);
|
44
45
|
}
|
45
46
|
|
46
47
|
class path_t {
|
47
48
|
std::map< location_t, point_t >* map_p;
|
48
49
|
std::multimap< location_t, location_t >* connectivity_p;
|
49
|
-
|
50
|
+
float cost_paid;
|
50
51
|
|
51
52
|
public:
|
52
53
|
std::vector<location_t> path;
|
@@ -55,7 +56,7 @@ class path_t {
|
|
55
56
|
path_t(std::map< location_t, point_t >* mm,
|
56
57
|
std::multimap< location_t, location_t >* cc)
|
57
58
|
: map_p(mm), connectivity_p(cc), cost_paid(0), path() { }
|
58
|
-
|
59
|
+
float get_cost_paid() const { return cost_paid; }
|
59
60
|
void add_loc(location_t l, const location_t& goal) {
|
60
61
|
if (!path.empty()) {
|
61
62
|
location_t last = *path.crbegin();
|
@@ -63,7 +64,7 @@ class path_t {
|
|
63
64
|
}
|
64
65
|
path.push_back(l);
|
65
66
|
}
|
66
|
-
|
67
|
+
float dist_to(const location_t& goal) const {
|
67
68
|
return dist(*path.crbegin(), goal);
|
68
69
|
}
|
69
70
|
|
@@ -98,6 +99,7 @@ class pathfinder_t {
|
|
98
99
|
}
|
99
100
|
|
100
101
|
bool line_blocked(const long int x1, const long int y1, const long int x2, const long int y2) {
|
102
|
+
if (block_size == 1) return false;
|
101
103
|
long int dx = dir(x1, x2);
|
102
104
|
long int dy = dir(y1, y2);
|
103
105
|
long int runner_x = x1;
|
@@ -169,14 +171,20 @@ class pathfinder_t {
|
|
169
171
|
init_path.add_loc(start, goal);
|
170
172
|
// Cut out the part of the path already visited
|
171
173
|
bool drop = true;
|
174
|
+
float last_dist = std::numeric_limits<float>::max();
|
172
175
|
for (location_t l : current) {
|
173
|
-
|
176
|
+
float d = dist(l, start);
|
177
|
+
if (d > last_dist) {
|
174
178
|
drop = false;
|
175
179
|
}
|
176
180
|
if (!drop && start != l) {
|
177
181
|
init_path.add_loc(l, goal);
|
178
182
|
queue.push(init_path);
|
179
183
|
}
|
184
|
+
last_dist = d;
|
185
|
+
}
|
186
|
+
if (queue.empty()) {
|
187
|
+
queue.push(init_path);
|
180
188
|
}
|
181
189
|
// Add every prefix of current to initial guess and converge to new location.
|
182
190
|
return find_path_internal(queue, goal);
|
data/lib/chingu_pathfinding.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chingu-pathfinding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zombiecalypse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Find paths C supported on a static map with the A* algorithm.
|
14
14
|
email: maergil@gmail.com
|