forked from Maxluli/RustyPropagation
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc13c48302 | |||
| ced3a93412 | |||
| 3fe4ddc2ee | |||
| eccb238f5e |
9
ReadMe.md
Normal file
9
ReadMe.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Rusty Propagation
|
||||
Run :
|
||||
```
|
||||
cargo run -q
|
||||
```
|
||||
Speed run :
|
||||
```
|
||||
cargo run -q --release
|
||||
```
|
||||
@@ -20,7 +20,7 @@ fn main() {
|
||||
|
||||
|
||||
let disease = Disease::new(20,10,5,String::from("Covid 44"));
|
||||
let mut population = Population::new(20,10,5,300,300,disease);
|
||||
let mut population = Population::new(20,10,5,1000,1000,disease);
|
||||
//population.change_disease(disease);
|
||||
println!("Before Filling");
|
||||
//population.display();
|
||||
|
||||
@@ -50,7 +50,6 @@ impl Population{
|
||||
//One solution to this issue would be to have if else else statements but in this case for example 20% would be lower with the last because its 20% on the remaining population and not of the all
|
||||
//In other words I did it that way but it can be changed just its not the right method to have perfect ratios
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut i: i32 = 0;
|
||||
for x in self.humans.iter_mut() {
|
||||
if rng.gen_range(0..CORRECTED_PERCENTAGE) < self.start_infected_ratio as i32
|
||||
@@ -77,6 +76,7 @@ impl Population{
|
||||
let mut stats: [i32;4] = [0,0,0,0];
|
||||
// stats[0] Normal stats[1] Infected stats[2] Immune stats[3] Dead
|
||||
|
||||
/*
|
||||
for h in self.humans.iter() {
|
||||
match h.present_state{
|
||||
State::Normal => {stats[0] += 1;}
|
||||
@@ -85,7 +85,21 @@ impl Population{
|
||||
State::Dead => {stats[3] += 1;}
|
||||
}
|
||||
}
|
||||
// for pos in &people_to_check {
|
||||
*/
|
||||
|
||||
for x in 0..self.width{
|
||||
for y in 0..self.height{
|
||||
let idx = human_idx(x as i32, y as i32, self.width as i32);
|
||||
match self.humans[idx].present_state{
|
||||
State::Normal => {stats[0] += 1;}
|
||||
State::Infected => {people_to_check.push(Point{x:x,y:y});stats[1]+=1;}
|
||||
State::Immune => {stats[2] += 1;}
|
||||
State::Dead => {stats[3] += 1;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for pos in &people_to_check {
|
||||
for pos in people_to_check.iter() {
|
||||
//people_to_check.iter().map(|pos|{
|
||||
//get all the other people next to me and check if i die cure or infect
|
||||
@@ -169,7 +183,7 @@ impl Population{
|
||||
};
|
||||
for infected_position in &people_to_infect {
|
||||
// println!("To infect: {:?}", infected_position);
|
||||
//people_to_infect.iter().map(|infected_position|{
|
||||
//people_to_infect.iter().map(|infected_position|{
|
||||
let infected_index = human_idx(infected_position.x, infected_position.y, self.width);
|
||||
// let _ = infected_position.x;
|
||||
//DEBUG
|
||||
@@ -194,6 +208,7 @@ impl Population{
|
||||
//DEBUG
|
||||
//println!("Killed someone");
|
||||
};
|
||||
|
||||
stats
|
||||
}
|
||||
pub fn roll(&self,probability:u32)->bool{
|
||||
|
||||
Reference in New Issue
Block a user