forked from Maxluli/RustyPropagation
Compare commits
2 Commits
bdb6e60e98
...
3a41670fea
| Author | SHA1 | Date | |
|---|---|---|---|
|
3a41670fea
|
|||
|
fb6e9e82b3
|
+54
-67
@@ -108,6 +108,8 @@ impl Population {
|
|||||||
pub fn propagate(&mut self) -> [i32; 4] {
|
pub fn propagate(&mut self) -> [i32; 4] {
|
||||||
let mut people_to_check: Vec<Point> =
|
let mut people_to_check: Vec<Point> =
|
||||||
Vec::with_capacity((self.width * self.height) as usize);
|
Vec::with_capacity((self.width * self.height) as usize);
|
||||||
|
let mut possible_infected: Vec<Point> =
|
||||||
|
Vec::with_capacity((self.width * self.height) as usize);
|
||||||
let mut people_to_infect: Vec<Point> =
|
let mut people_to_infect: Vec<Point> =
|
||||||
Vec::with_capacity((self.width * self.height) as usize);
|
Vec::with_capacity((self.width * self.height) as usize);
|
||||||
let mut people_to_cure: Vec<Point> =
|
let mut people_to_cure: Vec<Point> =
|
||||||
@@ -120,6 +122,7 @@ impl Population {
|
|||||||
for h in self.humans.iter() {
|
for h in self.humans.iter() {
|
||||||
match h.present_state {
|
match h.present_state {
|
||||||
State::Normal => {
|
State::Normal => {
|
||||||
|
possible_infected.push(Point{ x: h.x, y: h.y});
|
||||||
stats[0] += 1;
|
stats[0] += 1;
|
||||||
}
|
}
|
||||||
State::Infected => {
|
State::Infected => {
|
||||||
@@ -150,75 +153,59 @@ impl Population {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for pos in self.humans.iter() {
|
for pos in possible_infected.iter() {
|
||||||
if pos.present_state == State::Normal {
|
let infected: bool = self.is_inside_and_infected(
|
||||||
let infected: bool = self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x - 1,
|
||||||
x: pos.x - 1,
|
y: pos.y - 1,
|
||||||
y: pos.y - 1,
|
},
|
||||||
},
|
) || //Top Left
|
||||||
) || //Top Left
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x,
|
||||||
x: pos.x,
|
y: pos.y - 1,
|
||||||
y: pos.y - 1,
|
},
|
||||||
},
|
) || //Top
|
||||||
) || //Top
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x + 1,
|
||||||
x: pos.x + 1,
|
y: pos.y - 1,
|
||||||
y: pos.y - 1,
|
},
|
||||||
},
|
) || //Top Right
|
||||||
) || //Top Right
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x - 1,
|
||||||
x: pos.x - 1,
|
y: pos.y,
|
||||||
y: pos.y,
|
},
|
||||||
},
|
) || //Left
|
||||||
) || //Left
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x + 1,
|
||||||
x: pos.x + 1,
|
y: pos.y,
|
||||||
y: pos.y,
|
},
|
||||||
},
|
) || //Right
|
||||||
) || //Right
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x - 1,
|
||||||
x: pos.x - 1,
|
y: pos.y + 1,
|
||||||
y: pos.y + 1,
|
},
|
||||||
},
|
) || //Bottom Left
|
||||||
) || //Bottom Left
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x,
|
||||||
x: pos.x,
|
y: pos.y + 1,
|
||||||
y: pos.y + 1,
|
},
|
||||||
},
|
) || //Bottom
|
||||||
) || //Bottom
|
self.is_inside_and_infected(
|
||||||
self.is_inside_and_infected(
|
Point {
|
||||||
Point {
|
x: pos.x + 1,
|
||||||
x: pos.x + 1,
|
y: pos.y + 1,
|
||||||
y: pos.y + 1,
|
},
|
||||||
},
|
); //Bottom Right
|
||||||
);
|
if infected {
|
||||||
if infected {
|
people_to_infect.push(Point { x: pos.x, y: pos.y });
|
||||||
people_to_infect.push(Point { x: pos.x, y: pos.y });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ); //Bottom Right
|
|
||||||
// for poss_infected_pos in possible_infections.iter() {
|
|
||||||
// //possible_infections.iter().map(|poss_infected_pos|{
|
|
||||||
// let inf_idx =
|
|
||||||
// human_idx(poss_infected_pos.x, poss_infected_pos.y, self.width);
|
|
||||||
// if self.humans[inf_idx].present_state == State::Normal {
|
|
||||||
// if roll(self.plague.infection_rate) {
|
|
||||||
// people_to_infect.push(Point {
|
|
||||||
// x: poss_infected_pos.x,
|
|
||||||
// y: poss_infected_pos.y,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
for infected_position in people_to_infect.iter() {
|
for infected_position in people_to_infect.iter() {
|
||||||
// println!("To infect: {:?}", infected_position);
|
// println!("To infect: {:?}", infected_position);
|
||||||
|
|||||||
Reference in New Issue
Block a user