diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-10 18:06:37 +0200 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-10 18:06:37 +0200 |
| commit | 3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996 (patch) | |
| tree | c3913fce710a879e2375c60a2b78e0cad483de18 /server/bot/src/algos/customer.rs | |
| parent | f78856e4cd4928c790748b883b7916585980b3dd (diff) | |
| download | hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.bz2 hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.zst | |
Update to newest rust; replace rand with std random
Diffstat (limited to 'server/bot/src/algos/customer.rs')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 33 |
1 files changed, 17 insertions, 16 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() |