Skip to content

Commit 612af48

Browse files
authored
Merge pull request #23 from DrInfy/find_low_inside_fixes
Find low inside fixes
2 parents 1e5ef47 + abcb06b commit 612af48

File tree

13 files changed

+295
-226
lines changed

13 files changed

+295
-226
lines changed

kite_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def read_maze(file_name: str) -> List[List[int]]:
1919

2020
maze = read_maze("tests/empty10x10.txt")
2121
pf = sc2pathlibp.PathFinder(maze)
22-
pf.normalize_influence(1)
22+
pf.normalize_influence(10)
2323
enemy_pos = (4, 0)
24-
start_pos = (5, 5)
24+
start_pos = (5, 2)
2525
pf.add_influence_walk([enemy_pos], 100, 7)
2626
end_result = pf.find_low_inside_walk(start_pos, enemy_pos, 5)
2727
print(end_result)

sc2pathlibp/map.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
class Sc2Map:
10+
__slots__ = ['_overlord_spots', '_chokes', 'heuristic_accuracy', 'height_map', '_map']
11+
1012
def __init__(
1113
self,
1214
pathing_grid: np.ndarray,
@@ -119,10 +121,10 @@ def add_walk_influence(self, points: List["sc.Point2"], influence: float, range:
119121
self._map.add_influence_walk(points, influence, range)
120122

121123
def add_tank_influence(
122-
self, points: List["sc.Point2"], influence: float, tank_min_range: float = 3, tank_max_range: float = 14.5
124+
self, points: List["sc.Point2"], influence: float, tank_min_range: float = 2.5, tank_max_range: float = 14.5
123125
):
124126
"""
125-
:param tank_min_range: Tank minimum range is 2, adding both unit radiuses to that and we'll estimate it to be 3.
127+
:param tank_min_range: Tank minimum range is 2, adding both unit radiuses to that and we'll estimate it to be 2.5.
126128
:param tank_max_range: Same for max range, 13, but but with unit radius, let's say it's 14.5 instead to err on the safe side
127129
"""
128130
self._map.add_influence_flat_hollow(points, influence, tank_min_range, tank_max_range)

src/helpers/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
pub fn round_point2(point: (f32, f32)) -> (usize, usize) {
22
let x = point.0.round() as usize;
33
let y = point.1.round() as usize;
4-
return (x, y);
4+
(x, y)
5+
}
6+
7+
pub fn point2_f32(point: (usize, usize)) -> (f32, f32) {
8+
let x = point.0 as f32;
9+
let y = point.1 as f32;
10+
(x, y)
511
}

src/mapping/chokes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,5 @@ fn distance(first: (usize, usize), second: (usize, usize)) -> f32 {
331331
let pos1 = Pos(first.0, first.1);
332332
let pos2 = Pos(second.0, second.1);
333333

334-
return pos1.euclidean_distance(&pos2) as f32 / MULTF32;
334+
pos1.euclidean_distance(&pos2) as f32 / MULTF32
335335
}

src/mapping/influence.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl Map {
151151
maps.push(&mut self.reaper_pathing);
152152
}
153153

154-
return maps;
154+
maps
155155
}
156156

157157
fn get_pure_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -162,7 +162,7 @@ impl Map {
162162
maps.push(&mut self.reaper_pathing);
163163
}
164164

165-
return maps;
165+
maps
166166
}
167167

168168
pub fn get_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -176,7 +176,7 @@ impl Map {
176176
maps.push(&mut self.reaper_pathing);
177177
}
178178

179-
return maps;
179+
maps
180180
}
181181

182182
pub fn get_air_influence_maps(&mut self) -> Vec<&mut PathFind> {
@@ -187,6 +187,6 @@ impl Map {
187187
maps.push(&mut self.colossus_pathing);
188188
}
189189

190-
return maps;
190+
maps
191191
}
192192
}

src/mapping/map.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,29 @@ impl Map {
150150
}
151151
}
152152

153-
return result;
153+
result
154154
}
155155

156156
/// Returns current influence value
157157
fn current_influence(&self, map_type: u8, position: (f32, f32)) -> f32 {
158158
let map = self.get_map(map_type);
159159
let position_int = round_point2(position);
160160

161-
return map.current_influence(position_int) as f32;
161+
map.current_influence(position_int) as f32
162162
}
163163

164164
/// Finds the first reachable position within specified walking distance from the center point with lowest value
165165
fn lowest_influence_walk(&self, map_type: u8, center: (f32, f32), distance: f32) -> ((usize, usize), f32) {
166166
let map = self.get_map(map_type);
167167
let center_int = round_point2(center);
168168

169-
return map.lowest_influence_walk(center_int, distance);
169+
map.lowest_influence_walk(center_int, distance)
170170
}
171171

172172
/// Finds the first reachable position within specified distance from the center point with lowest value
173173
pub fn lowest_influence(&self, map_type: u8, center: (f32, f32), distance: usize) -> ((usize, usize), f32) {
174174
let map = self.get_map(map_type);
175-
return map.inline_lowest_value(center, distance);
175+
map.inline_lowest_value(center, distance)
176176
}
177177

178178
/// Find the shortest path values without considering influence and returns the path and distance
@@ -186,7 +186,7 @@ impl Map {
186186
let end_int = (end.0.round() as usize, end.1.round() as usize);
187187

188188
let map = self.get_map(map_type);
189-
return map.find_path(start_int, end_int, possible_heuristic);
189+
map.find_path(start_int, end_int, possible_heuristic)
190190
}
191191

192192
/// Find the shortest path values without considering influence and returns the path and distance
@@ -200,7 +200,7 @@ impl Map {
200200
let end_int = (end.0.round() as usize, end.1.round() as usize);
201201

202202
let map = self.get_map(map_type);
203-
return map.find_path_large(start_int, end_int, possible_heuristic);
203+
map.find_path_large(start_int, end_int, possible_heuristic)
204204
}
205205

206206
/// Find the path using influence values and returns the path and distance
@@ -213,7 +213,7 @@ impl Map {
213213
let start_int = (start.0.round() as usize, start.1.round() as usize);
214214
let end_int = (end.0.round() as usize, end.1.round() as usize);
215215
let map = self.get_map(map_type);
216-
return map.find_path_influence(start_int, end_int, possible_heuristic);
216+
map.find_path_influence(start_int, end_int, possible_heuristic)
217217
}
218218

219219
/// Find the path using influence values and returns the path and distance
@@ -226,7 +226,7 @@ impl Map {
226226
let start_int = (start.0.round() as usize, start.1.round() as usize);
227227
let end_int = (end.0.round() as usize, end.1.round() as usize);
228228
let map = self.get_map(map_type);
229-
return map.find_path_influence_large(start_int, end_int, possible_heuristic);
229+
map.find_path_influence_large(start_int, end_int, possible_heuristic)
230230
}
231231

232232
/// Find the shortest path values without considering influence and returns the path and distance
@@ -241,7 +241,7 @@ impl Map {
241241
let end_int = (end.0.round() as usize, end.1.round() as usize);
242242

243243
let map = self.get_map(map_type);
244-
return map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
244+
map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
245245
}
246246

247247
/// Find the shortest path values without considering influence and returns the path and distance
@@ -256,7 +256,7 @@ impl Map {
256256
let end_int = (end.0.round() as usize, end.1.round() as usize);
257257

258258
let map = self.get_map(map_type);
259-
return map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
259+
map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
260260
}
261261

262262
/// Find the path using influence values and returns the path and distance
@@ -270,7 +270,7 @@ impl Map {
270270
let start_int = (start.0.round() as usize, start.1.round() as usize);
271271
let end_int = (end.0.round() as usize, end.1.round() as usize);
272272
let map = self.get_map(map_type);
273-
return map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
273+
map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
274274
}
275275

276276
/// Find the path using influence values and returns the path and distance
@@ -284,7 +284,7 @@ impl Map {
284284
let start_int = (start.0.round() as usize, start.1.round() as usize);
285285
let end_int = (end.0.round() as usize, end.1.round() as usize);
286286
let map = self.get_map(map_type);
287-
return map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
287+
map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
288288
}
289289

290290
/// Finds a compromise where low influence matches with close position to the start position.
@@ -295,7 +295,7 @@ impl Map {
295295
distance: f32)
296296
-> ((f32, f32), f32) {
297297
let map = self.get_map(map_type);
298-
return map.find_low_inside_walk(start, target, distance);
298+
map.find_low_inside_walk(start, target, distance)
299299
}
300300
}
301301

@@ -402,14 +402,13 @@ impl Map {
402402

403403
let c = points[x][y].cliff_type;
404404

405-
if c != Cliff::None {
406-
if points[x + 1][y].cliff_type != c
407-
&& points[x - 1][y].cliff_type != c
408-
&& points[x][y + 1].cliff_type != c
409-
&& points[x][y - 1].cliff_type != c
410-
{
411-
points[x][y].cliff_type = Cliff::None;
412-
}
405+
if c != Cliff::None
406+
&& points[x + 1][y].cliff_type != c
407+
&& points[x - 1][y].cliff_type != c
408+
&& points[x][y + 1].cliff_type != c
409+
&& points[x][y - 1].cliff_type != c
410+
{
411+
points[x][y].cliff_type = Cliff::None;
413412
}
414413

415414
if !set_handled_overlord_spots.contains(&point_hash) && points[x][y].overlord_spot {
@@ -515,7 +514,7 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,
515514

516515
let mut result = true;
517516
points[x][y].overlord_spot = replacement;
518-
// if points[x][y].overlord_spot == target {
517+
519518
if y > 0 {
520519
result &= flood_fill_overlord(points, x, ((y as u32) - 1) as usize, target_height, replacement, set);
521520
}
@@ -528,7 +527,6 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,
528527
if x < points.len() - 1 {
529528
result &= flood_fill_overlord(points, x + 1, y, target_height, replacement, set);
530529
}
531-
// }
532530

533-
return result;
531+
result
534532
}

src/mapping/zones.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ impl Map {
7373

7474
pub fn get_zone(&self, position: (f32, f32)) -> i8 {
7575
let u_position = round_point2(position);
76-
let index = self.points[u_position.0][u_position.1].zone_index;
77-
index
76+
self.points[u_position.0][u_position.1].zone_index
7877
}
7978
}
8079

8180
impl Map {
82-
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { return &mut self.points[x][y]; }
83-
fn zone_index(&mut self, x: usize, y: usize) -> i8 { return self.points[x][y].zone_index; }
81+
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { &mut self.points[x][y] }
82+
fn zone_index(&mut self, x: usize, y: usize) -> i8 { self.points[x][y].zone_index }
8483
}
8584

8685
fn flood_fill(map: &mut Map,
@@ -128,7 +127,6 @@ fn flood_fill(map: &mut Map,
128127
return;
129128
}
130129

131-
// if points[x][y].overlord_spot == target {
132130
if y > 0 {
133131
flood_fill(map, x, ((y as u32) - 1) as usize, target_height, zone_index, origin, sorted_base_locations);
134132
}
@@ -141,7 +139,4 @@ fn flood_fill(map: &mut Map,
141139
if x < map.points.len() - 1 {
142140
flood_fill(map, x + 1, y, target_height, zone_index, origin, sorted_base_locations);
143141
}
144-
// }
145-
146-
return;
147142
}

0 commit comments

Comments
 (0)