Skip to content

Commit

Permalink
fix movement
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevin96 committed Jun 4, 2024
1 parent a3c2a2b commit fe599d9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 39 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ members = [
"template",
"virusnetwork",
"wolfsheepgrass",
"gis",
]
2 changes: 1 addition & 1 deletion gis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
krabmaga = {path="/home/tirocinio/krABMaga"}
krabmaga = {path="../../krABMaga"}
rand = "0.8"

[features]
Expand Down
69 changes: 61 additions & 8 deletions gis/maps/map.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,70 @@
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[5.0, 25.0],
[25.0, 25.0],
[25.0, 5.0],
[5.0, 5.0],
[5.0, 25.0]
5.0,
25.0
],
[
25.0,
25.0
]
],
"type": "LineString"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
25.0,
25.0
],
[
25.0,
5.0
]
],
"type": "LineString"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
25.0,
5.0
],
[
5.0,
5.0
]
],
"type": "LineString"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
5.0,
5.0
],
[
5.0,
25.0
]
]
],
"type": "LineString"
}
}

]
}
}
2 changes: 1 addition & 1 deletion gis/src/model/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl State for Map {
}

fn set_gis(&mut self, vec: Vec<i32>, schedule: &mut Schedule) {
let loc = Real2D { x: 10., y: 10. };
let loc = Real2D { x: 4., y: 4. };
let agent = Person {
id: 0 as u32,
loc,
Expand Down
41 changes: 13 additions & 28 deletions gis/src/model/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,27 @@ impl Person {

for dx in -1..2 {
for dy in -1..2 {

let new_x = dx + x;
let new_y = dy + y;

if (dx != 0 && dy != 0) && map.gis_value(Int2D { x: new_x, y: new_y }) == 1 {
if map.gis_value(Int2D { x: new_x, y: new_y }) == 1 {
if dx == 0 && dy == -1 {
possible_direction.push(Direction::Down);
possible_direction.push(Direction::Up);
}
if dx == 1 && dy == 0 {
possible_direction.push(Direction::Right);
possible_direction.push(Direction::Left);
}
if dx == -1 && dy == 0 {
possible_direction.push(Direction::Left);
possible_direction.push(Direction::Right);
}
if dx == 0 && dy == 1 {
possible_direction.push(Direction::Up);
}
if dx == 1 && dy == -1 {
possible_direction.push(Direction::DownRight);
}
if dx == 1 && dy == 1 {
possible_direction.push(Direction::UpRight);
}
if dx == -1 && dy == 1 {
possible_direction.push(Direction::UpLeft);
}
if dx == -1 && dy == -1 {
possible_direction.push(Direction::DownLeft);
possible_direction.push(Direction::Down);
}
}
}
}

let rand_index = rand::thread_rng().gen_range(0..=possible_direction.len() - 1);
new_direction = possible_direction[rand_index];

/* match curr_direction {

match curr_direction {
Some(Direction::Left) => {
if possible_direction.contains(&Direction::Left) {
new_direction = Direction::Left;
Expand Down Expand Up @@ -136,7 +121,7 @@ impl Person {
}
}
None => new_direction = Direction::Left,
} */
}

Some(new_direction)
}
Expand All @@ -150,19 +135,19 @@ impl Agent for Person {

match direction {
Some(Direction::Left) => {
self.loc.x -= 1.;
self.loc.x += 1.;
self.direction = Some(Direction::Left);
}
Some(Direction::Right) => {
self.loc.x += 1.;
self.loc.x -= 1.;
self.direction = Some(Direction::Right);
}
Some(Direction::Up) => {
self.loc.y += 1.;
self.loc.y -= 1.;
self.direction = Some(Direction::Up);
}
Some(Direction::Down) => {
self.loc.y -= 1.;
self.loc.y += 1.;
self.direction = Some(Direction::Down);
}
Some(Direction::UpRight) => {
Expand Down
2 changes: 1 addition & 1 deletion gis/src/visualization/person_vis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl AgentRender for PersonVis {

/// Specify how much the texture should be scaled by. A common scale is (0.1, 0.1).
fn scale(&self, _agent: &Box<dyn Agent>, _state: &Box<&dyn State>) -> (f32, f32) {
(0.2, 0.2)
(0.05, 0.05)
}

/// Define the degrees in radians to rotate the texture by.
Expand Down

0 comments on commit fe599d9

Please sign in to comment.