callbreak

package
v0.0.0-...-b534549 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NCards   = 52
	NPlayers = 4
	NRounds  = 5
	NTricks  = NCards / NPlayers

	AssistMinTimeout = 50 * time.Millisecond
	AssistMaxTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func GetValidMoves

func GetValidMoves(game *CallBreak) ([]deck.Card, error)

return a slice containing cards that can be played by the player with next turn in the ongoing trick

func RegisterStrategy

func RegisterStrategy(name string, f func() Strategy) error

func VerifyStrategy

func VerifyStrategy(name string) error

Types

type Assistant

type Assistant struct {
	// contains filtered or unexported fields
}

func (*Assistant) Assist

func (p *Assistant) Assist()

type CallBreak

type CallBreak struct {
	// TODO: think about have a token that provides access to all data in game
	Players      [NPlayers]PlayerId `json:"players"`
	Rounds       [NRounds]Round     `json:"rounds"`
	Stage        Stage              `json:"stage"`
	TotalPlayers int                `json:"totalplayers"`
	RoundNumber  int                `json:"roundnumber"`
	// contains filtered or unexported fields
}

CallBreak implements the callbreak game

func New

func New() *CallBreak

func (*CallBreak) AddPlayer

func (game *CallBreak) AddPlayer(config PlayerConfig) (PlayerId, error)

add a player to the game. returns an authentication token on success else return error on failure

func (*CallBreak) Break

func (game *CallBreak) Break(token Token, card deck.Card) error

the next player in line playes the card c

func (*CallBreak) Call

func (game *CallBreak) Call(token Token, call Score) error

func (*CallBreak) Next

func (game *CallBreak) Next() int

func (*CallBreak) Query

func (game *CallBreak) Query(token Token) (*CallBreak, error)

Get the current state of the game as visible to a token

func (*CallBreak) Turn

func (game *CallBreak) Turn(token *Token) int

returns the turn in the game of the given token. [0-3] on success, NPlayers on failure

type Config

type Config struct {
	Debug   bool `json:"debug,omitempty"`
	Players []PlayerConfig
}

type Hand

type Hand [NTricks]deck.Card

func (*Hand) HasPlayable

func (h *Hand) HasPlayable(cards ...deck.Card) bool

func (*Hand) HasSuit

func (h *Hand) HasSuit(suit deck.Suit) bool

func (*Hand) IsValid

func (h *Hand) IsValid() bool

func (*Hand) Playables

func (h *Hand) Playables() []deck.Card

func (*Hand) Sort

func (h *Hand) Sort()

sort by suit, Hukum -> itta -> chidi -> paan for the same suit, sort by rank descending

func (Hand) String

func (h Hand) String() string

type PlayerConfig

type PlayerConfig struct {
	Name     string        `json:"name"`
	Strategy string        `json:"strategy"`
	Timeout  time.Duration `json:"timeout"`
}

type PlayerId

type PlayerId struct {
	Name  string `json:"name"`
	Token `json:"token"`
}

type Round

type Round struct {
	Calls       [NPlayers]Score
	Scores      [NPlayers]Score
	Hands       [NPlayers]Hand
	Tricks      [NTricks]Trick
	TrickNumber int // current Trick number
}

type Score

type Score int

type Stage

type Stage int

track the current state of the game

const (
	NOTFULL Stage = iota
	DEALT
	CALLED
	DONE
)

type Strategy

type Strategy interface {
	Call(*CallBreak) (Score, error)
	Break(*CallBreak) (deck.Card, error)
}

func GetStrategy

func GetStrategy(name string) (Strategy, error)

type Token

type Token string

type Trick

type Trick struct {
	Cards [NPlayers]deck.Card
	Lead  int // the card position that is 1st in this trick
	Size  int // number of cards played so far in this trick
}

func (*Trick) Add

func (t *Trick) Add(card deck.Card)

func (*Trick) LeadCard

func (t *Trick) LeadCard() deck.Card

func (*Trick) LeadRank

func (t *Trick) LeadRank() deck.Rank

func (*Trick) LeadSuit

func (t *Trick) LeadSuit() deck.Suit

func (Trick) SuitWinner

func (t Trick) SuitWinner(suit deck.Suit) int

returns index of the winning card of a trick but only considers cards of a given suit -1 if no card of the suit exist

func (Trick) Winner

func (t Trick) Winner() int

returns the index of the winning card in a given trick

Jump to

Keyboard shortcuts

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