Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed May 2, 2021
1 parent 46e074d commit df2cfa9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions examples/dorf_hero/src/ai/scorers/enemy_distance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use bevy::prelude::*;
use big_brain::{evaluators::{Evaluator, LinearEvaluator}, prelude::*};
use big_brain::{
evaluators::{Evaluator, LinearEvaluator},
prelude::*,
};

use crate::components::{EvilDorf, Hero, Position};
use crate::util;
Expand Down Expand Up @@ -47,21 +50,31 @@ pub fn enemy_distance(
if let Ok(hero_pos) = hero_q.single() {
let distance = util::euclidean_distance(enemy_pos, hero_pos);
if distance <= enemy_distance.within {
score.set(enemy_distance.evaluator.evaluate(distance / enemy_distance.within));
score.set(
enemy_distance
.evaluator
.evaluate(distance / enemy_distance.within),
);
} else {
score.set(0.0);
}
}
}
if let Ok(hero_pos) = hero_q.get(*actor) {
let mut max = 0.;
for enemy_pos in enemy_q.iter() {
let distance = util::euclidean_distance(enemy_pos, hero_pos);
if distance <= enemy_distance.within {
score.set(enemy_distance.evaluator.evaluate(distance / enemy_distance.within));
} else {
score.set(0.0);
let val = enemy_distance.evaluator.evaluate(distance / enemy_distance.within);
if val > max {
max = val;
}
if max >= 1.0 {
break;
}
}
}
score.set(max);
}
}
}

0 comments on commit df2cfa9

Please sign in to comment.