aboutsummaryrefslogtreecommitdiff
path: root/server/bot
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-10 18:06:37 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-10 18:06:37 +0200
commit3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996 (patch)
treec3913fce710a879e2375c60a2b78e0cad483de18 /server/bot
parentf78856e4cd4928c790748b883b7916585980b3dd (diff)
downloadhurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar
hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.bz2
hurrycurry-3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996.tar.zst
Update to newest rust; replace rand with std random
Diffstat (limited to 'server/bot')
-rw-r--r--server/bot/Cargo.toml3
-rw-r--r--server/bot/src/algos/customer.rs33
-rw-r--r--server/bot/src/algos/frank.rs11
-rw-r--r--server/bot/src/lib.rs8
4 files changed, 31 insertions, 24 deletions
diff --git a/server/bot/Cargo.toml b/server/bot/Cargo.toml
index 17534947..94170510 100644
--- a/server/bot/Cargo.toml
+++ b/server/bot/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "hurrycurry-bot"
version = "2.3.5"
-edition = "2021"
+edition = "2024"
[dependencies]
hurrycurry-client-lib = { path = "../client-lib", features = ["tokio-network"] }
@@ -11,4 +11,3 @@ anyhow = "1.0.99"
env_logger = "0.11.8"
rustls = { version = "0.23.31", features = ["ring"] }
clap = { version = "4.5.47", features = ["derive"] }
-rand = "0.9.2"
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()
}
diff --git a/server/bot/src/lib.rs b/server/bot/src/lib.rs
index cc1cb2a8..927ac7b0 100644
--- a/server/bot/src/lib.rs
+++ b/server/bot/src/lib.rs
@@ -15,14 +15,16 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#![feature(random)]
pub mod algos;
pub mod pathfinding;
use hurrycurry_client_lib::Game;
use hurrycurry_protocol::{
- glam::{IVec2, Vec2},
PacketS, PlayerID,
+ glam::{IVec2, Vec2},
};
+use std::random::random;
#[derive(Default, Clone)]
pub struct BotInput {
@@ -43,3 +45,7 @@ impl<T: BotAlgo + ?Sized> BotAlgo for Box<T> {
(**self).tick(me, game, dt)
}
}
+
+fn random_float() -> f32 {
+ random::<u32>(..) as f32 / u32::MAX as f32
+}