model

package
v0.0.0-...-83cae81 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	InvalidPlayerID PlayerID = ``
	InvalidGameID   GameID   = 0
)
View Source
const (
	WinningScore    int = 121
	MaxPeggingValue int = 31
)
View Source
const (
	MinPlayerGame int = 2
	MaxPlayerGame int = 4
)
View Source
const JackValue = 11 // Ace is 1, King is 13
View Source
const NumCardsPerDeck = 52

Variables

View Source
var (
	InvalidCard = Card{}
)

Functions

func IsValidPlayerID

func IsValidPlayerID(pID PlayerID) bool

Types

type Blocker

type Blocker int
const (
	DealCards Blocker = 0
	CribCard  Blocker = 1
	CutCard   Blocker = 2
	PegCard   Blocker = 3
	CountHand Blocker = 4
	CountCrib Blocker = 5
)

func NewBlockerFromString

func NewBlockerFromString(b string) Blocker

func (Blocker) String

func (b Blocker) String() string

type BuildCribAction

type BuildCribAction struct {
	Cards []Card `json:"cs" bson:"cs"`
}

type Card

type Card struct {
	Suit Suit `json:"s" bson:"s"`
	// Ace is 1, King is 13
	Value int `json:"v" bson:"v"`
}

func NewCard

func NewCard(suit Suit, value int) Card

func NewCardFromExternalString

func NewCardFromExternalString(card string) (Card, error)

NewCardFromExternalString returns a card, or an error if the input is invalid Use this for external inputs (i.e. REST requests)

func NewCardFromNumber

func NewCardFromNumber(val int) Card

func NewCardFromString

func NewCardFromString(card string) Card

func NewCardFromTinyInt

func NewCardFromTinyInt(val int8) (Card, error)

func SortByValue

func SortByValue(input []Card, descending bool) []Card

SortByValue sorts a slice of cards either ascending or descending by their rank order

func (Card) PegValue

func (c Card) PegValue() int

func (Card) String

func (c Card) String() string

func (Card) ToTinyInt

func (c Card) ToTinyInt() int8

type CountCribAction

type CountCribAction struct {
	Pts int `json:"pts" bson:"pts"`
}

type CountHandAction

type CountHandAction struct {
	Pts int `json:"pts" bson:"pts"`
}

type CribBlocker

type CribBlocker struct {
	Desired      int                      `protobuf:"varint,1,req,name=desired,proto3" json:"d" bson:"d"`                                        //nolint:lll//nolint:lll
	Dealer       PlayerID                 `protobuf:"varint,2,req,name=playerID,proto3" json:"pID" bson:"pID"`                                   //nolint:lll//nolint:lll
	PlayerColors map[PlayerID]PlayerColor `protobuf:"map<varint,varint>,3,opt,name=playerColors,proto3" json:"pc,omitempty" bson:"pc,omitempty"` //nolint:lll//nolint:lll
}

type CutDeckAction

type CutDeckAction struct {
	Percentage float64 `json:"p" bson:"p"`
}

type DealAction

type DealAction struct {
	NumShuffles int `json:"ns" bson:"ns"`
}

type Deck

type Deck interface {
	Deal() Card
	Shuffle()
	CutDeck(p float64) (Card, error)
}

func NewDeck

func NewDeck() Deck

type Game

type Game struct {
	// The unique identifier used to reference this game
	ID GameID `protobuf:"-" json:"id" bson:"id"` //nolint:lll

	// The players playing this game and their colors
	Players      []Player                 `protobuf:"-" json:"ps" bson:"ps"`             //nolint:lll
	PlayerColors map[PlayerID]PlayerColor `protobuf:"-" json:"pcs,omitempty" bson:"pcs"` //nolint:lll

	// The current (and lagging) scores
	CurrentScores map[PlayerColor]int `protobuf:"-" json:"cs" bson:"cs"` //nolint:lll
	LagScores     map[PlayerColor]int `protobuf:"-" json:"ls" bson:"ls"` //nolint:lll

	// What phase this game is in
	Phase Phase `protobuf:"-" json:"p" bson:"p"` //nolint:lll
	// Who is blocking and why
	BlockingPlayers map[PlayerID]Blocker `protobuf:"-" json:"bps,omitempty" bson:"bps"` //nolint:lll

	// The identifier for the current dealer
	CurrentDealer PlayerID `protobuf:"-" json:"cd" bson:"cd"` //nolint:lll

	// The hands of each player
	Hands map[PlayerID][]Card `protobuf:"-" json:"hs,omitempty" bson:"hs"` //nolint:lll
	// The cards currently in the crib
	Crib []Card `protobuf:"-" json:"c,omitempty" bson:"c"` //nolint:lll

	// The flipped card which acts as the lead
	CutCard Card `protobuf:"-" json:"cc" bson:"cc"` //nolint:lll

	// An ordered list of previously pegged cards (which includes who pegged them), most recent last
	PeggedCards []PeggedCard `protobuf:"-" json:"pegged,omitempty" bson:"pegged"` //nolint:lll

	// An ordered list of player actions
	Actions []PlayerAction `protobuf:"-" json:"as" bson:"as"` //nolint:lll
}

Game represents all of the data needed for a game of cribbage between 2, 3, or 4 players

func (*Game) AddAction

func (g *Game) AddAction(a PlayerAction)

func (*Game) CurrentPeg

func (g *Game) CurrentPeg() int

func (*Game) GetDeck

func (g *Game) GetDeck() (Deck, error)

func (*Game) IsOver

func (g *Game) IsOver() bool

func (*Game) NumActions

func (g *Game) NumActions() int

type GameID

type GameID uint32

func NewGameID

func NewGameID() GameID

type PegAction

type PegAction struct {
	Card  Card `json:"c" bson:"c"`
	SayGo bool `json:"sg" bson:"sg"`
}

type PeggedCard

type PeggedCard struct {
	Card `protobuf:"-" json:"pc" bson:"pc"` //nolint:lll

	Action   int      `protobuf:"-" json:"aIdx" bson:"aIdx"` //nolint:lll
	PlayerID PlayerID `protobuf:"-" json:"pID" bson:"pID"`   //nolint:lll
}

func NewPeggedCard

func NewPeggedCard(pID PlayerID, c Card, numActions int) PeggedCard

func NewPeggedCardFromString

func NewPeggedCardFromString(pID PlayerID, cStr string, numActions int) PeggedCard

type Phase

type Phase int
const (
	Deal              Phase = 0
	BuildCribReady    Phase = 1
	BuildCrib         Phase = 2
	CutReady          Phase = 3
	Cut               Phase = 4
	PeggingReady      Phase = 5
	Pegging           Phase = 6
	CountingReady     Phase = 7
	Counting          Phase = 8
	CribCountingReady Phase = 9
	CribCounting      Phase = 10
	DealingReady      Phase = 11
)

func NewPhaseFromString

func NewPhaseFromString(p string) Phase

func (Phase) String

func (p Phase) String() string

type Player

type Player struct {
	ID    PlayerID               `protobuf:"varint,1,req,name=id,proto3" json:"id" bson:"id"`                           //nolint:lll
	Name  string                 `protobuf:"string,2,req,name=name,proto3" json:"n" bson:"n"`                           //nolint:lll
	Games map[GameID]PlayerColor `protobuf:"map<varint, varint>,3,opt,name=games,proto3" json:"gs,omitempty" bson:"gs"` //nolint:lll
}

type PlayerAction

type PlayerAction struct {
	GameID    GameID      `json:"gID" bson:"gID"`
	ID        PlayerID    `json:"pID" bson:"pID"`
	Overcomes Blocker     `json:"o" bson:"o"`
	Action    interface{} `json:"a" bson:"a"`

	TimestampStr string `json:"timestamp,omitempty" bson:"-"`
}

func (*PlayerAction) SetTimeStamp

func (pa *PlayerAction) SetTimeStamp(ts time.Time)

type PlayerColor

type PlayerColor int8
const (
	UnsetColor PlayerColor = 0
	Green      PlayerColor = 1
	Blue       PlayerColor = 2
	Red        PlayerColor = 3
)

func NewPlayerColorFromString

func NewPlayerColorFromString(c string) PlayerColor

func (PlayerColor) String

func (c PlayerColor) String() string

type PlayerID

type PlayerID string

type Suit

type Suit int
const (
	Spades Suit = iota
	Clubs
	Diamonds
	Hearts
)

func (Suit) String

func (s Suit) String() string

type TestingTossStats

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

func NewTestingTossStats

func NewTestingTossStats(min int, avg, median float64, max int) *TestingTossStats

func (*TestingTossStats) Avg

func (ts *TestingTossStats) Avg() float64

func (*TestingTossStats) Max

func (ts *TestingTossStats) Max() int

func (*TestingTossStats) Median

func (ts *TestingTossStats) Median() float64

func (*TestingTossStats) Min

func (ts *TestingTossStats) Min() int

type TossStats

type TossStats interface {
	Min() int
	Median() float64
	Avg() float64
	Max() int
}

type TossSummary

type TossSummary struct {
	Kept   []Card
	Tossed []Card

	HandStats TossStats
	CribStats TossStats
}

Jump to

Keyboard shortcuts

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