|
|
|
@ -4,7 +4,7 @@ import (
|
|
|
|
|
"log"
|
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
|
|
. "git.sr.ht/~tslocum/cards"
|
|
|
|
|
. "git.sr.ht/~tslocum/joker"
|
|
|
|
|
"github.com/fighterlyt/permutation"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -83,9 +83,10 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
|
|
|
|
|
var scoreCards Cards
|
|
|
|
|
if scoringType == Peg {
|
|
|
|
|
scoreCards = c.Reverse()
|
|
|
|
|
scoreCards = c.Reversed()
|
|
|
|
|
} else {
|
|
|
|
|
scoreCards = append(c.Copy(), starter).Sort()
|
|
|
|
|
scoreCards = append(c.Copy(), starter)
|
|
|
|
|
sort.Sort(scoreCards)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Score 15s
|
|
|
|
@ -126,7 +127,8 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
allusedcards = append(allusedcards, usedcards)
|
|
|
|
|
fifteenscore++
|
|
|
|
|
|
|
|
|
|
results = append(results, ScoreResult{Type: Score15, Cards: usedcards.Sort(), Points: 2})
|
|
|
|
|
sort.Sort(usedcards)
|
|
|
|
|
results = append(results, ScoreResult{Type: Score15, Cards: usedcards, Points: 2})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -136,7 +138,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if Sum(scoreCards) == 15 {
|
|
|
|
|
results = append(results, ScoreResult{Type: Score15, Cards: scoreCards.Sort(), Points: 2})
|
|
|
|
|
results = append(results, ScoreResult{Type: Score15, Cards: scoreCards.Sorted(), Points: 2})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -166,29 +168,32 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
} else if len(paircards) == 4 {
|
|
|
|
|
pairmultiplier = 3
|
|
|
|
|
}
|
|
|
|
|
results = append(results, ScoreResult{Type: ScorePair, Cards: paircards.Sort(), Points: len(paircards) * pairmultiplier})
|
|
|
|
|
sort.Sort(paircards)
|
|
|
|
|
results = append(results, ScoreResult{Type: ScorePair, Cards: paircards, Points: len(paircards) * pairmultiplier})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
faces = append(faces, card.Face)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if len(scoreCards) > 0 {
|
|
|
|
|
var paircards Cards
|
|
|
|
|
var pairCards Cards
|
|
|
|
|
for _, compcard := range scoreCards[1:] {
|
|
|
|
|
if compcard.Face != scoreCards[0].Face {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paircards = append(paircards, compcard)
|
|
|
|
|
pairCards = append(pairCards, compcard)
|
|
|
|
|
}
|
|
|
|
|
pairmultiplier := 1
|
|
|
|
|
if len(paircards) == 2 {
|
|
|
|
|
if len(pairCards) == 2 {
|
|
|
|
|
pairmultiplier = 2
|
|
|
|
|
} else if len(paircards) == 3 {
|
|
|
|
|
} else if len(pairCards) == 3 {
|
|
|
|
|
pairmultiplier = 3
|
|
|
|
|
}
|
|
|
|
|
if paircards != nil {
|
|
|
|
|
results = append(results, ScoreResult{Type: ScorePair, Cards: append(paircards, scoreCards[0]).Sort(), Points: (len(paircards) + 1) * pairmultiplier})
|
|
|
|
|
if pairCards != nil {
|
|
|
|
|
pairCards = append(pairCards, scoreCards[0])
|
|
|
|
|
sort.Sort(pairCards)
|
|
|
|
|
results = append(results, ScoreResult{Type: ScorePair, Cards: pairCards, Points: len(pairCards) * pairmultiplier})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -206,12 +211,12 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
// Examine the pile for a run by shortening the checked pile one card
|
|
|
|
|
// after each iteration.
|
|
|
|
|
SCOREPEGRUN:
|
|
|
|
|
for complen := 0; complen < len(scoreCards); complen++ {
|
|
|
|
|
compHand = scoreCards[0 : len(scoreCards)-complen]
|
|
|
|
|
for complen := len(scoreCards); complen > 0; complen-- {
|
|
|
|
|
compHand = scoreCards[0:complen].Sorted()
|
|
|
|
|
compScore = 1
|
|
|
|
|
runCards = nil
|
|
|
|
|
|
|
|
|
|
for i, compcard := range compHand.Sort() {
|
|
|
|
|
for i, compcard := range compHand {
|
|
|
|
|
if i > 0 {
|
|
|
|
|
if int(compcard.Face) == (runValue + 1) {
|
|
|
|
|
compScore++
|
|
|
|
@ -227,7 +232,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
runScore = compScore
|
|
|
|
|
|
|
|
|
|
if runScore == len(scoreCards) {
|
|
|
|
|
runCards = compHand.Sort()
|
|
|
|
|
runCards = compHand
|
|
|
|
|
break SCOREPEGRUN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -262,7 +267,7 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runCards = runCards.Sort()
|
|
|
|
|
sort.Sort(runCards)
|
|
|
|
|
for _, rc := range allRunCards {
|
|
|
|
|
containsAll := true
|
|
|
|
|
for _, runCard := range runCards {
|
|
|
|
@ -298,7 +303,8 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
flushCards = append(flushCards, starter)
|
|
|
|
|
}
|
|
|
|
|
if suitvalue == 5 || (suitvalue == 4 && scoringType == ShowHand) {
|
|
|
|
|
results = append(results, ScoreResult{Type: ScoreFlush, Cards: flushCards.Sort(), Points: suitvalue})
|
|
|
|
|
sort.Sort(flushCards)
|
|
|
|
|
results = append(results, ScoreResult{Type: ScoreFlush, Cards: flushCards, Points: suitvalue})
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -314,7 +320,8 @@ func Score(scoringType ScoringType, c Cards, starter Card) (int, ScoreResults) {
|
|
|
|
|
|
|
|
|
|
// Score 31
|
|
|
|
|
if scoringType == Peg && Sum(scoreCards) == 31 {
|
|
|
|
|
results = append(results, ScoreResult{Type: Score31, Cards: scoreCards.Sort(), Points: 2})
|
|
|
|
|
sort.Sort(scoreCards)
|
|
|
|
|
results = append(results, ScoreResult{Type: Score31, Cards: scoreCards, Points: 2})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, r := range results {
|
|
|
|
|