Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidPlayerID(pID PlayerID) bool
- type Blocker
- type BuildCribAction
- type Card
- type CountCribAction
- type CountHandAction
- type CribBlocker
- type CutDeckAction
- type DealAction
- type Deck
- type Game
- type GameID
- type PegAction
- type PeggedCard
- type Phase
- type Player
- type PlayerAction
- type PlayerColor
- type PlayerID
- type Suit
- type TestingTossStats
- type TossStats
- type TossSummary
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 ¶
Types ¶
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 NewCardFromExternalString ¶
NewCardFromExternalString returns a card, or an error if the input is invalid Use this for external inputs (i.e. REST requests)
func NewCardFromNumber ¶
func NewCardFromString ¶
func NewCardFromTinyInt ¶
func SortByValue ¶
SortByValue sorts a slice of cards either ascending or descending by their rank order
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 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 (*Game) NumActions ¶
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 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 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
Click to show internal directories.
Click to hide internal directories.