Documentation
¶
Index ¶
- Constants
- Variables
- func CalcScore(c Category, dice [5]int) int
- func IsValidCategory(c Category) bool
- func Reroll(dice [5]int, hold []int, src rand.Source) [5]int
- func RollAll(src rand.Source) [5]int
- type AIPlayer
- type AITurnResult
- type BattleConfig
- type BattlePlayer
- type BattlePlayerResult
- type BattleResult
- type Category
- type Game
- type GameClient
- type GamePhase
- type GameState
- type GreedyStrategy
- type HoldStep
- type LocalClient
- type Player
- type PlayerState
- type Scorecard
- func (sc *Scorecard) AvailableCategories() []Category
- func (sc *Scorecard) Fill(c Category, score int)
- func (sc *Scorecard) GetScore(c Category) int
- func (sc *Scorecard) HasUpperBonus() bool
- func (sc *Scorecard) IsFilled(c Category) bool
- func (sc Scorecard) MarshalJSON() ([]byte, error)
- func (sc *Scorecard) Total() int
- func (sc *Scorecard) UnmarshalJSON(data []byte) error
- func (sc *Scorecard) UpperTotal() int
- type StatisticalStrategy
- type Strategy
- type TurnAction
Constants ¶
const MaxRolls = 3
const MaxRounds = 13
const UpperBonusThreshold = 63
const UpperBonusValue = 35
Variables ¶
var AllCategories = []Category{ Ones, Twos, Threes, Fours, Fives, Sixes, ThreeOfAKind, FourOfAKind, FullHouse, SmallStraight, LargeStraight, Yahtzee, Chance, }
Functions ¶
func IsValidCategory ¶
Types ¶
type AIPlayer ¶
type AIPlayer struct {
// contains filtered or unexported fields
}
func NewAIPlayer ¶
func NewAIPlayerWithStrategy ¶
func (*AIPlayer) PlayTurn ¶
func (ai *AIPlayer) PlayTurn() (AITurnResult, error)
type AITurnResult ¶
type BattleConfig ¶
type BattleConfig struct {
Players []BattlePlayer
Seed int64
OnTurnDone func(result AITurnResult)
}
BattleConfig holds the configuration for a battle.
type BattlePlayer ¶
BattlePlayer represents a player in a battle.
type BattlePlayerResult ¶
BattlePlayerResult holds the final result for a single player.
type BattleResult ¶
type BattleResult struct {
Players []BattlePlayerResult
}
BattleResult holds the final results of a battle.
type Category ¶
type Category string
const ( Ones Category = "ones" Twos Category = "twos" Threes Category = "threes" Fours Category = "fours" Fives Category = "fives" Sixes Category = "sixes" ThreeOfAKind Category = "three_of_a_kind" FourOfAKind Category = "four_of_a_kind" FullHouse Category = "full_house" SmallStraight Category = "small_straight" LargeStraight Category = "large_straight" Yahtzee Category = "yahtzee" Chance Category = "chance" )
type Game ¶
type Game struct {
Players []Player
Current int
Round int
Dice [5]int
RollCount int
Phase GamePhase
// contains filtered or unexported fields
}
func (*Game) GetAvailableCategories ¶
func (*Game) GetScorecard ¶
type GameClient ¶
type GameState ¶
type GameState struct {
Players []PlayerState
CurrentPlayer string
CurrentPlayerIndex int
Round int
Dice [5]int
RollCount int
Phase GamePhase
AvailableCategories []Category
}
func RunBattle ¶
func RunBattle(cfg BattleConfig) (*GameState, error)
RunBattle executes a full AI-vs-AI game and returns the final state.
type GreedyStrategy ¶
type GreedyStrategy struct{}
GreedyStrategy always scores immediately with the highest-scoring available category. It never uses Hold to reroll.
func (*GreedyStrategy) DecideAction ¶
func (s *GreedyStrategy) DecideAction(dice [5]int, rollCount int, scorecard Scorecard, available []Category) TurnAction
func (*GreedyStrategy) Name ¶
func (s *GreedyStrategy) Name() string
type LocalClient ¶
type LocalClient struct {
LastAIResults []AITurnResult
// contains filtered or unexported fields
}
func NewLocalClient ¶
func NewLocalClient(game *Game, playerID string, ais []*AIPlayer) *LocalClient
func (*LocalClient) GetState ¶
func (c *LocalClient) GetState() (*GameState, error)
func (*LocalClient) Roll ¶
func (c *LocalClient) Roll() (*GameState, error)
type PlayerState ¶
type Scorecard ¶
type Scorecard struct {
// contains filtered or unexported fields
}
func NewScorecard ¶
func NewScorecard() Scorecard
func (*Scorecard) AvailableCategories ¶
func (*Scorecard) HasUpperBonus ¶
func (Scorecard) MarshalJSON ¶
func (*Scorecard) UnmarshalJSON ¶
func (*Scorecard) UpperTotal ¶
type StatisticalStrategy ¶
type StatisticalStrategy struct{}
StatisticalStrategy uses expected value calculation to decide whether to hold or score. On the 3rd roll it always scores the best category. Otherwise it compares immediate scoring vs expected value of each hold combination.
func (*StatisticalStrategy) DecideAction ¶
func (s *StatisticalStrategy) DecideAction(dice [5]int, rollCount int, scorecard Scorecard, available []Category) TurnAction
func (*StatisticalStrategy) Name ¶
func (s *StatisticalStrategy) Name() string
type Strategy ¶
type Strategy interface {
Name() string
DecideAction(dice [5]int, rollCount int, scorecard Scorecard, available []Category) TurnAction
}
Strategy defines the interface for AI decision-making.
type TurnAction ¶
type TurnAction struct {
Type string // "hold" or "score"
Indices []int // hold: dice indices to keep
Category Category // score: category to score in
}
TurnAction represents a decision made by a Strategy during a turn.