enlarged kill radius
This commit is contained in:
parent
17551f2ae2
commit
aef4cffd43
1 changed files with 17 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ use parry2d::shape::Shape;
|
||||||
|
|
||||||
const VIEW_DIST: f32 = 180.0;
|
const VIEW_DIST: f32 = 180.0;
|
||||||
const BOT_RADIUS: f32 = 16.0;
|
const BOT_RADIUS: f32 = 16.0;
|
||||||
|
const KILL_RADIUS: f32 = 140.0;
|
||||||
|
|
||||||
trait Mortal {
|
trait Mortal {
|
||||||
fn collider(&self) -> (&Pose, &dyn Shape);
|
fn collider(&self) -> (&Pose, &dyn Shape);
|
||||||
|
|
@ -85,11 +86,11 @@ impl Robot {
|
||||||
|
|
||||||
fn draw_weapon(&self) {
|
fn draw_weapon(&self) {
|
||||||
let tl = self.pose.translation;
|
let tl = self.pose.translation;
|
||||||
draw_circle(tl.x, tl.y, 80.0, ORANGE);
|
draw_circle(tl.x, tl.y, KILL_RADIUS, ORANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn weapon<'a>(&self, peers: impl Iterator<Item = &'a dyn Mortal>) {
|
fn weapon<'a>(&self, peers: impl Iterator<Item = &'a dyn Mortal>) {
|
||||||
let weapon = Ball::new(80.0);
|
let weapon = Ball::new(KILL_RADIUS);
|
||||||
|
|
||||||
for peer in peers {
|
for peer in peers {
|
||||||
let (p_p, p_c) = peer.collider();
|
let (p_p, p_c) = peer.collider();
|
||||||
|
|
@ -105,7 +106,7 @@ impl Robot {
|
||||||
match sensor {
|
match sensor {
|
||||||
Sensor::Food => self.move_step(1.0, 0.0),
|
Sensor::Food => self.move_step(1.0, 0.0),
|
||||||
Sensor::Kin => self.move_step(-0.3, 0.02),
|
Sensor::Kin => self.move_step(-0.3, 0.02),
|
||||||
Sensor::NonKin => self.move_step(-0.3, 0.02),
|
Sensor::NonKin => self.move_step(0.3, -0.02),
|
||||||
Sensor::None => self.move_step(0.3, 0.01),
|
Sensor::None => self.move_step(0.3, 0.01),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,13 +163,14 @@ impl Food {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_simulation() -> (i32, i32) {
|
async fn run_simulation() -> (i32, i32) {
|
||||||
|
let mut watchdog = 0; // iterations since something interesting
|
||||||
let mut robots = Vec::new();
|
let mut robots = Vec::new();
|
||||||
|
|
||||||
let mut score = HashMap::new();
|
let mut score = HashMap::new();
|
||||||
|
|
||||||
for i in 5..20 {
|
for i in 5..20 {
|
||||||
robots.push(Robot::new(Vec2 { x: 100.0, y: i as f32*50.0 }, RED));
|
robots.push(Robot::new(Vec2 { x: 100.0, y: i as f32*50.0 }, BLUE));
|
||||||
robots.push(Robot::new(Vec2 { x: 1200.0, y: i as f32*50.0 }, BLUE));
|
robots.push(Robot::new(Vec2 { x: 1200.0, y: i as f32*50.0 }, RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut food = Vec::new();
|
let mut food = Vec::new();
|
||||||
|
|
@ -192,7 +194,8 @@ async fn run_simulation() -> (i32, i32) {
|
||||||
|
|
||||||
let mut loo = 0;
|
let mut loo = 0;
|
||||||
loop {
|
loop {
|
||||||
let rendered = loo %1 == 0;
|
let rendered = loo %90 == 0;
|
||||||
|
//let rendered = false;
|
||||||
clear_background(LIGHTGRAY);
|
clear_background(LIGHTGRAY);
|
||||||
|
|
||||||
for food in &mut food{
|
for food in &mut food{
|
||||||
|
|
@ -200,6 +203,7 @@ async fn run_simulation() -> (i32, i32) {
|
||||||
if food.living() {
|
if food.living() {
|
||||||
score.entry(color_hash(team)).and_modify(|s| *s +=1 ).or_insert(1);
|
score.entry(color_hash(team)).and_modify(|s| *s +=1 ).or_insert(1);
|
||||||
food.kill();
|
food.kill();
|
||||||
|
watchdog = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rendered { food.draw(); }
|
if rendered { food.draw(); }
|
||||||
|
|
@ -239,9 +243,12 @@ async fn run_simulation() -> (i32, i32) {
|
||||||
let robots = robots.map(|r| r as &dyn Mortal);
|
let robots = robots.map(|r| r as &dyn Mortal);
|
||||||
let peers = robots.chain(food.iter().map(|f| f as &dyn Mortal));
|
let peers = robots.chain(food.iter().map(|f| f as &dyn Mortal));
|
||||||
|
|
||||||
let death = robot.policy(&sensors[idx]);
|
let mut death = robot.policy(&sensors[idx]);
|
||||||
|
if robot.team == BLUE {
|
||||||
|
death = false; // pacifists
|
||||||
|
}
|
||||||
if death {
|
if death {
|
||||||
if rendered {robot.draw_weapon();}
|
if true {robot.draw_weapon();}
|
||||||
robot.weapon(peers);
|
robot.weapon(peers);
|
||||||
}
|
}
|
||||||
if rendered { robot.draw();}
|
if rendered { robot.draw();}
|
||||||
|
|
@ -255,7 +262,8 @@ async fn run_simulation() -> (i32, i32) {
|
||||||
next_frame().await // TODO: framerate cap
|
next_frame().await // TODO: framerate cap
|
||||||
}
|
}
|
||||||
|
|
||||||
if food.is_empty() {
|
watchdog += 1;
|
||||||
|
if food.is_empty() || watchdog > 1000 {
|
||||||
let red = score.get(&color_hash(RED)).unwrap_or(&0);
|
let red = score.get(&color_hash(RED)).unwrap_or(&0);
|
||||||
let blu = score.get(&color_hash(BLUE)).unwrap_or(&0);
|
let blu = score.get(&color_hash(BLUE)).unwrap_or(&0);
|
||||||
return (*red, *blu);
|
return (*red, *blu);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue