Struct twt_werewolf_master_ng::judger::Judger

source ·
pub struct Judger {
    players: Vec<Box<dyn Responder>>,
    groups: Vec<Box<dyn RoleGroup>>,
    bind_addr: String,
    enabled_roles: Vec<(Identity, usize)>,
    player_num: usize,
    ai_num: usize,
    log: Log,
}
Expand description

法官类型。

  • players 存储接入的 Responder 的特型对象。
  • groups 存储 RoleGroup 特型对象,用于实现角色的行为。
  • enabled_roles 以 (身份, 数量) 的格式表示每个启用角色及其数量。

Fields§

§players: Vec<Box<dyn Responder>>§groups: Vec<Box<dyn RoleGroup>>§bind_addr: String§enabled_roles: Vec<(Identity, usize)>§player_num: usize§ai_num: usize§log: Log

Implementations§

source§

impl Judger

source

pub fn new() -> Self

source

fn get_bind_addr(&mut self)

source

fn get_enabled(&mut self)

获得启用的角色。狼人和平民是狼人杀的核心,不在选项内,直接加入。 这个函数中只获取启用的角色。角色数量和接入 AI 数量到 get_nums 中设置。

source

fn get_nums(&mut self)

获取角色和 AI 的数量。

source

fn get_config(&mut self)

设置绑定地址和接入角色。

source

fn get_option(&mut self)

获取所有设置。

source

fn build_connect(&mut self)

先接入人类用户,再接入指定数目的 AI。连接完成后获得每个玩家的用户名和编号。

source

fn assign_role(&mut self)

随机分配角色。

source

fn night( players: &mut Vec<Box<dyn Responder>>, groups: &Vec<Box<dyn RoleGroup>>, log: &mut Log )

对每个 RoleGroup 调用 night 方法。给每个玩家发送结束信号。

source

fn court(players: &mut Vec<Box<dyn Responder>>, log: &mut Log)

主持白天的审判法庭。传入所有用户。

source

fn day(players: &mut Vec<Box<dyn Responder>>, log: &mut Log)

白天。由讨论和投票两部组成。白天的开始是明确的,不需要发送开始信号。

source

fn devide( players: &mut Vec<Box<dyn Responder>> ) -> (Vec<&'_ mut Box<dyn Responder>>, Vec<&'_ mut Box<dyn Responder>>, Vec<&'_ mut Box<dyn Responder>>)

将玩家分成平民、狼人和神职三组,返回指向它们的可变引用构成的向量。

source

fn is_over(&mut self) -> bool

判断游戏是否结束。

source

fn calc_cost(players: &mut Vec<Box<dyn Responder>>, log: &mut Log)

计算使用豆包大模型产生的成本。 豆包轻量级 4k 上下文的收费是提示词 0.0003 元 / 千 tokens,输出 0.0006 元 / 千 tokens,使用其它大模型应相应修改。
不使用大模型花费均为 0。

source

fn run(&mut self)

循环处理白天黑夜,结束时计算开销。

source

pub fn init(&mut self)

服务端程序入口。

Auto Trait Implementations§

§

impl Freeze for Judger

§

impl !RefUnwindSafe for Judger

§

impl !Send for Judger

§

impl !Sync for Judger

§

impl Unpin for Judger

§

impl !UnwindSafe for Judger

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more