Skip to content

Commit

Permalink
Connected areas to specified point can now be found
Browse files Browse the repository at this point in the history
  • Loading branch information
DrInfy committed Dec 19, 2020
1 parent 9f6f8f9 commit 58d511b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
16 changes: 15 additions & 1 deletion sc2pathlibp/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def get_zone(self, position: Tuple[float, float]) -> int:
Zone 0 is empty zone.
"""
return self._map.get_zone(position)

def calculate_connections(self, start: Tuple[float, float]):
"""
Calculates ground connections to a single point in the map.
Use `is_connected` the check if a location is connected.
"""
self._map.calculate_connections(start)

def is_connected(self, start: Tuple[float, float]) -> bool:
"""
Check if a point is connected to earlier start position used in `calculate_connections`
If `calculate_connections` was not run, returns False.
"""
return self._map.is_connected(start)

def normalize_influence(self, value: int):
self._map.normalize_influence(value)
Expand Down Expand Up @@ -129,7 +143,7 @@ def current_influence(self, map_type: MapType, position: Tuple[float, float]):
"""
Finds the current influence in the position
"""
self._map.current_influence(map_type, position)
return self._map.current_influence(map_type, position)

def add_influence_without_zones(self, zones: List[int], value: float):
"""
Expand Down
40 changes: 40 additions & 0 deletions src/mapping/connections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use pyo3::prelude::*;

use crate::{
helpers::round_point2,
};

use super::{map::Map};

const DIFFERENCE: usize = 12;
const Y_MULT: usize = 1000000;

#[pymethods]
impl Map {
pub fn calculate_connections(&mut self, location: (f32, f32)) {
let pf = self.get_map_mut(0);

let result = pf.djiktra(location, 400f32);

let width = self.ground_pathing.map.len();
let height = self.ground_pathing.map[0].len();

// Reset
for x in 0..width {
for y in 0..height {
self.points[x][y].connected = false;
}
}

// Set non ground connected locations
for data_point in result {
let point = data_point.0;
self.points[point.0][point.1].connected = true;
}
}

pub fn is_connected(&mut self, location: (f32, f32)) -> bool {
let location_int = round_point2(location);
return self.points[location_int.0][location_int.1].connected;
}
}
3 changes: 3 additions & 0 deletions src/mapping/map_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct MapPoint {
pub pathable: bool,
pub walkable: bool,
pub climbable: bool,
pub connected: bool,
pub structure_index: i32,
pub height: usize,
pub overlord_spot: bool,
Expand All @@ -31,6 +32,7 @@ impl MapPoint {
let pathable = false;
let walkable = false;
let climbable = false;
let connected = false;
let structure_index = 0_i32;
let height = 0;
let overlord_spot = false;
Expand All @@ -42,6 +44,7 @@ impl MapPoint {
pathable,
walkable,
climbable,
connected,
structure_index,
height,
overlord_spot,
Expand Down
1 change: 1 addition & 0 deletions src/mapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod influence;
pub mod map;
pub mod map_point;
pub mod zones;
pub mod connections;
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def read_maze(file_name: str) -> List[List[int]]:
count = 0
ns_pf = time.perf_counter_ns()
pf.normalize_influence(100)
pf.heuristic_accuracy = 2
pf.heuristic_accuracy = 1

for pos1 in expansions:
for pos2 in expansions:
Expand Down

0 comments on commit 58d511b

Please sign in to comment.