Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
3af34dfb5e |
|||
|
bd22161bbc |
|||
|
710050f01a |
|||
|
c491497129 |
2 changed files with 34 additions and 18 deletions
|
|
@ -1,11 +1,12 @@
|
||||||
food_amount = 120
|
food_amount = 100
|
||||||
|
view_dist = 200
|
||||||
red_count = 10
|
red_count = 10
|
||||||
blu_count = 10
|
blu_count = 10
|
||||||
|
|
||||||
[weapon]
|
[weapon]
|
||||||
kills_user = false
|
kills_user = true
|
||||||
model.type = "lazer"
|
type = "forwardball"
|
||||||
model.range = 120
|
radius = 90
|
||||||
|
|
||||||
[red_policy]
|
[red_policy]
|
||||||
aggressive = true
|
aggressive = true
|
||||||
|
|
@ -18,5 +19,5 @@ none= [0.3, 0.01]
|
||||||
aggressive = false
|
aggressive = false
|
||||||
food = [1,0]
|
food = [1,0]
|
||||||
kin = [-0.3,0.02]
|
kin = [-0.3,0.02]
|
||||||
nonkin = [0.3,-0.02]
|
nonkin = [-0.3,-0.02]
|
||||||
none= [0.3, 0.01]
|
none= [0.3, 0.01]
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,7 @@ use clap::Parser;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -48,6 +46,7 @@ struct Robot {
|
||||||
team: Color,
|
team: Color,
|
||||||
policy: Policy,
|
policy: Policy,
|
||||||
weapon: Weapon,
|
weapon: Weapon,
|
||||||
|
view_dist: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mortal for Robot {
|
impl Mortal for Robot {
|
||||||
|
|
@ -72,8 +71,8 @@ impl Mortal for Robot {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Robot {
|
impl Robot {
|
||||||
fn new(pose: Pose, team: Color, policy: Policy, weapon: Weapon) -> Self {
|
fn new(pose: Pose, team: Color, policy: Policy, weapon: Weapon, view_dist: f32) -> Self {
|
||||||
Self { pose, alive: AtomicBool::new(true), collider: Ball::new(BOT_RADIUS), team, policy, weapon}
|
Self { pose, alive: AtomicBool::new(true), collider: Ball::new(BOT_RADIUS), team, policy, weapon, view_dist}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_step(&mut self, forward_right: [f32;2]) {
|
fn move_step(&mut self, forward_right: [f32;2]) {
|
||||||
|
|
@ -87,7 +86,7 @@ impl Robot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_end(&self) -> Vec2 {
|
fn view_end(&self) -> Vec2 {
|
||||||
self.pose.translation + self.ahead() * VIEW_DIST
|
self.pose.translation + self.ahead() * self.view_dist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -99,8 +98,7 @@ impl Robot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crater(&self) -> (f32, f32, f32, Color) {
|
fn crater(&self) -> (f32, f32, f32, Color) {
|
||||||
let tl = self.pose.translation;
|
self.weapon.model.crater(self)
|
||||||
(tl.x, tl.y, KILL_RADIUS, ORANGE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_weapon(&self) {
|
fn draw_weapon(&self) {
|
||||||
|
|
@ -116,14 +114,13 @@ impl Robot {
|
||||||
|
|
||||||
if let Some(_) = contact(&pose, &*weapon, p_p , p_c, 0.0).unwrap() {
|
if let Some(_) = contact(&pose, &*weapon, p_p , p_c, 0.0).unwrap() {
|
||||||
peer.kill();
|
peer.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
if self.weapon.kills_user {
|
if self.weapon.kills_user {
|
||||||
self.kill(); // o7
|
self.kill(); // o7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn policy(&mut self, sensor: &Sensor) -> bool{
|
pub fn policy(&mut self, sensor: &Sensor) -> bool{
|
||||||
match sensor {
|
match sensor {
|
||||||
Sensor::Food => self.move_step(self.policy.food),
|
Sensor::Food => self.move_step(self.policy.food),
|
||||||
|
|
@ -218,17 +215,35 @@ impl WeaponType {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn crater(&self, robot: &Robot) -> (f32, f32, f32, Color) {
|
||||||
|
match self {
|
||||||
|
WeaponType::Ball{radius} => {
|
||||||
|
let tl = robot.pose.translation;
|
||||||
|
(tl.x, tl.y, *radius, ORANGE)
|
||||||
|
},
|
||||||
|
WeaponType::Lazer{range} => {
|
||||||
|
let tl = robot.pose.translation;
|
||||||
|
(tl.x, tl.y, *range, LIGHTGRAY)
|
||||||
|
},
|
||||||
|
WeaponType::ForwardBall{radius} => {
|
||||||
|
let tl = robot.view_end();
|
||||||
|
(tl.x, tl.y, *radius, ORANGE)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
struct Weapon {
|
struct Weapon {
|
||||||
kills_user: bool,
|
kills_user: bool,
|
||||||
|
#[serde(flatten)]
|
||||||
model: WeaponType,
|
model: WeaponType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct SimConfig {
|
struct SimConfig {
|
||||||
food_amount: usize,
|
food_amount: usize,
|
||||||
|
view_dist: f32,
|
||||||
red_count: usize,
|
red_count: usize,
|
||||||
red_policy: Policy,
|
red_policy: Policy,
|
||||||
blu_count: usize,
|
blu_count: usize,
|
||||||
|
|
@ -261,14 +276,14 @@ impl Simulation {
|
||||||
for i in 0..config.blu_count {
|
for i in 0..config.blu_count {
|
||||||
let rand_angle = angle.sample(&mut rng);
|
let rand_angle = angle.sample(&mut rng);
|
||||||
let pose:Pose = Pose::from_parts(Vec2 { x: 100.0, y: i as f32*50.0 + 250.0}, Rot2::from_angle(rand_angle));
|
let pose:Pose = Pose::from_parts(Vec2 { x: 100.0, y: i as f32*50.0 + 250.0}, Rot2::from_angle(rand_angle));
|
||||||
robots.push(Robot::new(pose, BLUE, config.blu_policy.clone(), config.weapon.clone()));
|
robots.push(Robot::new(pose, BLUE, config.blu_policy.clone(), config.weapon.clone(), config.view_dist));
|
||||||
}
|
}
|
||||||
|
|
||||||
//red robots
|
//red robots
|
||||||
for i in 0..config.red_count {
|
for i in 0..config.red_count {
|
||||||
let rand_angle = angle.sample(&mut rng);
|
let rand_angle = angle.sample(&mut rng);
|
||||||
let pose:Pose = Pose::from_parts(Vec2 { x: 1200.0, y: i as f32*50.0 + 250.0}, Rot2::from_angle(rand_angle));
|
let pose:Pose = Pose::from_parts(Vec2 { x: 1200.0, y: i as f32*50.0 + 250.0}, Rot2::from_angle(rand_angle));
|
||||||
robots.push(Robot::new(pose, RED, config.red_policy.clone(), config.weapon.clone()));
|
robots.push(Robot::new(pose, RED, config.red_policy.clone(), config.weapon.clone(), config.view_dist));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut food = Vec::new();
|
let mut food = Vec::new();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue