bot uses random skill not just highest cooldown

This commit is contained in:
ntr 2019-04-11 10:15:06 +10:00
parent 0f21269a7e
commit d69b74653e
2 changed files with 11 additions and 8 deletions

View File

@ -335,14 +335,17 @@ impl Cryp {
return None; return None;
} }
let highest_cd = available.iter() let mut rng = thread_rng();
.filter(|s| s.skill.base_cd().is_some()) return Some(available[rng.gen_range(0, available.len())].skill);
.max_by_key(|s| s.skill.base_cd().unwrap());
return match highest_cd { // let highest_cd = available.iter()
Some(s) => Some(s.skill), // .filter(|s| s.skill.base_cd().is_some())
None => Some(available[0].skill), // .max_by_key(|s| s.skill.base_cd().unwrap());
};
// return match highest_cd {
// Some(s) => Some(s.skill),
// None => Some(available[0].skill),
// };
} }
pub fn knows(&self, skill: Skill) -> bool { pub fn knows(&self, skill: Skill) -> bool {

View File

@ -391,6 +391,6 @@ mod tests {
let mut player = Player::new(player_account, Uuid::new_v4(), &"test".to_string(), cryps).set_bot(true); let mut player = Player::new(player_account, Uuid::new_v4(), &"test".to_string(), cryps).set_bot(true);
player.autobuy(); player.autobuy();
println!("{:#?}", player); assert!(player.cryps.iter().all(|c| c.skills.len() == 2));
} }
} }