diff options
Diffstat (limited to 'server/bot')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 25 | ||||
| -rw-r--r-- | server/bot/src/algos/simple.rs | 33 |
2 files changed, 26 insertions, 32 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index ebc6e64a..0ed1ba9a 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -22,7 +22,7 @@ use crate::{ }; use hurrycurry_game_core::Game; use hurrycurry_protocol::{ - DemandIndex, Hand, ItemLocation, Message, PacketS, PlayerClass, PlayerID, Score, + DemandIndex, Hand, ItemLocation, Message, PacketS, PlayerClass, PlayerID, Score, TileIndex, glam::{IVec2, Vec2}, }; use log::debug; @@ -101,12 +101,14 @@ impl CustomerState { match self { CustomerState::New => { if !game.data.demands.is_empty() { + let chair_ti = game.data.get_tile_by_name("chair").unwrap_or(TileIndex(0)); // TODO let chairs = game - .tiles - .iter() - .filter(|(_, t)| game.data.tile_name(t.kind) == "chair") - .map(|(p, _)| *p) - .collect::<Vec<_>>(); + .tile_index + .get(&chair_ti) + .into_iter() + .flatten() + .copied() + .collect::<Vec<_>>(); //? maybe opt alloc if let Some(&chair) = chairs.get(random::<usize>(..) % chairs.len().max(1)) && let Some(path) = find_path(game, pos.as_ivec2(), chair) { @@ -135,12 +137,11 @@ impl CustomerState { 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| { - game.data - .tile_placeable_items - .get(&t.kind) - .is_none_or(|p| p.contains(&requested_item)) - }) { + if game + .tiles + .get(&(off + *chair)) + .is_some_and(|t| game.data.can_place_item(&t.parts, requested_item)) + { facing = off.as_vec2(); } } diff --git a/server/bot/src/algos/simple.rs b/server/bot/src/algos/simple.rs index ba617707..5d19ed58 100644 --- a/server/bot/src/algos/simple.rs +++ b/server/bot/src/algos/simple.rs @@ -99,13 +99,10 @@ impl<S> Context<'_, S> { [IVec2::X, IVec2::Y, -IVec2::X, -IVec2::Y] .into_iter() .find(|off| { - self.game.tiles.get(&(pos + *off)).is_some_and(|t| { - self.game - .data - .tile_placeable_items - .get(&t.kind) - .is_none_or(|placable| placable.contains(item)) - }) + self.game + .tiles + .get(&(pos + *off)) + .is_some_and(|t| self.game.data.can_place_item(&t.parts, *item)) }) .map(|off| pos + off) .map(|pos| (*item, pos, timeout.remaining)) @@ -134,7 +131,7 @@ impl<S> Context<'_, S> { self.game .tiles .iter() - .find(|(_, t)| t.kind == tile) + .find(|(_, t)| t.parts.contains(&tile)) // TODO opt use tile index .map(|(p, _)| *p) } pub fn find_occupied_table_or_floor(&self) -> Option<IVec2> { @@ -143,10 +140,9 @@ impl<S> Context<'_, S> { .iter() .find(|(_, t)| { t.item.is_some() - && matches!( - self.game.data.tile_names[t.kind.0].as_str(), - "table" | "floor" - ) + && t.parts.iter().any(|p| { + matches!(self.game.data.tile_names[p.0].as_str(), "table" | "floor") + }) }) .map(|(p, _)| *p) } @@ -155,9 +151,10 @@ impl<S> Context<'_, S> { .tiles .iter() .find(|(_, t)| { - !self.game.data.tile_placeable_items.contains_key(&t.kind) - && t.item.is_none() - && self.game.data.tile_names[t.kind.0] == name + t.item.is_none() + && t.parts + .iter() + .any(|i| self.game.data.tile_names[i.0] == name) // TODO use index }) .map(|(p, _)| *p) } @@ -178,11 +175,7 @@ impl<S: State> Context<'_, S> { } } warn!("all counters filled up"); - self.game - .tiles - .iter() - .find(|(_, t)| !self.game.data.tile_placeable_items.contains_key(&t.kind)) // TODO filter by placable item - .map(|(p, _)| *p) + None } pub fn clear_tile(&mut self, pos: IVec2) -> LogicRes { debug!("clear tile {pos}"); |