use super::Identity::{self, *};
use super::LifeStatus::{self, *};
pub mod human;
pub mod widget;
pub mod doubao_ai;
pub mod debug_bot;
pub use widget::*;
use super::RespBoxesMut;
pub trait Responder {
fn send(&mut self, _msg: &str) { }
fn rec(&mut self) -> String { String::new() }
fn send_number(&mut self, x: usize) {
self.send(&format!("n{}", x.to_string()));
}
fn rec_number(&mut self) -> usize {
let msg = self.rec();
assert_eq!(msg.chars().nth(0).unwrap(), 'n');
msg.chars().skip(1).collect::<String>().parse().unwrap()
}
fn send_begin(&mut self) {
self.send("y");
}
fn send_end(&mut self) {
self.send("o");
}
fn send_msg(&mut self, msg: &str) {
self.send(&format!("m{}", msg));
}
fn rec_text(&mut self) -> String {
let msg = self.rec();
assert_eq!(msg.chars().nth(0).unwrap(), 't');
msg.chars().skip(1).collect::<String>()
}
fn send_json(&mut self, jstr: &str) {
self.send(&format!("j{}", jstr));
}
fn vote(&mut self, msg: &str, list: Vec<(usize, String)>) -> (String, usize) {
let (id, names): (Vec<_>, Vec<_>) = list.into_iter().unzip();
let json = serde_json::to_string(&names).unwrap();
self.send_begin();
self.send_msg(msg);
self.send_json(&json);
let x = self.rec_number();
(format!("{} -> {}", self.name(), names[x]), id[x])
}
fn role(&self) -> Identity {
Raw
}
fn set_role(&mut self, _r: Identity) {}
fn status(&self) -> LifeStatus {
Alive
}
fn set_status(&mut self, _s: LifeStatus) {}
fn set_name(&mut self) {}
fn name(&self) -> String { String::new() }
fn set_id(&mut self, _id: usize) {}
fn get_id(&self) -> usize { 0 }
fn coutinue_game(&mut self) {
self.send_end();
}
fn game_over(&mut self, msg: String) {
self.send_msg(&msg);
}
fn cost(&self) -> (u64, u64) { (0, 0) }
}