summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/knowledge.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/knowledge.rs b/src/knowledge.rs
index f8d71eb..1923f41 100644
--- a/src/knowledge.rs
+++ b/src/knowledge.rs
@@ -4,6 +4,7 @@ use state::*;
use math::*;
use std::collections::HashMap;
+use std::cmp::Ordering;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Knowledge {
@@ -215,7 +216,11 @@ impl Knowledge {
let best: (Weapon, (Vec<Point>, usize)) =
best_shots.iter()
- .max_by_key(|&(_, &(_, score))| score)
+ .max_by(|&(weapon_a, &(_, score_a)), &(weapon_b, &(_, score_b))| {
+ let score = score_a.cmp(&score_b);
+ let cost = weapon_a.energy_cost(self.map_size).cmp(&weapon_b.energy_cost(self.map_size));
+ if score == Ordering::Equal { cost } else { score }
+ })
.and_then(|(&weapon, x)| {
if self.shootable_weapons.contains(&weapon) {
Some((weapon, x.clone()))