Started C# porting git add . NOT WORKING FOR NOW

This commit is contained in:
2022-04-29 11:32:48 +02:00
commit 404c5b91a7
7 changed files with 291 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
use crate::prelude::*;
use rand::Rng;
pub const MUTATION_TRAIT_INCREASE_PROBABILITY:i32 = 50;
pub const MUTATION_TRAIT_CHANGE_AMOUNT:i32 = 20;
pub struct Disease {
pub infection_rate:u32,
pub curing_rate:u32,
pub death_rate:u32,
pub traits: Vec<u32>,
pub name: String,
}
impl Disease{
pub fn new(infection_r:u32,curing_r:u32,death_r:u32,the_name:String) -> Self{
Self{
infection_rate : infection_r,
curing_rate : curing_r,
death_rate : death_r,
name : the_name,
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;
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;
}
}
}