From a52785f4869a09e05417f97aff1c0d5b19587463 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 20 Oct 2025 20:11:02 +0200 Subject: Refactor bot input to packet based --- server/bot/src/lib.rs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'server/bot/src/lib.rs') diff --git a/server/bot/src/lib.rs b/server/bot/src/lib.rs index a3889021..337d18e8 100644 --- a/server/bot/src/lib.rs +++ b/server/bot/src/lib.rs @@ -18,31 +18,37 @@ #![feature(random)] pub mod algos; pub mod pathfinding; +pub mod step; use hurrycurry_game_core::Game; -use hurrycurry_protocol::{ - PacketS, PlayerID, - glam::{IVec2, Vec2}, -}; -use std::random::random; - -#[derive(Default, Clone)] -pub struct BotInput { - pub direction: Vec2, - pub boost: bool, - pub interact: Option, - pub leave: bool, - pub extra: Vec, +use hurrycurry_protocol::PacketS; +use std::{collections::VecDeque, random::random}; + +pub struct PacketSink<'a> { + buf: &'a mut VecDeque, +} +impl<'a> PacketSink<'a> { + pub fn new(buf: &'a mut VecDeque) -> Self { + Self { buf } + } + pub fn push(&mut self, p: PacketS) { + self.buf.push_back(p); + } } pub type DynBotAlgo = Box; pub trait BotAlgo { - fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput; + fn tick(&mut self, out: PacketSink, game: &Game, dt: f32); + fn is_finished(&self) -> bool { + false + } } - impl BotAlgo for Box { - fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput { - (**self).tick(me, game, dt) + fn tick(&mut self, out: PacketSink, game: &Game, dt: f32) { + (**self).tick(out, game, dt) + } + fn is_finished(&self) -> bool { + (**self).is_finished() } } -- cgit v1.3