/*
    Hurry Curry! - a game about cooking
    Copyright (C) 2026 Hurry Curry! Contributors

    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/>.

*/

pub mod algos;
pub mod pathfinding;
pub mod step;

use hurrycurry_game_core::Game;
use hurrycurry_protocol::PacketS;
#[cfg(feature = "debug_events")]
use hurrycurry_protocol::{PlayerID, glam::Vec3};
use rand::{Rng, RngExt};
use std::collections::VecDeque;

pub struct PacketSink<'a> {
    buf: &'a mut VecDeque<PacketS>,
}
impl<'a> PacketSink<'a> {
    pub fn new(buf: &'a mut VecDeque<PacketS>) -> Self {
        Self { buf }
    }
    pub fn push(&mut self, p: PacketS) {
        self.buf.push_back(p);
    }
}

pub type DynBotAlgo = Box<dyn BotAlgo + Send + Sync + 'static>;
pub trait BotAlgo {
    fn tick(&mut self, out: PacketSink, game: &Game, dt: f32);
    fn is_finished(&self) -> bool {
        false
    }
}
impl<T: BotAlgo + ?Sized> BotAlgo for Box<T> {
    fn tick(&mut self, out: PacketSink, game: &Game, dt: f32) {
        (**self).tick(out, game, dt)
    }
    fn is_finished(&self) -> bool {
        (**self).is_finished()
    }
}

fn random_usize<T: Rng>(rng: &mut T) -> usize {
    usize::from_ne_bytes(rng.random())
}

#[cfg(feature = "debug_events")]
fn debug_player_color(d: PlayerID) -> Vec3 {
    Vec3::new(0.5, 0.3, d.0 as f32 * 57.29577)
}
