package tienlen

import (
	"fmt"
	"math/rand"
	"sort"
	"testing"
)

//牌序- 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

func TestPoker(t *testing.T) {
	poker := NewPoker()

	gradess := [][]int{}
	gradess1 := []int{}
	gradess2 := []int{}
	gradess3 := []int{}
	gradess4 := []int{}

	for i := 0; i < 1000; i++ {
		grade4s := SendHandCard(poker)
		//fmt.Println("局数: ", i+1)
		//for _, grade := range grades {
		//	fmt.Println(" grade: ", grade)
		//}
		gradess = append(gradess, grade4s)
	}

	fmt.Println("gradess: ", gradess)
	for _, grades := range gradess {
		for i, grade := range grades {
			if i == 0 {
				gradess1 = append(gradess1, grade)
			}
			if i == 1 {
				gradess2 = append(gradess2, grade)
			}
			if i == 2 {
				gradess3 = append(gradess3, grade)
			}
			if i == 3 {
				gradess4 = append(gradess4, grade)
			}
		}
	}
	fmt.Println("==========================1")
	for _, g1 := range gradess1 {
		fmt.Println(g1)
	}
	fmt.Println("==========================2")
	for _, g2 := range gradess2 {
		fmt.Println(g2)
	}
	fmt.Println("==========================3")
	for _, g3 := range gradess3 {
		fmt.Println(g3)
	}
	fmt.Println("==========================4")
	for _, g4 := range gradess4 {
		fmt.Println(g4)
	}
}

func TestGetCardsGrade(t *testing.T) {
	var n int
	for i := 0; i < 100; i++ {
		var score []int
		var allCards []int32
		for i := 0; i < POKER_CNT; i++ {
			allCards = append(allCards, int32(i))
		}
		rand.Shuffle(len(allCards), func(i, j int) {
			allCards[i], allCards[j] = allCards[j], allCards[i]
		})
		for i := 0; i < 4; i++ {
			ok := Have6StraightTwin(allCards[:13]) || Have12Straight(allCards[:13]) || Have2FourBomb(allCards[:13])
			if ok {
				t.Log("ttttttttttttttttttttttttttttttttttt")
			}
			score = append(score, GetCardsGrade(allCards[:13], false))
			allCards = allCards[13:]
		}
		sort.Ints(score)
		fmt.Println(score)
		if score[len(score)-1]-score[0] > 30 && score[len(score)-2]-score[0] > 30 {
			n++
		}
	}
	fmt.Println(n)
}
