forked from Maxluli/RustyPropagation
Many fixes:
- comment out dead code - reduce number of casting - fix loop block
This commit is contained in:
+20
-19
@@ -1,9 +1,10 @@
|
||||
use crate::prelude::*;
|
||||
// use crate::prelude::*;
|
||||
|
||||
|
||||
pub const MUTATION_TRAIT_INCREASE_PROBABILITY:i32 = 50;
|
||||
pub const MUTATION_TRAIT_CHANGE_AMOUNT:i32 = 20;
|
||||
// pub const MUTATION_TRAIT_INCREASE_PROBABILITY:i32 = 50;
|
||||
// pub const MUTATION_TRAIT_CHANGE_AMOUNT:i32 = 20;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Disease {
|
||||
pub infection_rate:u32,
|
||||
pub curing_rate:u32,
|
||||
@@ -21,21 +22,21 @@ impl Disease{
|
||||
traits : vec![infection_r,curing_r,death_r],
|
||||
}
|
||||
}
|
||||
pub fn mutate(&mut self){
|
||||
let mut rng = rand::thread_rng();
|
||||
for i in 0..self.traits.len(){
|
||||
let mut new_ratio:i32 = self.traits[i] as i32;
|
||||
// pub fn mutate(&mut self){
|
||||
// let mut rng = rand::thread_rng();
|
||||
// for i in 0..self.traits.len(){
|
||||
// let mut new_ratio:i32 = self.traits[i] as i32;
|
||||
|
||||
if rng.gen_range(0..CORRECTED_PERCENTAGE) >= MUTATION_TRAIT_INCREASE_PROBABILITY{
|
||||
new_ratio += MUTATION_TRAIT_CHANGE_AMOUNT;
|
||||
}else{
|
||||
new_ratio -= MUTATION_TRAIT_CHANGE_AMOUNT;
|
||||
}
|
||||
if new_ratio < 0{
|
||||
new_ratio = 0;
|
||||
}
|
||||
new_ratio = new_ratio % CORRECTED_PERCENTAGE;
|
||||
self.traits[i] = new_ratio as u32;
|
||||
}
|
||||
}
|
||||
// if rng.gen_range(0..CORRECTED_PERCENTAGE) >= MUTATION_TRAIT_INCREASE_PROBABILITY{
|
||||
// new_ratio += MUTATION_TRAIT_CHANGE_AMOUNT;
|
||||
// }else{
|
||||
// new_ratio -= MUTATION_TRAIT_CHANGE_AMOUNT;
|
||||
// }
|
||||
// if new_ratio < 0{
|
||||
// new_ratio = 0;
|
||||
// }
|
||||
// new_ratio = new_ratio % CORRECTED_PERCENTAGE;
|
||||
// self.traits[i] = new_ratio as u32;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user