Do not use dot imports outside of tests
This commit is contained in:
parent
4543b916d8
commit
57717781be
|
@ -1,5 +1,5 @@
|
|||
# joker-cribbage
|
||||
[![GoDoc](https://godoc.org/gitlab.com/tslocum/joker-cribbage?status.svg)](https://godoc.org/gitlab.com/tslocum/joker-cribbage)
|
||||
[![GoDoc](https://gitlab.com/tslocum/godoc-static/-/raw/master/badge.svg)](https://docs.rocketnine.space/gitlab.com/tslocum/joker-cribbage)
|
||||
[![CI status](https://gitlab.com/tslocum/joker-cribbage/badges/master/pipeline.svg)](https://gitlab.com/tslocum/joker-cribbage/commits/master)
|
||||
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
|
||||
|
||||
|
@ -7,10 +7,10 @@ Cribbage scoring library based on [joker](https://gitlab.com/tslocum/joker)
|
|||
|
||||
## Documentation
|
||||
|
||||
Documentation is available via [godoc](https://godoc.org):
|
||||
Documentation is available via [godoc](https://docs.rocketnine.space):
|
||||
|
||||
- [joker](https://godoc.org/gitlab.com/tslocum/joker)
|
||||
- [joker-cribbage](https://godoc.org/gitlab.com/tslocum/joker-cribbage)
|
||||
- [joker](https://docs.rocketnine.space/gitlab.com/tslocum/joker)
|
||||
- [joker-cribbage](https://docs.rocketnine.space/gitlab.com/tslocum/joker-cribbage)
|
||||
|
||||
## Support
|
||||
|
||||
|
|
6
card.go
6
card.go
|
@ -1,9 +1,9 @@
|
|||
package cribbage
|
||||
|
||||
import . "gitlab.com/tslocum/joker"
|
||||
import "gitlab.com/tslocum/joker"
|
||||
|
||||
// Value returns the cribbage value of a card.
|
||||
func Value(c Card) int {
|
||||
func Value(c joker.Card) int {
|
||||
v := int(c.Face)
|
||||
if v > 10 {
|
||||
v = 10
|
||||
|
@ -12,7 +12,7 @@ func Value(c Card) int {
|
|||
}
|
||||
|
||||
// Sum returns the total cribbage value of the supplied cards.
|
||||
func Sum(c Cards) int {
|
||||
func Sum(c joker.Cards) int {
|
||||
var v int
|
||||
for _, card := range c {
|
||||
v += Value(card)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module gitlab.com/tslocum/joker-cribbage
|
|||
|
||||
go 1.13
|
||||
|
||||
require gitlab.com/tslocum/joker v0.1.2
|
||||
require gitlab.com/tslocum/joker v0.1.4
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,2 +1,2 @@
|
|||
gitlab.com/tslocum/joker v0.1.2 h1:7ujvgkGNUJbrvpXvNHSvKWFDYIKTCWbvFcWL1IbRVWA=
|
||||
gitlab.com/tslocum/joker v0.1.2/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
|
||||
gitlab.com/tslocum/joker v0.1.4 h1:eE/lF/m+L9gQRajPIoZnYa+7vSg2MYlzcd39TMjs0lk=
|
||||
gitlab.com/tslocum/joker v0.1.4/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
|
||||
|
|
36
score.go
36
score.go
|
@ -3,7 +3,7 @@ package cribbage
|
|||
import (
|
||||
"sort"
|
||||
|
||||
. "gitlab.com/tslocum/joker"
|
||||
"gitlab.com/tslocum/joker"
|
||||
)
|
||||
|
||||
// ScoringType represents a set of scoring rules.
|
||||
|
@ -68,7 +68,7 @@ func (t ScoreType) String() string {
|
|||
}
|
||||
|
||||
// Score returns the score of a pegging play or shown hand.
|
||||
func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
||||
func Score(scoringType ScoringType, c joker.Cards, starter joker.Card) (int, ScoreResults) {
|
||||
if (scoringType == ShowHand || scoringType == ShowCrib) && (starter.Face == 0 || starter.Suit == 0) {
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
return points, results
|
||||
}
|
||||
|
||||
var scoreCards Cards
|
||||
var permutations []Cards
|
||||
var scoreCards joker.Cards
|
||||
var permutations []joker.Cards
|
||||
if scoringType == Peg {
|
||||
scoreCards = c.Reversed()
|
||||
} else {
|
||||
|
@ -93,12 +93,12 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
fifteenscore := 0
|
||||
fifteenvalue := 0
|
||||
if scoringType != Peg {
|
||||
var allusedcards []Cards
|
||||
var usedcards Cards
|
||||
var allusedcards []joker.Cards
|
||||
var usedcards joker.Cards
|
||||
SCORE15:
|
||||
for _, permhand := range permutations {
|
||||
fifteenvalue = 0
|
||||
usedcards = Cards{}
|
||||
usedcards = joker.Cards{}
|
||||
|
||||
for _, card := range permhand {
|
||||
usedcards = append(usedcards, card)
|
||||
|
@ -136,7 +136,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
|
||||
// Score pairs
|
||||
if scoringType != Peg {
|
||||
var faces []CardFace
|
||||
var faces []joker.CardFace
|
||||
SCOREPAIR:
|
||||
for _, card := range scoreCards {
|
||||
for _, face := range faces {
|
||||
|
@ -145,7 +145,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
}
|
||||
}
|
||||
|
||||
var paircards Cards
|
||||
var paircards joker.Cards
|
||||
for _, compcard := range scoreCards {
|
||||
if compcard.Face != card.Face {
|
||||
continue
|
||||
|
@ -168,7 +168,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
}
|
||||
} else {
|
||||
if len(scoreCards) > 0 {
|
||||
var pairCards Cards
|
||||
var pairCards joker.Cards
|
||||
for _, compcard := range scoreCards[1:] {
|
||||
if compcard.Face != scoreCards[0].Face {
|
||||
break
|
||||
|
@ -191,11 +191,11 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
}
|
||||
|
||||
// Score runs
|
||||
var allRunCards []Cards
|
||||
var runCards Cards
|
||||
var allRunCards []joker.Cards
|
||||
var runCards joker.Cards
|
||||
var runScore int
|
||||
if scoringType == Peg {
|
||||
var compHand Cards
|
||||
var compHand joker.Cards
|
||||
var compScore int
|
||||
var runValue int
|
||||
runScore = 1
|
||||
|
@ -237,7 +237,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
for runLength := 6; runLength > 3; runLength-- {
|
||||
SCOREHANDRUN:
|
||||
for _, permhand := range permutations {
|
||||
runCards = Cards{}
|
||||
runCards = joker.Cards{}
|
||||
|
||||
runScore = 0
|
||||
for i := range permhand {
|
||||
|
@ -275,9 +275,9 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
|
||||
// Score flushes
|
||||
if scoringType != Peg {
|
||||
for _, suit := range StandardSuits {
|
||||
for _, suit := range joker.StandardSuits {
|
||||
suitvalue := 0
|
||||
var flushCards Cards
|
||||
var flushCards joker.Cards
|
||||
for _, card := range c {
|
||||
if card.Suit == suit {
|
||||
suitvalue++
|
||||
|
@ -298,9 +298,9 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|||
|
||||
// Score nobs
|
||||
if scoringType != Peg {
|
||||
rightJack := Card{FaceJack, starter.Suit}
|
||||
rightJack := joker.Card{joker.FaceJack, starter.Suit}
|
||||
if c.Contains(rightJack) {
|
||||
results = append(results, ScoreResult{Type: ScoreNobs, Cards: Cards{rightJack}, Points: 1})
|
||||
results = append(results, ScoreResult{Type: ScoreNobs, Cards: joker.Cards{rightJack}, Points: 1})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@ package cribbage
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
. "gitlab.com/tslocum/joker"
|
||||
"gitlab.com/tslocum/joker"
|
||||
)
|
||||
|
||||
// ScoreResult is a score from pegging or showing a hand.
|
||||
type ScoreResult struct {
|
||||
Type ScoreType
|
||||
Cards Cards
|
||||
Cards joker.Cards
|
||||
Points int
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue