model

package
v0.4.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	T_OVER       = "Over"
	T_SKIP       = "Skip"
	T_FORCE_SKIP = "ForceSkip"
)

Variables

View Source
var (
	R_NAME = Request{
		Type:            "NAME",
		RequireResponse: true,
	}
	R_TALK = Request{
		Type:            "TALK",
		RequireResponse: true}
	R_WHISPER = Request{
		Type:            "WHISPER",
		RequireResponse: true}
	R_VOTE = Request{
		Type:            "VOTE",
		RequireResponse: true}
	R_DIVINE = Request{
		Type:            "DIVINE",
		RequireResponse: true}
	R_GUARD = Request{
		Type:            "GUARD",
		RequireResponse: true}
	R_ATTACK = Request{
		Type:            "ATTACK",
		RequireResponse: true}
	R_INITIALIZE = Request{
		Type:            "INITIALIZE",
		RequireResponse: false}
	R_DAILY_INITIALIZE = Request{
		Type:            "DAILY_INITIALIZE",
		RequireResponse: false}
	R_DAILY_FINISH = Request{
		Type:            "DAILY_FINISH",
		RequireResponse: false}
	R_FINISH = Request{
		Type:            "FINISH",
		RequireResponse: false}
)
View Source
var (
	R_WEREWOLF  = Role{Name: "WEREWOLF", Team: T_WEREWOLF, Species: S_WEREWOLF}
	R_POSSESSED = Role{Name: "POSSESSED", Team: T_WEREWOLF, Species: S_HUMAN}
	R_SEER      = Role{Name: "SEER", Team: T_VILLAGER, Species: S_HUMAN}
	R_BODYGUARD = Role{Name: "BODYGUARD", Team: T_VILLAGER, Species: S_HUMAN}
	R_VILLAGER  = Role{Name: "VILLAGER", Team: T_VILLAGER, Species: S_HUMAN}
	R_MEDIUM    = Role{Name: "MEDIUM", Team: T_VILLAGER, Species: S_HUMAN}
	R_NONE      = Role{Name: "NONE", Team: T_NONE, Species: S_NONE}
)

Functions

func RolesFromConfig added in v0.4.6

func RolesFromConfig(config Config) (map[Role]int, error)

Types

type Agent

type Agent struct {
	Idx                int
	TeamName           string
	OriginalName       string
	GameName           string
	Profile            *Profile
	ProfileDescription *string
	Role               Role
	Connection         *websocket.Conn
	HasError           bool
}

func NewAgent

func NewAgent(idx int, role Role, conn Connection) *Agent

func NewAgentWithProfile added in v0.3.1

func NewAgentWithProfile(idx int, role Role, conn Connection, profile Profile, encoding map[string]string) *Agent

func (Agent) Close

func (a Agent) Close()

func (Agent) MarshalJSON

func (a Agent) MarshalJSON() ([]byte, error)

func (*Agent) SendPacket

func (a *Agent) SendPacket(packet Packet, actionTimeout, responseTimeout, acceptableTimeout time.Duration) (string, error)

func (Agent) String

func (a Agent) String() string

type BroadcastPacket

type BroadcastPacket struct {
	Id     string `json:"id"`
	Idx    int    `json:"idx"`
	Day    int    `json:"day"`
	IsDay  bool   `json:"is_day"`
	Agents []struct {
		Idx     int     `json:"idx"`
		Team    string  `json:"team"`
		Name    string  `json:"name"`
		Profile *string `json:"profile,omitempty"`
		Avatar  *string `json:"avatar,omitempty"`
		Role    string  `json:"role"`
		IsAlive bool    `json:"is_alive"`
	} `json:"agents"`
	Event     string  `json:"event"`
	Message   *string `json:"message,omitempty"`
	FromIdx   *int    `json:"from_idx,omitempty"`
	ToIdx     *int    `json:"to_idx,omitempty"`
	BubbleIdx *int    `json:"bubble_idx,omitempty"`
}

type Config

type Config struct {
	Server              ServerConfig              `yaml:"server"`
	Game                GameConfig                `yaml:"game"`
	Logic               LogicConfig               `yaml:"logic"`
	Matching            MatchingConfig            `yaml:"matching"`
	CustomProfile       CustomProfileConfig       `yaml:"custom_profile"`
	JSONLogger          JSONLoggerConfig          `yaml:"json_logger"`
	GameLogger          GameLoggerConfig          `yaml:"game_logger"`
	RealtimeBroadcaster RealtimeBroadcasterConfig `yaml:"realtime_broadcaster"`
	TTSBroadcaster      TTSBroadcasterConfig      `yaml:"tts_broadcaster"`
}

func LoadFromPath

func LoadFromPath(path string) (*Config, error)

type Connection

type Connection struct {
	TeamName     string
	OriginalName string
	Conn         *websocket.Conn
	Header       *http.Header
}

func NewConnection

func NewConnection(conn *websocket.Conn, header *http.Header) (*Connection, error)

type CustomProfileConfig added in v0.4.5

type CustomProfileConfig struct {
	Enable          bool                 `yaml:"enable"`
	ProfileEncoding map[string]string    `yaml:"profile_encoding"`
	Profiles        []Profile            `yaml:"profiles"`
	DynamicProfile  DynamicProfileConfig `yaml:"dynamic_profile"`
}

type DynamicProfileConfig added in v0.4.8

type DynamicProfileConfig struct {
	Enable    bool     `yaml:"enable"`
	Prompt    string   `yaml:"prompt"`
	Attempts  int      `yaml:"attempts"`
	Model     string   `yaml:"model"`
	MaxTokens int      `yaml:"max_tokens"`
	Avatars   []string `yaml:"avatars"`
}

type GameConfig added in v0.4.5

type GameConfig struct {
	AgentCount     int        `yaml:"agent_count"`
	MaxDay         int        `yaml:"max_day"`
	VoteVisibility bool       `yaml:"vote_visibility"`
	Talk           TalkConfig `yaml:"talk"`
	Whisper        TalkConfig `yaml:"whisper"`
	Vote           struct {
		MaxCount      int  `yaml:"max_count"`
		AllowSelfVote bool `yaml:"allow_self_vote"`
	} `yaml:"vote"`
	AttackVote struct {
		MaxCount      int  `yaml:"max_count"`
		AllowSelfVote bool `yaml:"allow_self_vote"`
		AllowNoTarget bool `yaml:"allow_no_target"`
	} `yaml:"attack_vote"`
}

type GameLoggerConfig added in v0.4.3

type GameLoggerConfig struct {
	Enable    bool   `yaml:"enable"`
	OutputDir string `yaml:"output_dir"`
	Filename  string `yaml:"filename"`
}

type GameStatus

type GameStatus struct {
	Day             int
	MediumResult    *Judge
	DivineResult    *Judge
	ExecutedAgent   *Agent
	AttackedAgent   *Agent
	Guard           *Guard
	Votes           []Vote
	AttackVotes     []Vote
	Talks           []Talk
	Whispers        []Talk
	StatusMap       map[Agent]Status
	RemainCountMap  *map[Agent]int
	RemainLengthMap *map[Agent]int
	RemainSkipMap   *map[Agent]int
}

func NewInitializeGameStatus

func NewInitializeGameStatus(agents []*Agent) GameStatus

func (GameStatus) NextDay

func (g GameStatus) NextDay() GameStatus

type Guard

type Guard struct {
	Day    int   `json:"day"`
	Agent  Agent `json:"agent"`
	Target Agent `json:"target"`
}

type Info

type Info struct {
	GameID         string           `json:"game_id"`
	Day            int              `json:"day"`
	Agent          *Agent           `json:"agent"`
	Profile        *string          `json:"profile,omitempty"`
	MediumResult   *Judge           `json:"medium_result,omitempty"`
	DivineResult   *Judge           `json:"divine_result,omitempty"`
	ExecutedAgent  *Agent           `json:"executed_agent,omitempty"`
	AttackedAgent  *Agent           `json:"attacked_agent,omitempty"`
	VoteList       []Vote           `json:"vote_list,omitempty"`
	AttackVoteList []Vote           `json:"attack_vote_list,omitempty"`
	TalkList       []Talk           `json:"-"`
	WhisperList    []Talk           `json:"-"`
	StatusMap      map[Agent]Status `json:"status_map"`
	RoleMap        map[Agent]Role   `json:"role_map"`
	RemainCount    *int             `json:"remain_count,omitempty"`
	RemainLength   *int             `json:"remain_length,omitempty"`
	RemainSkip     *int             `json:"remain_skip,omitempty"`
}

func (Info) MarshalJSON

func (i Info) MarshalJSON() ([]byte, error)

type JSONLoggerConfig added in v0.4.3

type JSONLoggerConfig struct {
	Enable    bool   `yaml:"enable"`
	OutputDir string `yaml:"output_dir"`
	Filename  string `yaml:"filename"`
}

type Judge

type Judge struct {
	Day    int     `json:"day"`
	Agent  Agent   `json:"agent"`
	Target Agent   `json:"target"`
	Result Species `json:"result"`
}

type LogicConfig added in v0.4.3

type LogicConfig struct {
	DayPhases   []Phase                `yaml:"day_phases"`
	NightPhases []Phase                `yaml:"night_phases"`
	Roles       map[int]map[string]int `yaml:"roles"`
}

type MatchWeight

type MatchWeight struct {
	RoleIdxs map[Role][]int `json:"role_idxs"`
	Weight   float64        `json:"weight"`
}

func (MatchWeight) Equal

func (mw MatchWeight) Equal(other MatchWeight) bool

func (MatchWeight) MarshalJSON

func (mw MatchWeight) MarshalJSON() ([]byte, error)

type MatchingConfig added in v0.4.5

type MatchingConfig struct {
	SelfMatch    bool   `yaml:"self_match"`
	IsOptimize   bool   `yaml:"is_optimize"`
	TeamCount    int    `yaml:"team_count"`
	GameCount    int    `yaml:"game_count"`
	OutputPath   string `yaml:"output_path"`
	InfiniteLoop bool   `yaml:"infinite_loop"`
}

type Packet

type Packet struct {
	Request        *Request `json:"request"`
	Info           *Info    `json:"info,omitempty"`
	Setting        *Setting `json:"setting,omitempty"`
	TalkHistory    *[]Talk  `json:"talk_history,omitempty"`
	WhisperHistory *[]Talk  `json:"whisper_history,omitempty"`
}

type Phase added in v0.4.3

type Phase struct {
	Name      string   `yaml:"name"`
	Actions   []string `yaml:"actions"`
	OnlyDay   *int     `yaml:"only_day,omitempty"`
	ExceptDay *int     `yaml:"except_day,omitempty"`
}

type Profile added in v0.3.9

type Profile struct {
	Name      string            `yaml:"name"`
	AvatarURL string            `yaml:"avatar_url"`
	VoiceID   int               `yaml:"voice_id"`
	Arguments map[string]string `yaml:",inline"`
}

type RealtimeBroadcasterConfig added in v0.4.3

type RealtimeBroadcasterConfig struct {
	Enable    bool          `yaml:"enable"`
	Delay     time.Duration `yaml:"delay"`
	OutputDir string        `yaml:"output_dir"`
	Filename  string        `yaml:"filename"`
}

type Request

type Request struct {
	Type            string
	RequireResponse bool
}

func RequestFromString

func RequestFromString(s string) Request

func (Request) MarshalJSON

func (r Request) MarshalJSON() ([]byte, error)

func (Request) String

func (r Request) String() string

type Role

type Role struct {
	Name    string
	Team    Team
	Species Species
}

func RoleFromString

func RoleFromString(s string) Role

func (Role) MarshalJSON

func (r Role) MarshalJSON() ([]byte, error)

func (Role) String

func (r Role) String() string

type ServerConfig added in v0.4.5

type ServerConfig struct {
	WebSocket struct {
		Host string `yaml:"host"`
		Port int    `yaml:"port"`
	} `yaml:"web_socket"`
	Authentication struct {
		Enable bool `yaml:"enable"`
	} `yaml:"authentication"`
	Timeout struct {
		Action     time.Duration `yaml:"action"`
		Response   time.Duration `yaml:"response"`
		Acceptable time.Duration `yaml:"acceptable"`
	} `yaml:"timeout"`
	MaxContinueErrorRatio float64 `yaml:"max_continue_error_ratio"`
}

type Setting

type Setting struct {
	AgentCount     int          `json:"agent_count"`
	MaxDay         *int         `json:"max_day,omitempty"`
	RoleNumMap     map[Role]int `json:"role_num_map"`
	VoteVisibility bool         `json:"vote_visibility"`
	Talk           struct {
		TalkSetting `json:",inline"`
	} `json:"talk"`
	Whisper struct {
		TalkSetting `json:",inline"`
	} `json:"whisper"`
	Vote struct {
		MaxCount      int  `json:"max_count"`
		AllowSelfVote bool `json:"allow_self_vote"`
	} `json:"vote"`
	AttackVote struct {
		MaxCount      int  `json:"max_count"`
		AllowSelfVote bool `json:"allow_self_vote"`
		AllowNoTarget bool `json:"allow_no_target"`
	} `json:"attack_vote"`
	Timeout struct {
		Action   int `json:"action"`
		Response int `json:"response"`
	} `json:"timeout"`
}

func NewSetting

func NewSetting(config Config) (*Setting, error)

func (Setting) MarshalJSON

func (s Setting) MarshalJSON() ([]byte, error)

type Species

type Species string
const (
	S_HUMAN    Species = "HUMAN"
	S_WEREWOLF Species = "WEREWOLF"
	S_NONE     Species = "NONE"
)

func SpeciesFromString

func SpeciesFromString(s string) Species

type Status

type Status string
const (
	S_ALIVE Status = "ALIVE"
	S_DEAD  Status = "DEAD"
)

func (Status) String

func (s Status) String() string

type TTSBroadcasterConfig added in v0.4.3

type TTSBroadcasterConfig struct {
	Enable         bool          `yaml:"enable"`
	Async          bool          `yaml:"async"`
	TargetDuration time.Duration `yaml:"target_duration"`
	SegmentDir     string        `yaml:"segment_dir"`
	TempDir        string        `yaml:"temp_dir"`
	Host           string        `yaml:"host"`
	Timeout        time.Duration `yaml:"timeout"`
	FfmpegPath     string        `yaml:"ffmpeg_path"`
	FfprobePath    string        `yaml:"ffprobe_path"`
	ConvertArgs    []string      `yaml:"convert_args"`
	DurationArgs   []string      `yaml:"duration_args"`
	PreConvertArgs []string      `yaml:"pre_convert_args"`
	SplitArgs      []string      `yaml:"split_args"`
}

type Talk

type Talk struct {
	Idx   int    `json:"idx"`
	Day   int    `json:"day"`
	Turn  int    `json:"turn"`
	Agent Agent  `json:"agent"`
	Text  string `json:"text"`
}

func (Talk) MarshalJSON

func (t Talk) MarshalJSON() ([]byte, error)

type TalkConfig added in v0.3.1

type TalkConfig struct {
	MaxCount struct {
		PerAgent int `yaml:"per_agent"`
		PerDay   int `yaml:"per_day"`
	} `yaml:"max_count"`
	MaxLength struct {
		CountInWord   bool `yaml:"count_in_word"`
		CountSpaces   bool `yaml:"count_spaces"`
		PerTalk       int  `yaml:"per_talk"`
		MentionLength int  `yaml:"mention_length"`
		PerAgent      int  `yaml:"per_agent"`
		BaseLength    int  `yaml:"base_length"`
	} `yaml:"max_length"`
	MaxSkip int `yaml:"max_skip"`
}

type TalkSetting added in v0.3.1

type TalkSetting struct {
	MaxCount struct {
		PerAgent int `json:"per_agent"`
		PerDay   int `json:"per_day"`
	} `json:"max_count"`
	MaxLength struct {
		CountInWord   *bool `json:"count_in_word,omitempty"`
		CountSpaces   *bool `json:"count_spaces,omitempty"`
		PerTalk       *int  `json:"per_talk,omitempty"`
		MentionLength *int  `json:"mention_length,omitempty"`
		PerAgent      *int  `json:"per_agent,omitempty"`
		BaseLength    *int  `json:"base_length,omitempty"`
	} `json:"max_length"`
	MaxSkip int `json:"max_skip"`
}

type Team

type Team string
const (
	T_VILLAGER Team = "VILLAGER"
	T_WEREWOLF Team = "WEREWOLF"
	T_NONE     Team = "NONE"
)

func TeamFromString

func TeamFromString(s string) Team

type Vote

type Vote struct {
	Day    int   `json:"day"`
	Agent  Agent `json:"agent"`
	Target Agent `json:"target"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL