diff options
Diffstat (limited to 'server/bot/src/algos')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 33 | ||||
| -rw-r--r-- | server/bot/src/algos/frank.rs | 11 |
2 files changed, 23 insertions, 21 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index 8a53ac20..17ade544 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -1,3 +1,5 @@ +use std::random::random; + /* Hurry Curry! - a game about cooking Copyright (C) 2025 Hurry Curry! Contributors @@ -16,16 +18,16 @@ */ use crate::{ - pathfinding::{find_path, Path}, BotAlgo, BotInput, + pathfinding::{Path, find_path}, + random_float, }; use hurrycurry_client_lib::Game; use hurrycurry_protocol::{ - glam::{IVec2, Vec2}, DemandIndex, Hand, Message, PacketS, PlayerClass, PlayerID, Score, + glam::{IVec2, Vec2}, }; -use log::info; -use rand::{random, rng, seq::IndexedRandom}; +use log::debug; #[derive(Debug, Clone, Default)] pub struct Customer { @@ -103,16 +105,15 @@ impl CustomerState { match self { CustomerState::New => { if !game.data.demands.is_empty() { - if let Some(&chair) = game + let chairs = game .tiles .iter() .filter(|(_, t)| game.data.tile_name(t.kind) == "chair") .map(|(p, _)| *p) - .collect::<Vec<_>>() - .choose(&mut rng()) - { + .collect::<Vec<_>>(); + if let Some(&chair) = chairs.get(random::<usize>(..) % chairs.len().max(1)) { if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), chair) { - info!("{me:?} -> entering"); + debug!("{me:?} -> entering"); *self = CustomerState::Entering { path, chair, @@ -133,10 +134,10 @@ impl CustomerState { *ticks += 1; let check = *ticks % 10 == 0; if path.is_done() { - let demand = DemandIndex(random::<u32>() as usize % game.data.demands.len()); + let demand = DemandIndex(random::<usize>(..) % game.data.demands.len()); let requested_item = game.data.demands[demand.0].input; - info!("{me:?} -> waiting"); - let timeout = 90. + random::<f32>() * 60.; + debug!("{me:?} -> waiting"); + let timeout = 90. + random_float() * 60.; let mut facing = Vec2::ZERO; for off in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { if game.tiles.get(&(off + *chair)).is_some_and(|t| { @@ -209,7 +210,7 @@ impl CustomerState { if *timeout <= 0. { let path = find_path(&game.walkable, pos.as_ivec2(), *origin) .expect("no path to exit"); - info!("{me:?} -> exiting"); + debug!("{me:?} -> exiting"); *self = CustomerState::Exiting { path }; return BotInput { extra: vec![ @@ -285,7 +286,7 @@ impl CustomerState { } }); if let Some(pos) = demand_pos { - info!("{me:?} -> eating"); + debug!("{me:?} -> eating"); let points = game.data.demands[demand.0].points; *self = CustomerState::Eating { demand: *demand, @@ -348,7 +349,7 @@ impl CustomerState { let demand = &game.data.demands[demand.0]; *progress += dt / demand.duration; if *progress >= 1. { - info!("{me:?} -> finishing"); + debug!("{me:?} -> finishing"); *self = CustomerState::Finishing { table: *table, origin: *origin, @@ -414,7 +415,7 @@ impl CustomerState { } CustomerState::Exiting { path } => { if path.is_done() || path.is_stuck() { - info!("{me:?} -> leave"); + debug!("{me:?} -> leave"); BotInput { leave: true, ..Default::default() diff --git a/server/bot/src/algos/frank.rs b/server/bot/src/algos/frank.rs index c8127198..c815c75f 100644 --- a/server/bot/src/algos/frank.rs +++ b/server/bot/src/algos/frank.rs @@ -1,3 +1,5 @@ +use std::random::random; + /* Hurry Curry! - a game about cooking Copyright (C) 2025 Hurry Curry! Contributors @@ -16,12 +18,11 @@ */ use crate::{ - pathfinding::{find_path_to_neighbour, Path}, BotAlgo, BotInput, + pathfinding::{Path, find_path_to_neighbour}, }; use hurrycurry_client_lib::Game; -use hurrycurry_protocol::{glam::Vec2, Message, PacketS, PlayerClass, PlayerID}; -use rand::{random, rng, seq::IndexedRandom}; +use hurrycurry_protocol::{Message, PacketS, PlayerClass, PlayerID, glam::Vec2}; #[derive(Default)] pub struct Frank { @@ -71,7 +72,7 @@ impl BotAlgo for Frank { extra: vec![PacketS::Communicate { player: me, message: Some(Message::Translation { - id: format!("s.bot.frank.line.{}", random::<u32>() % 8), + id: format!("s.bot.frank.line.{}", random::<u32>(..) % 8), params: vec![Message::Text(player.name.clone())], }), timeout: Some(3.), @@ -110,5 +111,5 @@ fn find_chef(game: &Game, me: PlayerID) -> Option<PlayerID> { .filter(|(i, p)| p.class == PlayerClass::Chef && **i != me) .map(|(i, _)| *i) .collect::<Vec<_>>(); - chefs.choose(&mut rng()).copied() + chefs.get(random::<usize>(..) % chefs.len().max(1)).copied() } |