cribbage

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 3 Imported by: 0

README

joker-cribbage

GoDoc CI status Donate

Cribbage scoring library based on joker

Documentation

Documentation is available via godoc:

Support

Please share issues and suggestions here.

Documentation

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)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type ScoreResult

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

ScoreResult is a score from pegging or showing a hand.

func (ScoreResult) String

func (r ScoreResult) String() string

type ScoreResults

type ScoreResults []ScoreResult

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

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

type ScoreType int

ScoreType represents a type of score.

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
)

Score types and their point values

func (ScoreType) String

func (t ScoreType) String() string

type ScoringType

type ScoringType int

ScoringType represents a set of scoring rules.

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

Scoring types

func (ScoringType) String

func (t ScoringType) String() string

Jump to

Keyboard shortcuts

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