aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-20 20:11:02 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-20 20:11:02 +0200
commita52785f4869a09e05417f97aff1c0d5b19587463 (patch)
tree9d288a969a6da19ddb2848ac18a22f9d3c1879b7 /server/bot/src/lib.rs
parentf8d95d074c36ec35eee8def73b8d9f2b83c922cb (diff)
downloadhurrycurry-a52785f4869a09e05417f97aff1c0d5b19587463.tar
hurrycurry-a52785f4869a09e05417f97aff1c0d5b19587463.tar.bz2
hurrycurry-a52785f4869a09e05417f97aff1c0d5b19587463.tar.zst
Refactor bot input to packet based
Diffstat (limited to 'server/bot/src/lib.rs')
-rw-r--r--server/bot/src/lib.rs38
1 files changed, 22 insertions, 16 deletions
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;
+use hurrycurry_protocol::PacketS;
+use std::{collections::VecDeque, random::random};
-#[derive(Default, Clone)]
-pub struct BotInput {
- pub direction: Vec2,
- pub boost: bool,
- pub interact: Option<IVec2>,
- pub leave: bool,
- pub extra: Vec<PacketS>,
+pub struct PacketSink<'a> {
+ buf: &'a mut VecDeque<PacketS>,
+}
+impl<'a> PacketSink<'a> {
+ pub fn new(buf: &'a mut VecDeque<PacketS>) -> Self {
+ Self { buf }
+ }
+ pub fn push(&mut self, p: PacketS) {
+ self.buf.push_back(p);
+ }
}
pub type DynBotAlgo = Box<dyn BotAlgo + Send + Sync + 'static>;
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<T: BotAlgo + ?Sized> BotAlgo for Box<T> {
- 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()
}
}