aboutsummaryrefslogtreecommitdiff
path: root/server/bot
diff options
context:
space:
mode:
Diffstat (limited to 'server/bot')
-rw-r--r--server/bot/src/algos/dishwasher.rs98
-rw-r--r--server/bot/src/algos/mod.rs3
2 files changed, 101 insertions, 0 deletions
diff --git a/server/bot/src/algos/dishwasher.rs b/server/bot/src/algos/dishwasher.rs
new file mode 100644
index 00000000..bfa903e5
--- /dev/null
+++ b/server/bot/src/algos/dishwasher.rs
@@ -0,0 +1,98 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+use super::simple::State;
+use crate::{algos::simple::Context, pathfinding::Path, BotAlgo, BotInput};
+use hurrycurry_client_lib::Game;
+use hurrycurry_protocol::{glam::IVec2, ItemIndex, PlayerID};
+
+#[derive(Default)]
+pub struct DishWasher {
+ path: Option<(Path, IVec2, f32)>,
+ cooldown: f32,
+}
+
+type LogicRes<Out = ()> = Result<Out, ()>;
+
+impl BotAlgo for DishWasher {
+ fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput {
+ let Some(player) = game.players.get(&me) else {
+ return BotInput::default();
+ };
+ let pos = player.movement.position;
+
+ if self.cooldown > 0. {
+ self.cooldown -= dt;
+ return BotInput::default();
+ }
+
+ if let Some((path, target, down)) = &mut self.path {
+ let direction = path.next_direction(pos, dt);
+ let arrived = path.is_done();
+ let target = *target;
+ if arrived {
+ *down -= dt;
+ if *down < 0. {
+ self.path = None;
+ self.cooldown = 0.2;
+ }
+ }
+ return BotInput {
+ direction,
+ boost: false,
+ interact: if arrived { Some(target) } else { None },
+ ..Default::default()
+ };
+ }
+ Context {
+ game,
+ own_position: pos.as_ivec2(),
+ me,
+ state: self,
+ recursion_abort: 0,
+ }
+ .update()
+ .ok();
+
+ BotInput::default()
+ }
+}
+
+impl State for DishWasher {
+ fn cooldown(&mut self, dur: f32) {
+ self.cooldown += dur
+ }
+ fn queue_segment(&mut self, path: Path, tile: IVec2, duration: f32) {
+ self.path = Some((path, tile, duration));
+ }
+ fn get_empty_tile_priority(&self) -> &'static [&'static str] {
+ &["counter-window", "counter"]
+ }
+}
+
+impl Context<'_, DishWasher> {
+ fn update(&mut self) -> LogicRes {
+ if let Some(pos) = self.find_item_on_map(ItemIndex(0)) {
+ self.assert_tile_is_clear(pos)?;
+ }
+ if self.is_hand_item(ItemIndex(0)) {
+ self.interact_with(self.find_empty_interactable_tile_by_name("sink").unwrap(), 2.0)?;
+ }
+ self.assert_hand_is_clear()?;
+ Ok(())
+ }
+}
diff --git a/server/bot/src/algos/mod.rs b/server/bot/src/algos/mod.rs
index dea31406..0b8e4339 100644
--- a/server/bot/src/algos/mod.rs
+++ b/server/bot/src/algos/mod.rs
@@ -20,18 +20,21 @@ mod frank;
mod simple;
mod test;
mod waiter;
+mod dishwasher;
pub use customer::Customer;
pub use frank::Frank;
pub use simple::Simple;
pub use test::Test;
pub use waiter::Waiter;
+pub use dishwasher::DishWasher;
#[allow(clippy::type_complexity)]
pub const ALGO_CONSTRUCTORS: &[(&str, fn() -> crate::DynBotAlgo)] = &[
("test", || Box::new(Test::default())),
("simple", || Box::new(Simple::default())),
("waiter", || Box::new(Waiter::default())),
+ ("dishwasher", || Box::new(DishWasher::default())),
("customer", || Box::new(Customer::default())),
("frank", || Box::new(Frank::default())),
];