...

Package cribbage

Overview ▾

Package cribbage provides cribbage scoring.

Cards

To retrieve the cribbage value of a card:

cribbageValue := cribbage.Value(card)

Scoring

To score a play, supply a discard pile:

pegPoints, pegResult := cribbage.Score(cribbage.Peg, discard, Card{})

To score a shown hand, supply a hand and a starter card:

handPoints, handResult := cribbage.Score(cribbage.ShownHand, hand, starter)

func Sum

func Sum(c joker.Cards) int

Sum returns the total cribbage value of the supplied cards.

func Value

func Value(c joker.Card) int

Value returns the cribbage value of a card.

type ScoreResult

ScoreResult is a score from pegging or showing a hand.

type ScoreResult struct {
    Type   ScoreType
    Cards  joker.Cards
    Points int
}

func (ScoreResult) String

func (r ScoreResult) String() string

type ScoreResults

ScoreResults is a slice of scores from pegging or showing a hand.

type ScoreResults []ScoreResult

func Score

func Score(scoringType ScoringType, c joker.Cards, starter joker.Card) (int, ScoreResults)

Score returns the score of a pegging play or shown hand.

func (ScoreResults) Len

func (r ScoreResults) Len() int

func (ScoreResults) Less

func (r ScoreResults) Less(i, j int) bool

func (ScoreResults) Swap

func (r ScoreResults) Swap(i, j int)

type ScoreType

ScoreType represents a type of score.

type ScoreType int

Score types and their point values

const (
    Score15    ScoreType = 1 // 2
    ScorePair  ScoreType = 2 // 2
    ScoreRun   ScoreType = 3 // 1/card
    ScoreFlush ScoreType = 4 // 1/card
    ScoreNibs  ScoreType = 5 // 2
    ScoreNobs  ScoreType = 6 // 1
    Score31    ScoreType = 7 // 2
    ScoreGo    ScoreType = 8 // 1
)

func (ScoreType) String

func (t ScoreType) String() string

type ScoringType

ScoringType represents a set of scoring rules.

type ScoringType int

Scoring types

const (
    Peg      ScoringType = 1
    ShowHand ScoringType = 2
    ShowCrib ScoringType = 3
)

func (ScoringType) String

func (t ScoringType) String() string