From e65e8b9f7d6f86a94213a60ec1fdea60f143c063 Mon Sep 17 00:00:00 2001 From: Patrick Tescher Date: Sat, 14 Nov 2026 18:19:58 -0800 Subject: [PATCH] Lookahead: the model has the drones' flight; measuring example and findings The model counted a drone in a tower's circle as soon as it was near; in the arena it comes down from its orbit height first. The lookahead went from -0.47 to +0.05 against a commander with no advisor. Drift, redeploy and charging are switches of the model; the example measures each. Co-Authored-By: Claude --- .../cognition/towers/examples/lookahead.rs | 503 ++++++++++++++++++ domains/recreation/towers/src/advice.rs | 54 +- domains/recreation/towers/src/lib.rs | 1 + domains/recreation/towers/src/lookahead.rs | 339 ++++++++++-- domains/recreation/towers/tests/acceptance.rs | 2 +- expectations/09-towers/rules/18-advice.expect | 10 +- plans/actors.md | 103 ++++ 7 files changed, 961 insertions(+), 51 deletions(-) create mode 100644 domains/cognition/towers/examples/lookahead.rs diff --git a/domains/cognition/towers/examples/lookahead.rs b/domains/cognition/towers/examples/lookahead.rs new file mode 100644 index 0000000..c25366c --- /dev/null +++ b/domains/cognition/towers/examples/lookahead.rs @@ -0,0 +1,503 @@ +//! What the lookahead does to a game, and whether the model or the taking is at fault +//! (plans/actors.md, step 4): +//! +//! `cargo run --release -p cognition_towers --example lookahead -- calibrate [SEEDS]` +//! every proposal the lookahead makes in a game of Blue (advised) against Red (no advisor), and +//! every one the commander takes, with what the model promised and what the real arena game +//! gave over the next 45 s: the same game replayed from the seed, once with the proposal taken +//! and once without it, and nothing else proposed in between. +//! +//! `cargo run --release -p cognition_towers --example lookahead -- variants [SEEDS]` +//! each variant of the advisor or of the taking against a commander with no advisor, on paired +//! seeds, both sides. +//! +//! Nothing here is in the commander's hot path: the probes are advisors and captains of their own. + +use cognition_towers::{Captain, Match, TowersResult}; +use glam::Vec2; +use recreation_towers::{ + Advise, Commander, EnemyDrone, Hand, Lookahead, Model, Order, Outcome, Phase, Proposal, Rules, Team, TeamView, +}; +use std::sync::{Arc, Mutex}; + +const HORIZON: f32 = 45.0; + +/// What the model said, when. +#[derive(Clone, Copy, Debug)] +struct Made { + time: f32, + drone: usize, + tower: usize, + gain: f32, +} + +/// What the commander did with it. +#[derive(Clone, Copy, Debug)] +struct Taken { + made: Made, + /// What the drone was told to do before. + before: Before, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Before { + /// Nothing. + Idle, + /// On its way to a tower, not in its circle yet. + Flying, + /// In the circle of the tower it was told to take, which the team does not hold yet. + Capturing, + /// In the circle of the tower it was told to take, which the team holds (a guard). + Guarding, +} + +/// What to do with the lookahead's proposals in a replay. +#[derive(Clone, Copy, Debug, Default)] +struct Plan { + /// No proposal made in this window (time after, time up to and including) is handed on. + silence: Option<(f32, f32)>, + /// The proposal made at this time is not handed on. + veto: Option, +} + +/// The lookahead, watched: it logs what it proposes and hands on what the plan lets through. +#[derive(Clone, Debug)] +struct Probe { + inner: Lookahead, + log: Arc>>, + plan: Plan, +} + +impl Advise for Probe { + fn advise(&mut self, view: &TeamView, hand: &Hand) -> Vec { + let proposals = self.inner.advise(view, hand); + for p in &proposals { + if let Order::Take(tower) = p.order { + self.log.lock().unwrap().push(Made { time: view.time, drone: p.drone, tower, gain: p.gain }); + } + } + let t = view.time; + let silent = self.plan.silence.is_some_and(|(from, to)| t > from && t <= to); + let vetoed = self.plan.veto.is_some_and(|v| (t - v).abs() < 1e-3); + if silent || vetoed { vec![] } else { proposals } + } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} + +/// A commander that notes which proposals it took. +struct Spy { + commander: Commander, + log: Arc>>, + taken: Arc>>, + seen: usize, + circle: f32, +} + +impl Captain for Spy { + fn decide(&mut self, view: &TeamView) -> Result, String> { + let out = self.commander.decide(view); + let log = self.log.lock().unwrap(); + for &made in &log[self.seen..] { + let order = Order::Take(made.tower); + let before = self.commander.hand().and_then(|h| h.orders[made.drone]); + if self.commander.order(made.drone) == Some(order) && before != Some(order) { + let how = match before { + Some(Order::Take(t)) => { + let near = view.drones[made.drone].at.distance(view.towers[t].at) <= self.circle; + match (near, view.towers[t].holder == Some(view.team)) { + (false, _) => Before::Flying, + (true, false) => Before::Capturing, + (true, true) => Before::Guarding, + } + } + _ => Before::Idle, + }; + self.taken.lock().unwrap().push(Taken { made, before: how }); + } + } + self.seen = log.len(); + Ok(out) + } + + fn queue(&mut self, view: &TeamView, orders: &[(usize, Order)]) -> Vec<(usize, Vec)> { + Captain::queue(&mut self.commander, view, orders) + } +} + +fn plain(rules: Rules) -> Commander { + Commander::new(rules).with_lookahead(false) +} + +/// What a team has to its name at a moment: the points it is ahead, and that with the bars of the +/// towers counted as the model counts them (10 a point of a tower's score). +#[derive(Clone, Copy, Debug, Default)] +struct Standing { + margin: f32, + value: f32, +} + +fn standing(m: &Match<'_>, team: Team, rules: &Rules) -> Standing { + let g = &m.game; + let margin = g.score[team.index()] - g.score[team.other().index()]; + let bars: f32 = g.towers.iter().map(|t| t.control * team.sign() * rules.points(t.kind)).sum(); + Standing { margin, value: margin + 10.0 * bars } +} + +/// One replay of a game of `side` (advised by the lookahead under `plan`) against a plain commander, +/// until `stop` (s) or the end of the game. +struct Replay { + made: Vec, + taken: Vec, + at_stop: Standing, + result: Option, +} + +fn replay(rules: Rules, model: Model, seed: u64, side: Team, plan: Plan, stop: f32) -> Replay { + let log = Arc::new(Mutex::new(vec![])); + let taken = Arc::new(Mutex::new(vec![])); + let probe = Probe { inner: Lookahead::new(rules).with_model(model), log: log.clone(), plan }; + let mut spy = Spy { + commander: plain(rules).with_advisor(probe, 0.0), + log: log.clone(), + taken: taken.clone(), + seen: 0, + circle: rules.circle_radius, + }; + let mut other = plain(rules); + let mut m = Match::with_rules(rules, seed); + while m.result().is_none() && m.game.time < stop { + let _ = if side == Team::Blue { m.step(&mut spy, &mut other) } else { m.step(&mut other, &mut spy) }; + } + let (made, taken) = (log.lock().unwrap().clone(), taken.lock().unwrap().clone()); + Replay { made, taken, at_stop: standing(&m, side, &rules), result: m.result() } +} + +/// One bucket of the calibration: what the model promised and what the games gave. +#[derive(Clone, Copy, Default)] +struct Bucket { + n: usize, + promised: f32, + margin: f32, + value: f32, + margin_sq: f32, +} + +impl Bucket { + fn add(&mut self, promised: f32, margin: f32, value: f32) { + self.n += 1; + self.promised += promised; + self.margin += margin; + self.value += value; + self.margin_sq += margin * margin; + } + + fn row(&self, name: &str) -> String { + let n = self.n.max(1) as f32; + let sd = (self.margin_sq / n - (self.margin / n).powi(2)).max(0.0).sqrt(); + format!( + "| {name} | {} | {:+.1} | {:+.1} ± {:.1} | {:+.1} |", + self.n, + self.promised / n, + self.margin / n, + sd / n.sqrt(), + self.value / n + ) + } +} + +fn calibrate(seeds: &[u64], model: Model) { + let rules = Rules::default(); + let header = "| | taken | promised | realised points | realised value |\n|---|---|---|---|---|"; + let (mut games, mut made, mut taken, mut won, mut ended) = (0, 0, 0, 0, 0); + let (mut by_gain, mut by_before) = (vec![Bucket::default(); 6], vec![Bucket::default(); 4]); + let mut all = Bucket::default(); + let mut by_kind: Vec<(String, Bucket)> = vec![]; + let edges = [2.0, 5.0, 10.0, 20.0, 40.0, f32::INFINITY]; + for &seed in seeds { + for side in Team::BOTH { + let real = replay(rules, model, seed, side, Plan::default(), f32::INFINITY); + games += 1; + made += real.made.len(); + taken += real.taken.len(); + ended += 1; + if let Some(r) = &real.result + && matches!(r.outcome, Outcome::Won(t) if t == side) + { + won += 1; + } + for t in &real.taken { + let when = t.made.time; + let until = when + HORIZON; + let with = replay(rules, model, seed, side, Plan { silence: Some((when, until)), veto: None }, until); + let without = + replay(rules, model, seed, side, Plan { silence: Some((when, until)), veto: Some(when) }, until); + let (dm, dv) = + (with.at_stop.margin - without.at_stop.margin, with.at_stop.value - without.at_stop.value); + let g = t.made.gain; + let bucket = edges.iter().position(|&e| g <= e).unwrap_or(5); + by_gain[bucket].add(g, dm, dv); + let b = match t.before { + Before::Idle => 0, + Before::Flying => 1, + Before::Capturing => 2, + Before::Guarding => 3, + }; + by_before[b].add(g, dm, dv); + all.add(g, dm, dv); + let kind = format!("drone {}", t.made.drone + 1); + match by_kind.iter_mut().find(|(k, _)| *k == kind) { + Some((_, b)) => b.add(g, dm, dv), + None => { + let mut b = Bucket::default(); + b.add(g, dm, dv); + by_kind.push((kind, b)); + } + } + } + } + } + println!("calibrate: {} seeds, {games} games of the advised side (both sides), {HORIZON} s horizon", seeds.len()); + println!( + "per game: {:.1} proposals made, {:.1} taken; the advised side won {won} of {ended}\n", + made as f32 / games as f32, + taken as f32 / games as f32 + ); + println!("by the gain promised\n{header}"); + let names = ["2 to 5", "5 to 10", "10 to 20", "20 to 40", "over 40"]; + println!("{}", by_gain[0].row("up to 2 (not taken in general)")); + for (b, n) in by_gain[1..].iter().zip(names) { + println!("{}", b.row(n)); + } + println!("\nby what the drone was doing\n{header}"); + for (b, n) in by_before.iter().zip(["no order", "flying to a tower", "capturing a tower", "guarding a held tower"]) + { + println!("{}", b.row(n)); + } + println!("\nby drone\n{header}"); + by_kind.sort_by(|a, b| a.0.cmp(&b.0)); + for (k, b) in &by_kind { + println!("{}", b.row(k)); + } + println!("\nall\n{header}\n{}", all.row("all taken")); +} + +// ---------------------------------------------------------------- variants + +/// Which drones the lookahead may move. +#[derive(Clone, Copy, Debug, Default)] +struct Only { + /// Only drones with no order. + idle: bool, + /// Not a drone that is capturing a tower. + not_capturing: bool, +} + +/// The lookahead, with some drones taken out of its hand. +#[derive(Clone, Debug)] +struct Restrict { + inner: Lookahead, + only: Only, + circle: f32, +} + +impl Advise for Restrict { + fn advise(&mut self, view: &TeamView, hand: &Hand) -> Vec { + let mut hand = hand.clone(); + for k in 0..hand.free.len() { + let order = hand.orders[k]; + if self.only.idle && order.is_some() { + hand.free[k] = false; + } + if self.only.not_capturing + && let Some(Order::Take(t)) = order + && view.drones[k].at.distance(view.towers[t].at) <= self.circle + && view.towers[t].holder != Some(view.team) + { + hand.free[k] = false; + } + } + self.inner.advise(view, &hand) + } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} + +/// The lookahead, shown where the enemy really is. +#[derive(Clone, Debug)] +struct Oracle { + inner: Lookahead, + truth: Arc; 2]>>, +} + +impl Advise for Oracle { + fn advise(&mut self, view: &TeamView, hand: &Hand) -> Vec { + let mut view = view.clone(); + view.enemies = self.truth.lock().unwrap()[view.team.index()].clone(); + self.inner.advise(&view, hand) + } + + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} + +type Truth = Arc; 2]>>; + +fn publish(m: &Match<'_>, truth: &Truth) { + let g = &m.game; + let n = g.rules.drones; + let mut t = truth.lock().unwrap(); + for team in Team::BOTH { + t[team.index()] = (0..n) + .map(|k| (k, &g.drones[g.drone(team.other(), k)])) + .filter(|(_, d)| d.phase != Phase::Down) + .map(|(k, d)| EnemyDrone { + k, + at: d.at, + alt: d.alt, + vel: Vec2::new(d.vel.x, d.vel.y), + seen: true, + age: 0.0, + }) + .collect(); + } +} + +fn play(rules: Rules, seed: u64, blue: &mut dyn Captain, red: &mut dyn Captain, truth: &Truth) -> TowersResult { + let mut m = Match::with_rules(rules, seed); + loop { + if let Some(r) = m.result() { + return r; + } + publish(&m, truth); + m.step(blue, red).unwrap(); + } +} + +struct Row { + margin: f32, + error: f32, + won: usize, + lost: usize, + games: usize, +} + +/// `advised` against a commander with no advisor, on each seed on both sides. +fn compare(rules: Rules, seeds: &[u64], advised: &dyn Fn(&Truth) -> Commander) -> Row { + let truth: Truth = Arc::new(Mutex::new([vec![], vec![]])); + let mut scores = vec![]; + let (mut won, mut lost) = (0, 0); + for &seed in seeds { + for side in Team::BOTH { + let (mut a, mut b) = (advised(&truth), plain(rules)); + let r = if side == Team::Blue { + play(rules, seed, &mut a, &mut b, &truth) + } else { + play(rules, seed, &mut b, &mut a, &truth) + }; + scores.push(r.score_for(side, rules.win_score)); + match r.outcome { + Outcome::Won(t) if t == side => won += 1, + Outcome::Won(_) => lost += 1, + Outcome::Draw => {} + } + } + } + let n = scores.len() as f32; + let margin = scores.iter().sum::() / n; + let var = scores.iter().map(|s| (s - margin).powi(2)).sum::() / (n - 1.0); + Row { margin, error: (var / n).sqrt(), won, lost, games: scores.len() } +} + +fn model_named(spec: &str) -> Model { + let mut tokens = spec.split('+').filter(|t| !t.is_empty()).peekable(); + let mut m = match tokens.peek() { + Some(&("first" | "flight" | "drift" | "charging" | "redeploy")) => Model::first(), + _ => Model::default(), + }; + for t in tokens { + match t { + "first" => m = Model::first(), + "all" => m = Model::default(), + "flight" => m.flight = true, + "drift" => m.drift = true, + "charging" => m.charging = true, + "redeploy" => m.redeploy = true, + "spare" => m.spare_capturing = true, + "no-flight" => m.flight = false, + "no-drift" => m.drift = false, + "no-charging" => m.charging = false, + "no-redeploy" => m.redeploy = false, + s if s.starts_with('h') => m.horizon = s[1..].parse().unwrap_or(45.0), + s if s.starts_with('f') => m.futures = s[1..].parse().unwrap_or(8), + other => eprintln!("unknown model token {other}"), + } + } + m +} + +fn variants(seeds: &[u64], set: &str, model: Model) { + let rules = Rules::default(); + println!( + "variants: the commander with an advisor against the commander with none, {} seeds, both sides\n", + seeds.len() + ); + println!("| variant | margin | won | lost |\n|---|---|---|---|"); + let show = |name: &str, advised: &dyn Fn(&Truth) -> Commander| { + let r = compare(rules, seeds, advised); + println!("| {name} | {:+.2} ± {:.2} | {} | {} |", r.margin, r.error, r.won, r.lost); + let _ = r.games; + }; + let look = || Lookahead::new(rules).with_model(model); + if set == "models" { + for name in std::env::var("MODELS").unwrap_or_default().split(',').filter(|s| !s.is_empty()) { + let m = model_named(name); + show(name, &|_| plain(rules).with_advisor(Lookahead::new(rules).with_model(m), 0.0)); + } + return; + } + show("lookahead, margin 2 (as it is)", &|_| plain(rules).with_advisor(look(), 0.0)); + for m in [5.0, 10.0, 20.0, 40.0] { + show(&format!("margin {m}"), &|_| plain(rules).with_advisor(look(), 0.0).with_advice_margin(m)); + } + let restrict = |only: Only| { + move |_: &Truth| plain(rules).with_advisor(Restrict { inner: look(), only, circle: rules.circle_radius }, 0.0) + }; + show("only drones with no order", &restrict(Only { idle: true, not_capturing: false })); + show("not a drone that is capturing", &|_| { + plain(rules).with_advisor(look().with_model(Model { spare_capturing: true, ..model }), 0.0) + }); + for c in [10.0, 20.0, 40.0] { + show(&format!("cooldown {c} s per drone"), &|_| plain(rules).with_advisor(look().with_cooldown(c), 0.0)); + } + show("not capturing, margin 10", &|_| { + plain(rules) + .with_advisor(look().with_model(Model { spare_capturing: true, ..model }), 0.0) + .with_advice_margin(10.0) + }); + show("blind (the belief never updated)", &|_| plain(rules).with_advisor(look().blind(true), 0.0)); + show("oracle (enemy drones where they are)", &|truth| { + plain(rules).with_advisor(Oracle { inner: look(), truth: truth.clone() }, 0.0) + }); + show("no advisor (should be level)", &|_| plain(rules)); +} + +fn main() { + let mut args = std::env::args().skip(1); + let what = args.next().unwrap_or_else(|| "calibrate".into()); + let n: u64 = args.next().and_then(|s| s.parse().ok()).unwrap_or(40); + let seeds: Vec = (1..=n).collect(); + match what.as_str() { + "calibrate" => calibrate(&seeds, model_named(&args.next().unwrap_or_default())), + "variants" => { + let set = args.next().unwrap_or_else(|| "taking".into()); + variants(&seeds, &set, model_named(&args.next().unwrap_or_default())) + } + other => eprintln!("calibrate or variants, not {other}"), + } +} diff --git a/domains/recreation/towers/src/advice.rs b/domains/recreation/towers/src/advice.rs index 411c019..c56a85b 100644 --- a/domains/recreation/towers/src/advice.rs +++ b/domains/recreation/towers/src/advice.rs @@ -9,7 +9,7 @@ //! (`Commander::advise`), and an advisor that is slow is only late: its proposals reach the //! commander some seconds after the map they were made from. -use crate::lookahead::{self, HORIZON}; +use crate::lookahead::{self, Model}; use crate::{Belief, Order, Queued, Rules, Team, TeamView}; use serde::{Deserialize, Serialize}; @@ -66,7 +66,7 @@ pub const LOOK_EVERY: f32 = 5.0; pub const LOOK_AFTER: f32 = 10.0; /// The first advisor: the lookahead. Every [`LOOK_EVERY`] s it plays the game forward -/// [`HORIZON`] s in a small model (`lookahead`), with the enemy drones guessed from its own +/// 45 s in a small model (`lookahead`), with the enemy drones guessed from its own /// [`Belief`], and proposes the one change of orders that gains most. Its proposal is good for /// the horizon it looked over. #[derive(Clone, Debug)] @@ -77,14 +77,39 @@ pub struct Lookahead { last: f32, /// For measuring: the belief is never updated, so the model knows nothing of the enemy. blind: bool, + /// The rules of the model it plays forward. + model: Model, + /// A drone it proposed a move for is left alone this long (s), and when it proposed it last. + cooldown: f32, + moved: Vec, } impl Lookahead { pub fn new(rules: Rules) -> Lookahead { - Lookahead { rules, belief: Belief::new(rules, Team::Blue), last: f32::NEG_INFINITY, blind: false } + Lookahead { + rules, + belief: Belief::new(rules, Team::Blue), + last: f32::NEG_INFINITY, + blind: false, + model: Model::default(), + cooldown: 0.0, + moved: vec![], + } + } + + /// A lookahead whose model has these rules (for measuring what each is worth). + pub fn with_model(mut self, model: Model) -> Lookahead { + self.model = model; + self } /// A lookahead whose belief is never updated (for measuring what the belief is worth). + /// A lookahead that does not propose a move for a drone this long (s) after it proposed one. + pub fn with_cooldown(mut self, secs: f32) -> Lookahead { + self.cooldown = secs; + self + } + pub fn blind(mut self, blind: bool) -> Lookahead { self.blind = blind; self @@ -103,22 +128,33 @@ impl Advise for Lookahead { return vec![]; } self.last = view.time; - let Some((drone, tower, gain)) = - lookahead::best_change(&self.rules, view, &hand.orders, &hand.free, &hand.away, &self.belief) - else { + self.moved.resize(hand.orders.len(), f32::NEG_INFINITY); + let hold: Vec = self.moved.iter().map(|&m| view.time - m < self.cooldown).collect(); + let Some((drone, tower, gain)) = lookahead::best_change_with( + &self.rules, + view, + &hand.orders, + &hand.free, + &hold, + &hand.away, + &self.belief, + self.model, + ) else { return vec![]; }; + self.moved[drone] = view.time; vec![Proposal { drone, order: Order::Take(tower), queue: vec![], gain, made: view.time, - until: view.time + HORIZON, + until: view.time + self.model.horizon, why: format!( - "Send drone {} to the {} tower: about {gain:.0} points over the next {HORIZON:.0} s.", + "Send drone {} to the {} tower: about {gain:.0} points over the next {:.0} s.", drone + 1, - view.towers[tower].name + view.towers[tower].name, + self.model.horizon ), }] } diff --git a/domains/recreation/towers/src/lib.rs b/domains/recreation/towers/src/lib.rs index 1a96792..45758db 100644 --- a/domains/recreation/towers/src/lib.rs +++ b/domains/recreation/towers/src/lib.rs @@ -36,6 +36,7 @@ pub use commander::{ADVICE_MARGIN, Commander, CommanderTuning}; pub use edge::{EdgeObs, EnemySeen, TowerSeen}; pub use filter::LinkFilter; pub use instruction::{Instruction, MAX_QUEUE, Queued, Standing, When, queue_of}; +pub use lookahead::Model; pub use map::Map; pub use view::{EnemyDrone, Order, OwnDrone, Sites, TeamView, TowerView, Umpire}; diff --git a/domains/recreation/towers/src/lookahead.rs b/domains/recreation/towers/src/lookahead.rs index 3e037ab..fcafb97 100644 --- a/domains/recreation/towers/src/lookahead.rs +++ b/domains/recreation/towers/src/lookahead.rs @@ -3,10 +3,12 @@ //! //! The model is not the referee. It keeps what decides a game: where the drones are, which tower //! each flies to, how fast a tower is won (5 % of the bar each second for each unit of weight -//! more in the circle) and how many points that gives. The enemy drones are guesses drawn from the -//! team's [`Belief`]: each flies to its tower and, when its team holds it, to the nearest tower it -//! does not hold. +//! more in the circle, and only by a drone that has come down below the treetops), how a bar +//! drifts back when nobody is in the circle, and how many points that gives. The enemy drones are +//! guesses drawn from the team's [`Belief`]: each flies to its tower and, when its team holds it, +//! to the nearest tower it does not hold; so does one of ours that has won its tower. +use crate::flight::{ORBIT_RADIUS, low_height, orbit_height}; use crate::{Belief, Order, Phase, Rules, TeamView}; use glam::Vec2; @@ -19,12 +21,78 @@ const STEP: f32 = 1.0; const FUTURES: usize = 8; /// The value of each point of progress on a tower's bar, in points a second held for a minute. const PROGRESS: f32 = 10.0; +/// A drone climbs or sinks this fast (m/s), and a drone that takes off climbs to this height (m), +/// the drones of a team leaving this many seconds apart: the arena's and the server's flight. +const VERTICAL: f32 = 3.0; +const TAKEOFF_HEIGHT: f32 = 15.0; +const TAKEOFF_APART: f32 = 2.0; + +/// What the model keeps of the game. Each rule that the referee has, and that a drone's flight +/// makes matter, is a switch, so that a measurement can tell what each is worth. The default is +/// what measured best: flight and charging on; drift and redeploy are right by the referee but +/// measured worse (plans/actors.md, step 4). +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Model { + /// A drone flies at its orbit height and comes down below the treetops only within reach of its + /// tower, and only a low drone counts in a circle; a drone on the ground climbs out first. + pub flight: bool, + /// A circle with nobody in it drifts back across its bar (`Rules::decay_time`). + pub drift: bool, + /// A drone on its way to charge, or down, is not at a tower. + pub charging: bool, + /// A drone that has won its tower goes on to the nearest one the team does not hold, as the + /// commander sends it, and does not stay. + pub redeploy: bool, + /// A drone in the circle of the tower it is taking, which the team does not hold yet, is not + /// moved: what it has won there is lost the moment it leaves, and a measurement of the + /// proposals that did so (plans/actors.md) found them the worst. + pub spare_capturing: bool, + /// How far ahead the model looks (s). + pub horizon: f32, + /// How many futures of the enemy it draws. + pub futures: usize, +} + +impl Default for Model { + fn default() -> Model { + Model { + flight: true, + drift: false, + charging: true, + redeploy: false, + spare_capturing: false, + horizon: HORIZON, + futures: FUTURES, + } + } +} + +impl Model { + /// The model as the first version of the lookahead played it: no flight, no drift, no + /// charging, no going on. + pub fn first() -> Model { + Model { + flight: false, + drift: false, + charging: false, + redeploy: false, + spare_capturing: false, + ..Model::default() + } + } +} #[derive(Clone, Copy, Debug)] struct Mover { at: Vec2, + alt: f32, goal: Option, weight: f32, + /// The height it flies at, and the height it takes a tower at (m). + high: f32, + low: f32, + /// Seconds before it is in the air (on the ground at the start, or climbing out). + grounded: f32, } #[derive(Clone, Copy, Debug)] @@ -41,7 +109,10 @@ struct SimTower { #[derive(Clone, Debug)] pub struct Sim { circle: f32, + ceiling: f32, capture: f32, + decay: f32, + model: Model, towers: Vec, ours: Vec, theirs: Vec, @@ -51,9 +122,22 @@ pub struct Sim { impl Sim { /// From the team's map and one guess for each enemy drone. `orders` are our drones' orders. + #[cfg(test)] pub fn new(rules: &Rules, view: &TeamView, orders: &[Option], belief: &Belief, future: usize) -> Sim { + Sim::with_model(rules, view, orders, belief, future, Model::default()) + } + + /// The same, with the rules of the model chosen. + pub fn with_model( + rules: &Rules, + view: &TeamView, + orders: &[Option], + belief: &Belief, + future: usize, + model: Model, + ) -> Sim { let sign = view.team.sign(); - let towers = view + let towers: Vec = view .towers .iter() .map(|t| SimTower { @@ -70,22 +154,56 @@ impl Sim { let ours = view .drones .iter() - .map(|d| Mover { - at: d.at, - goal: match orders.get(d.k).copied().flatten() { - Some(Order::Take(t)) => Some(t), - _ => None, - }, - weight: if d.phase == Phase::Down { 0.0 } else { rules.class(d.k).weight() }, + .map(|d| { + let grounded = match d.phase { + Phase::Ground => { + (TAKEOFF_APART * d.k as f32 - view.time).max(0.0) + (TAKEOFF_HEIGHT - d.alt).max(0.0) / VERTICAL + } + _ => 0.0, + }; + Mover { + at: d.at, + alt: if model.flight { d.alt } else { 0.0 }, + goal: match orders.get(d.k).copied().flatten() { + Some(Order::Take(t)) => Some(t), + _ => None, + }, + weight: if d.phase == Phase::Down { 0.0 } else { rules.class(d.k).weight() }, + high: orbit_height(view.team, d.k), + low: low_height(view.team, d.k), + grounded: if model.flight { grounded } else { 0.0 }, + } }) .collect(); + let enemy = view.team.other(); let theirs = (0..belief.len()) .map(|k| { let (at, goal, _) = belief.guess(k, (future * 16 + k * 5) % 128); - Mover { at, goal: Some(goal), weight: rules.class(k).weight() } + let (high, low) = (orbit_height(enemy, k), low_height(enemy, k)); + // A guess at its tower is taken to be circling it low; one on its way, high. + let alt = if at.distance(towers[goal].at) <= ORBIT_RADIUS + 20.0 { low } else { high }; + Mover { at, alt, goal: Some(goal), weight: rules.class(k).weight(), high, low, grounded: 0.0 } }) .collect(); - Sim { circle: rules.circle_radius, capture: rules.capture_time, towers, ours, theirs, score: 0.0 } + Sim { + circle: rules.circle_radius, + ceiling: rules.circle_ceiling, + capture: rules.capture_time, + decay: rules.decay_time, + model, + towers, + ours, + theirs, + score: 0.0, + } + } + + /// Drone `k` of ours is on its way to charge: it is at no tower. + pub fn charging(&mut self, k: usize) { + if self.model.charging { + self.ours[k].goal = None; + self.ours[k].weight = 0.0; + } } /// Plays `secs` seconds. @@ -98,33 +216,78 @@ impl Sim { } } + /// Does the mover count in the circle of the tower at `at`? + fn counts(&self, m: &Mover, at: Vec2) -> bool { + m.grounded <= 0.0 && m.at.distance(at) <= self.circle && (!self.model.flight || m.alt < self.ceiling) + } + + /// One mover flies for `dt` towards its goal. + fn fly(&self, m: &mut Mover, dt: f32) { + if m.grounded > 0.0 { + m.grounded -= dt; + return; + } + let Some(t) = m.goal else { return }; + m.at = toward(m.at, self.towers[t].at, CRUISE * dt); + if self.model.flight { + let near = m.at.distance(self.towers[t].at) <= ORBIT_RADIUS + 20.0; + let want = if near { m.low } else { m.high }; + m.alt += (want - m.alt).clamp(-VERTICAL * dt, VERTICAL * dt); + } + } + fn step(&mut self, dt: f32) { - for m in &mut self.ours { - if let Some(t) = m.goal { - m.at = toward(m.at, self.towers[t].at, CRUISE * dt); + for i in 0..self.ours.len() { + let mut m = self.ours[i]; + self.fly(&mut m, dt); + if self.model.redeploy + && let Some(t) = m.goal + && m.at.distance(self.towers[t].at) < 5.0 + && self.towers[t].holder == 1 + && self.towers[t].control >= 1.0 + { + // The tower is ours: on to the nearest one the team does not hold, one that no + // other drone of ours is on its way to first. + let at = m.at; + let taken = |u: usize| self.ours.iter().enumerate().any(|(j, o)| j != i && o.goal == Some(u)); + let nearest = |free_only: bool| { + (0..self.towers.len()) + .filter(|&u| self.towers[u].holder != 1 && (!free_only || !taken(u))) + .min_by(|&a, &b| at.distance(self.towers[a].at).total_cmp(&at.distance(self.towers[b].at))) + }; + m.goal = nearest(true).or_else(|| nearest(false)).or(m.goal); } + self.ours[i] = m; } for i in 0..self.theirs.len() { - let m = self.theirs[i]; + let mut m = self.theirs[i]; if let Some(t) = m.goal { let there = m.at.distance(self.towers[t].at) < 5.0; if there && self.towers[t].holder == -1 { // The tower is theirs: on to the nearest one they do not hold. - self.theirs[i].goal = (0..self.towers.len()) + m.goal = (0..self.towers.len()) .filter(|&u| self.towers[u].holder != -1) .min_by(|&a, &b| m.at.distance(self.towers[a].at).total_cmp(&m.at.distance(self.towers[b].at))) .or(Some(t)); } - let goal = self.theirs[i].goal.unwrap_or(t); - self.theirs[i].at = toward(m.at, self.towers[goal].at, CRUISE * dt); + self.fly(&mut m, dt); } + self.theirs[i] = m; } - for t in &mut self.towers { - let weight = |ms: &[Mover]| -> f32 { - ms.iter().filter(|m| m.at.distance(t.at) <= self.circle).map(|m| m.weight).sum() - }; - let diff = weight(&self.ours) - weight(&self.theirs); - t.control = (t.control + diff * dt / self.capture).clamp(-1.0, 1.0); + for ti in 0..self.towers.len() { + let at = self.towers[ti].at; + let ours: Vec<&Mover> = self.ours.iter().filter(|m| self.counts(m, at)).collect(); + let theirs: Vec<&Mover> = self.theirs.iter().filter(|m| self.counts(m, at)).collect(); + let diff = ours.iter().map(|m| m.weight).sum::() - theirs.iter().map(|m| m.weight).sum::(); + let empty = ours.is_empty() && theirs.is_empty(); + let t = &mut self.towers[ti]; + if empty && self.model.drift && self.decay > 0.0 { + // Nobody in the circle: the bar drifts back towards its holder's end, or the middle. + let end = f32::from(t.holder); + t.control += (end - t.control).clamp(-dt / self.decay, dt / self.decay); + } else { + t.control = (t.control + diff * dt / self.capture).clamp(-1.0, 1.0); + } if t.control >= 1.0 { t.holder = 1; } else if t.control <= -1.0 { @@ -151,6 +314,7 @@ fn toward(from: Vec2, to: Vec2, step: f32) -> Vec2 { /// the points it expects to gain by it: `(k, t, gain)`. `None` if there is no change to try. Whether /// the gain is worth making is for the commander to say. `free` says which drones may be given a new /// order, and `away` which towers a drone must stay away from. +#[cfg(test)] pub fn best_change( rules: &Rules, view: &TeamView, @@ -158,6 +322,21 @@ pub fn best_change( free: &[bool], away: &[Vec], belief: &Belief, +) -> Option<(usize, usize, f32)> { + best_change_with(rules, view, orders, free, &vec![false; orders.len()], away, belief, Model::default()) +} + +/// The same with the model's rules chosen, and the drones `hold`ing back from a move. +#[allow(clippy::too_many_arguments)] +pub fn best_change_with( + rules: &Rules, + view: &TeamView, + orders: &[Option], + free: &[bool], + hold: &[bool], + away: &[Vec], + belief: &Belief, + model: Model, ) -> Option<(usize, usize, f32)> { let towers = view.towers.len(); let base = rules.base(view.team); @@ -170,31 +349,44 @@ pub fn best_change( rules.battery(rules.class(k)) <= 0.0 || d.battery >= rules.bingo + (d.at.distance(tower.at) + tower.at.distance(base)) / CRUISE + capture + 15.0 }; + let capturing = |k: usize| { + matches!(orders[k], Some(Order::Take(t)) + if view.drones[k].at.distance(view.towers[t].at) <= rules.circle_radius + && view.towers[t].holder != Some(view.team)) + }; let mut candidates: Vec<(usize, usize)> = vec![]; - for k in (0..orders.len()).filter(|&k| free[k]) { + for k in (0..orders.len()).filter(|&k| free[k] && !hold[k] && !(model.spare_capturing && capturing(k))) { for (t, &avoid) in away[k].iter().enumerate().take(towers) { if orders[k] != Some(Order::Take(t)) && !avoid && lasts(k, t) { candidates.push((k, t)); } } } + // A drone that is not free and in contact is on its way to charge (or down): it is at no tower. + let charging: Vec = (0..orders.len()) + .filter(|&k| !free[k] && view.drones[k].linked && view.drones[k].phase != Phase::Down) + .collect(); + let play = |orders: &[Option], future: usize| { + let mut sim = Sim::with_model(rules, view, orders, belief, future, model); + for &k in &charging { + sim.charging(k); + } + sim.run(model.horizon); + sim.value() + }; let mut gain = vec![0.0f32; candidates.len()]; - for future in 0..FUTURES { - let mut base = Sim::new(rules, view, orders, belief, future); - base.run(HORIZON); - let base = base.value(); + for future in 0..model.futures { + let base = play(orders, future); for (c, &(k, t)) in candidates.iter().enumerate() { let mut changed = orders.to_vec(); changed[k] = Some(Order::Take(t)); - let mut sim = Sim::new(rules, view, &changed, belief, future); - sim.run(HORIZON); - gain[c] += sim.value() - base; + gain[c] += play(&changed, future) - base; } } let (best, total) = gain.iter().copied().enumerate().max_by(|a, b| a.1.total_cmp(&b.1)).filter(|&(_, g)| g.is_finite())?; let (k, t) = candidates[best]; - Some((k, t, total / FUTURES as f32)) + Some((k, t, total / model.futures as f32)) } #[cfg(test)] @@ -214,6 +406,12 @@ mod tests { g.drones[i] = crate::Drone { at, alt: 50.0, phase: Phase::Flying, ..g.drones[i] }; } + /// A drone in the tower's circle, low. + fn low_at(g: &mut Game, team: Team, k: usize, at: Vec2) { + let i = g.drone(team, k); + g.drones[i] = crate::Drone { at, alt: 15.0, phase: Phase::Flying, ..g.drones[i] }; + } + fn no_away(view: &TeamView) -> Vec> { vec![vec![false; view.towers.len()]; view.drones.len()] } @@ -223,7 +421,7 @@ mod tests { let (rules, mut g) = setup(); let west = g.tower("west"); let at = g.towers[west].at; - fly_to(&mut g, Team::Blue, 0, at); + low_at(&mut g, Team::Blue, 0, at); let view = g.view(Team::Blue); let belief = Belief::new(rules, Team::Blue); let mut orders = vec![None; 3]; @@ -235,6 +433,50 @@ mod tests { assert_eq!(sim.towers[west].holder, 1); } + #[test] + fn a_drone_that_comes_to_a_tower_high_wins_it_only_after_it_has_come_down() { + let (rules, mut g) = setup(); + let west = g.tower("west"); + let at = g.towers[west].at; + // At the tower, at its orbit height: it comes down at 3 m/s to the treetops before it counts. + fly_to(&mut g, Team::Blue, 0, at); + let view = g.view(Team::Blue); + let belief = Belief::new(rules, Team::Blue); + let orders = [Some(Order::Take(west)), None, None]; + let mut sim = Sim::new(&rules, &view, &orders, &belief, 0); + sim.run(10.0); + assert!(sim.towers[west].control < 0.05, "still high: {}", sim.towers[west].control); + sim.run(40.0); + assert_eq!(sim.towers[west].holder, 1); + // The model before the measurement had no such wait. + let mut first = Sim::with_model(&rules, &view, &orders, &belief, 0, Model::first()); + first.run(10.0); + assert!(first.towers[west].control > 0.45, "{}", first.towers[west].control); + } + + #[test] + fn a_bar_that_nobody_is_at_drifts_back_to_its_holders_end_or_the_middle() { + let (rules, g) = setup(); + let west = g.tower("west"); + let view = g.view(Team::Blue); + let belief = Belief::new(rules, Team::Blue); + let mut sim = + Sim::with_model(&rules, &view, &[None, None, None], &belief, 0, Model { drift: true, ..Model::default() }); + sim.theirs.clear(); + sim.towers[west].control = 0.5; + sim.run(30.0); + assert!( + (sim.towers[west].control - 0.2).abs() < 1e-3, + "a bar nobody holds drifts to the middle: {}", + sim.towers[west].control + ); + // A held bar drifts back to its end. + sim.towers[west].holder = 1; + sim.towers[west].control = 0.5; + sim.run(30.0); + assert!((sim.towers[west].control - 0.8).abs() < 1e-3, "{}", sim.towers[west].control); + } + #[test] fn holding_a_tower_scores_its_points_each_second() { let (rules, g) = setup(); @@ -258,15 +500,36 @@ mod tests { let (rules, mut g) = setup(); let west = g.tower("west"); let at = g.towers[west].at; - fly_to(&mut g, Team::Blue, 0, at); + low_at(&mut g, Team::Blue, 0, at); let view = g.view(Team::Blue); let belief = Belief::new(rules, Team::Blue); let mut sim = Sim::new(&rules, &view, &[Some(Order::Take(west)), None, None], &belief, 0); - sim.theirs[0] = Mover { at, goal: Some(west), weight: 1.0 }; + sim.theirs[0] = Mover { at, alt: 15.0, goal: Some(west), weight: 1.0, high: 60.0, low: 15.0, grounded: 0.0 }; sim.run(30.0); assert!(sim.towers[west].control.abs() < 1e-3, "{}", sim.towers[west].control); } + #[test] + fn a_drone_that_has_won_its_tower_goes_on_to_the_nearest_one_the_team_does_not_hold() { + let (rules, mut g) = setup(); + let west = g.tower("west"); + let at = g.towers[west].at; + low_at(&mut g, Team::Blue, 0, at); + let view = g.view(Team::Blue); + let belief = Belief::new(rules, Team::Blue); + let all = Model { redeploy: true, ..Model::default() }; + let mut sim = Sim::with_model(&rules, &view, &[Some(Order::Take(west)), None, None], &belief, 0, all); + sim.theirs.clear(); + sim.run(22.0); + assert_eq!(sim.towers[west].holder, 1); + assert_ne!(sim.ours[0].goal, Some(west), "it has gone on"); + let mut stays = + Sim::with_model(&rules, &view, &[Some(Order::Take(west)), None, None], &belief, 0, Model::first()); + stays.theirs.clear(); + stays.run(22.0); + assert_eq!(stays.ours[0].goal, Some(west)); + } + #[test] fn it_prefers_the_free_tower_over_the_one_three_enemies_sit_on() { let (rules, mut g) = setup(); diff --git a/domains/recreation/towers/tests/acceptance.rs b/domains/recreation/towers/tests/acceptance.rs index d5d0ff6..5630503 100644 --- a/domains/recreation/towers/tests/acceptance.rs +++ b/domains/recreation/towers/tests/acceptance.rs @@ -1018,7 +1018,7 @@ mod advice { w.run(10.0); w.blue_decides(); assert_ne!(w.blue.order(0), red_home(&w)); - assert_eq!(w.say(w.blue.order(0)), "take the centre tower"); + assert_eq!(w.say(w.blue.order(0)), "take the west tower"); } #[test] diff --git a/expectations/09-towers/rules/18-advice.expect b/expectations/09-towers/rules/18-advice.expect index 90dd3f0..b526657 100644 --- a/expectations/09-towers/rules/18-advice.expect +++ b/expectations/09-towers/rules/18-advice.expect @@ -10,7 +10,9 @@ Feature: Advice for the commander A proposal that does not fit is dropped. The first advisor is the lookahead. Every 5 s it plays the game forward 45 s in a small model. - The enemy drones in the model are guesses from its [[belief]]. It tries to send each free + The enemy drones in the model are guesses from its [[belief]]. A drone in the model flies at its own height and comes + down below the treetops only near its tower, as a real drone does, so a drone that is sent to a + tower counts there only when it is low; a drone on its way to charge is at no tower. It tries to send each free drone to each other tower, and proposes the change that gives most points. Its proposal is good for 45 s. A commander with no advisor does not think ahead. A commander thinks ahead with the lookahead by default. @@ -36,11 +38,13 @@ Feature: Advice for the commander Expectation: A stale proposal is not taken The proposal is good for 5 s. The commander decides 10 s later, and does what it does with no - proposal: at that time it sends the first drone to the centre tower. + proposal: at that time it sends the first drone to the west tower. + (The lookahead used to send it to the centre tower here; its model has the flight now, and + leaves the west tower to it.) Given the proposal in the hand of the Blue commander is the Red home tower for 5 points, good for 5 seconds When the computer commander of Blue weighs the proposal 10 seconds later - Then the order of the first Blue drone is take the centre tower + Then the order of the first Blue drone is take the west tower Expectation: A proposal for a tower that the team holds now is not taken The advisor looked at the map when the Red home tower was Red's. When the commander decides, diff --git a/plans/actors.md b/plans/actors.md index ee9f297..7d07139 100644 --- a/plans/actors.md +++ b/plans/actors.md @@ -190,6 +190,109 @@ server. proposals taken, and how many are stale or no longer fit, are not counted). So the lookahead is a plumbing test for advisors, not a gain: it is the model and its enemy guesses that need work, before advice from a slower and better advisor can be told from lateness. + + **Why the lookahead lost (branch `actors-lookahead`; `cargo run --release -p cognition_towers + --example lookahead -- calibrate|variants SEEDS ...`).** The cause is a defect in the model: it had + no flight. A drone in the model counted in a tower's circle as soon as it was within 60 m; in the + arena it flies at its orbit height (55 to 87 m) and comes down at 3 m/s to 16 m only within 60 m of + the tower, and only a drone below the treetops (20 m) counts (`cognition_towers` `Flyer::step`, + `Game::in_circle`): 12 to 22 s of nothing at every arrival. A move that leaves a drone that is + already low and capturing, to a tower where it must come down again, was therefore always a + gain in the model and a loss in the game. Measured on the old model (40 seeds, both sides, the + real game replayed from the seed with and without each taken proposal, nothing else proposed for + 45 s): 45 proposals made and 25.5 taken per game (a move every 8 s); promised +17.6 points on + average, realised -1.9 (points of margin after 45 s). + + | Gain promised | Taken | Promised | Realised points | + | --- | --- | --- | --- | + | 2 to 5 | 359 | +3.3 | -3.0 ± 0.6 | + | 5 to 10 | 473 | +7.2 | -2.1 ± 0.5 | + | 10 to 20 | 533 | +14.5 | -2.4 ± 0.5 | + | 20 to 40 | 487 | +27.7 | -1.2 ± 0.4 | + | over 40 | 185 | +53.9 | +0.9 ± 0.3 | + + By what the drone was doing: flying to a tower (1574 taken) promised +18.4, realised +0.1; capturing a + tower (204) promised +10.9, realised **-16.5 ± 1.3**; guarding a held tower (259) +17.9, -2.0. The + harm is the moves of drones that sit low in a circle. With the flight in the model (the + default now) the same table: 44.5 made and 21.5 taken per game, promised +9.9, realised -0.3 ± 0.2; + capturing -6.4 ± 1.5 (86 taken), flying +0.3 (1401), guarding -1.6 (229). Still too many moves, + and still a loss for the drones that are capturing: not understood to the end (see below). + + Where the old model differs from the arena, rule by rule (old `lookahead.rs` lines): + - Flight, climb, descent (:104, :110-119; arena `lib.rs:229-257`, `Game::in_circle` `lib.rs:678`): + no height. 12 to 22 s per arrival. The biggest by far. **Fixed.** + - Take-off (arena `lib.rs:40-42, 230-239`): a drone on the ground at the start counted in a circle + as soon as it was near. 5 s plus 2 s a drone. **Fixed** (`grounded`). + - Charging (`commander.rs:370-371`: the hand's orders are those before the charge orders): a drone on + its way home counted at its tower. **Fixed**; worth +0.03 ± 0.04 (not measurable alone). + - Drift of an empty circle (`lib.rs:697-700`, 100 s a bar): the model kept every bar where it was, so + leaving a half-won tower cost nothing. Modelled (`Model::drift`), **but measured worse** (see below), + so it is off. + - What a drone does after it has won its tower (`commander.rs:288-361`, it goes on to the next): + the model left it there. Modelled (`Model::redeploy`), **measured worse**, so it is off. + - Not modelled, size unknown: the speed (16 m/s in the model; 0.95-1.05 of it plus a wind of up to + 5 m/s in the arena, `lib.rs:45, 335, 349`) and the orbit of 40 m round the tower; the order delay + of 0.3 to 2 s (`lib.rs:51, 389`); radio shadows (`lib.rs:564`: a drone sent into the shadow of a + tower is out of contact, and its orders do not reach it, `lib.rs:395-403`); batteries and the + contest drain (`lib.rs:614`, only the `lasts` check); the give-up rule (`commander.rs:226-238`: the + commander takes a drone off a tower it is behind at after 10 s, and the model keeps it there); the + score cap at 600 (`lib.rs:725`); a tower the team has not seen for a while (its control is the + old one); an enemy that goes down, charges or fights. + - The enemy in the model flies straight to the tower of a guess and stays; its altitude is a guess + (low at the tower, high elsewhere). With the enemy where it really is (an oracle, below) the model + gains little: the belief is not what holds the lookahead back. + + Each variant against a commander with no advisor, 400 seeds, both sides (800 games), delay 0, the + flight model (`variants 400 taking flight`; the rows with `first` are the model as it was): + + | Variant | Margin | Won | Lost | + | --- | --- | --- | --- | + | the model as it was (`first`) | -0.47 ± 0.04 | 268 | 532 | + | flight | +0.02 ± 0.04 | 420 | 379 | + | flight + drift | -0.08 ± 0.04 | 389 | 411 | + | flight + charging (**the default now**) | +0.05 ± 0.04 | 430 | 370 | + | flight + redeploy | -0.10 ± 0.04 | 380 | 419 | + | flight + drift + charging | -0.04 ± 0.04 | 404 | 396 | + | flight + drift + charging + redeploy | -0.18 ± 0.04 | 355 | 444 | + | on the flight model: margin 5 | +0.18 ± 0.04 | 466 | 333 | + | margin 10 | +0.12 ± 0.05 | 445 | 355 | + | margin 20 | +0.12 ± 0.05 | 439 | 361 | + | margin 40 | +0.02 ± 0.05 | 404 | 396 | + | not a drone that is capturing | -0.03 ± 0.04 | 411 | 388 | + | not capturing, margin 10 | +0.13 ± 0.05 | 446 | 354 | + | a drone moved is left alone 10 s | +0.00 ± 0.04 | 416 | 383 | + | 20 s | -0.17 ± 0.04 | 357 | 442 | + | 40 s | -0.51 ± 0.04 | 265 | 534 | + | blind (belief never updated) | -0.03 ± 0.04 | 410 | 389 | + | oracle (enemy drones where they are) | +0.05 ± 0.04 | 433 | 366 | + | only drones with no order | +0.00 ± 0.05 | 400 | 400 | + + ("Only drones with no order" is no advisor: every drone has an order.) On the old model the same rows + (100 seeds, ±0.09): margin 5 -0.48, 10 -0.54, 20 -0.13, 40 +0.07; not capturing -0.12; blind + -0.41; oracle -0.57. Horizon and futures on the model with all four rules on (100 seeds): 15 s + +0.04, 30 s +0.04, 60 s -0.27, 90 s -0.29; 2 futures -0.25, 32 futures -0.18 (8: -0.18). + + What it comes to. The model's missing flight was the defect: with it the lookahead goes from -0.47 + to +0.05 ± 0.04 (430 won, 370 lost), which is level with no advisor, not a gain. A larger margin + (5 points) wins by +0.18 ± 0.04; that is a number found by looking at the result, and is not in the + code (`ADVICE_MARGIN` is 2 as before). Not fixed, and for the owner: whether the default commander + keeps the lookahead. With the fix `judge --game captain --champion timid --challenger default + --seeds 24` gives the default commander +0.384 (lower bound +0.048, promoted) with the lookahead, + +0.268 (+0.031) with `SIM001_LOOKAHEAD=0`, and +0.175 (-0.132, kept out) with the lookahead as it was. + Late advice now costs, as it should for a plan that is exact in time (`advice 400`): + + | Delay | Margin | Won | Lost | + | --- | --- | --- | --- | + | 0 s | +0.05 ± 0.04 | 430 | 370 | + | 2 s | -0.16 ± 0.04 | 362 | 438 | + | 5 s | -0.27 ± 0.04 | 331 | 469 | + | 10 s | -0.55 ± 0.04 | 248 | 552 | + | 30 s | -0.94 ± 0.04 | 143 | 657 | + + The old table was flat because the proposals were noise. Unexplained: why the moves of capturing + drones still lose (-6.4 ± 1.5 a move with the flight model); why drift and redeploy, which are the + referee's and the commander's own rules, measure worse than leaving them out (about 2 sigma each, not + checked at more seeds); why 20 s and 40 s of cooldown per drone are so much worse than 10 s. **Results (the seat side: advisors beside the commander, a process advisor, a Claude advisor, and the app's accept).** Done in `recreation_towers_ground::{advisors, claude}`, the commander app and the server. An advisor at a seat runs on a thread of its own (`advisors::Runner`) behind