Cribbage server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
913 B

package main
import (
"fmt"
"strings"
"gitlab.com/tslocum/joker"
)
type PlayerCard struct {
joker.Card
Player int
}
func (c PlayerCard) String() string {
return fmt.Sprintf("{%d}%s", c.Player, c.Card)
}
type PlayerCards []PlayerCard
func (c PlayerCards) String() string {
var s strings.Builder
for i := range c {
if i > 0 {
s.WriteRune(',')
}
s.WriteString(c[i].String())
}
return s.String()
}
func (c PlayerCards) Len() int {
return len(c)
}
func (c PlayerCards) Less(i, j int) bool {
return c[i].Value() < c[j].Value()
}
func (c PlayerCards) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
func (c PlayerCards) Cards() joker.Cards {
var cards = make(joker.Cards, len(c))
for i, card := range c {
cards[i] = card.Card
}
return cards
}
func (c PlayerCards) PlayerCards(player int) int {
var i int
for _, card := range c {
if card.Player == player {
i++
}
}
return i
}