This commit is contained in:
2024-11-23 16:22:28 +01:00
parent 04b62ca4dd
commit a1e23c29f3
3 changed files with 95 additions and 17 deletions

View File

@@ -8,10 +8,18 @@ use rand::{thread_rng, Rng};
use serde::Deserialize;
use std::net::SocketAddr;
use tokio::sync::Mutex;
use log::debug;
use log::error;
use log::info;
use log::warn;
#[macro_use]
extern crate log;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
env_logger::init();
// tracing_subscriber::fmt::init();
// build our application with some routes
let app = Router::new()
@@ -66,17 +74,24 @@ async fn input(Json(input): Json<Input>) -> String {
if state.rem_a.is_empty() {
return "ERROR (everybody drew already)".into();
}
info!("joueur qui doivent piocher : {:?}", state.rem_a.join(", "));
match state.rem_a.iter().position(|p| input.person == *p) {
Some(pos) => {
info!("joueur qui pioche : {:?}", state.rem_a[pos]);
state.rem_a.remove(pos);
}
None => return "ERROR (you drew already)".into(),
None => {
return "ERROR (you drew already)".into()
}
}
loop {
let num = thread_rng().gen_range(0..state.rem_b.len());
if state.rem_b[num] != input.person {
info!("joueurs qui peuvent etre pick : {:?}", state.rem_b.join(", "));
info!("{:?} picked {:?}", input.person, state.rem_b[num]);
return state.rem_b.remove(num);
}
}