package samloc

import (
	"math/rand"
	"time"
)

//牌序- 2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3
//红桃- 51,50,49,48,47,46,45,44,43,42,41,40,39
//方片- 38,37,36,35,34,33,32,31,30,29,28,27,26
//梅花- 25,24,23,22,21,20,19,18,17,16,15,14,13
//黑桃- 12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

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]
	}
}

// 牌型算分~
func GetCardsGrade(cards []int32) int {
	return 0
}

func SelectOut(pokers []int32, lastShowCard *KindOfCard, otherPokers [][]int32, warn bool, outType int) (ret []int32, lcards []int32, err error) { // 选择手牌
	var v *line
	v, err = selectOut(pokers, lastShowCard,
		otherPokers, warn, 0)

	if err == nil {
		ret, lcards = v.outPokers(pokers)
		//v.Print(os.Stdout)
	}
	return
}
