game_sync/gamerule/tala/poker.go

43 lines
610 B
Go

package tala
import (
"math/rand"
"time"
)
const (
POKER_CNT = 52
PER_CARD_COLOR_MAX = 13
)
type Card int
type Poker struct {
buf [POKER_CNT]Card
}
func (this *Poker) GetPokerBuf() [POKER_CNT]Card {
return this.buf
}
func NewPoker() *Poker {
p := &Poker{}
p.init()
return p
}
func (this *Poker) init() {
for i := int32(0); i < POKER_CNT; i++ {
this.buf[i] = Card(i)
}
rand.Seed(time.Now().UnixNano())
this.Shuffle()
}
func (this *Poker) Shuffle() {
for i := int32(0); i < POKER_CNT; i++ {
j := rand.Intn(int(i) + 1)
this.buf[i], this.buf[j] = this.buf[j], this.buf[i]
}
}