game_sync/gamerule/thirteen/logic_test.go

282 lines
7.8 KiB
Go

package thirteen
import (
"fmt"
"math/rand"
"sort"
"strings"
"testing"
)
func TestFindAllPokers(t *testing.T) {
l := new(Logic)
l.LaiZi = []int{52, 53}
data := [][13]int{
{31, 3, 2, 8, 7, 15, 44, 49, 9, 16, 10, 19, 6},
{13, 23, 24, 36, 37, 38, 39, 51, 51, 50, 10, 11, 12},
{6 + 39, 7 + 39, 8 + 39, 2 + 13, 3 + 13, 4 + 13, 5 + 13, 6 + 13, 4 + 26, 5 + 26, 6 + 26, 7 + 26, 8 + 26},
{27, 28, 34, 12, 36, 39, 35, 46, 7, 2, 6, 24, 50},
{27, 51, 33, 29, 45, 7, 34, 31, 36, 38, 44, 10, 30},
{1, 2, 3, 8, 9, 0, 20, 32, 12, 45, 12},
{18, 5, 11, 20, 19, 36, 42, 17, 21, 25, 43, 34, 1},
{3, 9, 45, 31, 38, 21, 33, 36, 41, 20, 7, 28, 32},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
{0 + 13, 1 + 13, 2 + 13, 3 + 13, 4 + 13, 5 + 13, 6 + 13, 7 + 13, 8 + 13, 9 + 13, 10 + 13, 11 + 13, 12 + 13},
{0, 14, 28, 3, 17, 31, 45, 7, 21, 22, 36, 50, 25},
{0, 13, 26, 39, 12, 25, 38, 11, 37, 50, 10, 23, 49},
{1, 2, 3, 4, 5, 14, 15, 16, 17, 18, 27, 28, 29},
{0, 13, 26, 39, 1, 14, 27, 40, 3, 16, 29, 42, 50},
{7, 20, 21, 34, 35, 48, 10, 12, 24, 50, 12, 25, 0},
{1, 15, 29, 43, 5, 32, 46, 14, 28, 30, 31, 45, 7},
{0, 26, 1, 2, 28, 4, 30, 6, 32, 9, 35, 11, 37},
{0, 13, 26, 3, 16, 29, 5, 18, 31, 9, 22, 48, 12},
{0, 26, 2, 15, 4, 30, 6, 19, 8, 21, 11, 24, 50},
{0, 26, 2, 15, 4, 30, 6, 19, 8, 21, 10, 23, 24},
{0, 1, 15, 3, 17, 29, 43, 31, 19, 7, 36, 24, 12},
{0, 3, 6, 9, 12, 13, 19, 20, 21, 23, 26, 32, 38},
//三同花
{15, 17, 19, 23, 25, 28, 30, 33, 36, 38, 44, 47, 48},
{26, 27, 29, 31, 32, 44, 46, 48, 49, 51, 0, 8, 12},
{39, 42, 44, 45, 47, 0, 1, 7, 9, 11, 13, 17, 21},
{43, 42, 46, 26, 29, 33, 35, 34, 2, 1, 0, 5, 52},
//三顺子
{28, 16, 30, 5, 32, 44, 6, 7, 21, 35, 47, 22, 23},
{1, 28, 16, 17, 18, 30, 31, 45, 20, 8, 36, 50, 12},
//六对半
{17, 30, 5, 31, 6, 32, 8, 47, 23, 36, 38, 51, 39},
{26, 39, 15, 28, 16, 42, 4, 17, 18, 31, 34, 47, 22},
{7, 20, 21, 34, 10, 23, 24, 37, 38, 51, 15, 28, 43},
//五对三条
{17, 30, 5, 31, 6, 32, 8, 47, 23, 36, 12, 25, 38},
{26, 39, 15, 28, 16, 42, 4, 17, 18, 31, 9, 22, 35},
{7, 20, 21, 34, 10, 23, 24, 37, 38, 51, 1, 14, 40},
//四套三条
{5, 18, 44, 6, 19, 32, 7, 33, 46, 10, 23, 36, 50},
{1, 27, 40, 4, 17, 30, 6, 19, 32, 11, 37, 50, 51},
{16, 29, 42, 18, 31, 44, 8, 21, 47, 10, 23, 36, 25},
//凑一色
{13, 14, 40, 16, 42, 18, 44, 19, 46, 47, 23, 49, 25},
{0, 1, 2, 28, 3, 29, 5, 31, 8, 10, 11, 12, 37},
{39, 40, 17, 18, 44, 45, 21, 48, 49, 24, 50, 25, 51},
//全小
{2, 15, 28, 41, 4, 17, 30, 43, 5, 18, 6, 45, 6},
{3, 16, 42, 5, 18, 31, 6, 19, 32, 5, 18, 30, 45},
{14, 27, 40, 15, 28, 41, 4, 17, 5, 18, 6, 19, 6},
//全大
{8, 21, 47, 9, 22, 35, 48, 10, 23, 36, 12, 25, 51},
{7, 20, 33, 8, 21, 34, 12, 25, 38, 12, 25, 38, 10},
{7, 21, 35, 23, 11, 38, 25, 33, 48, 49, 50, 12, 25},
//三分天下
{4, 17, 30, 43, 5, 18, 31, 44, 7, 20, 33, 46, 51},
{6, 19, 32, 45, 7, 20, 33, 46, 9, 22, 35, 48, 49},
{10, 23, 36, 49, 11, 24, 37, 50, 12, 25, 38, 51, 13},
//
{24, 18, 42, 25, 13, 15, 2, 7, 39, 38, 34, 33, 30},
{51, 51, 51, 51, 12, 52, 12, 11, 10, 9, 8, 7, 6},
{46, 35, 30, 50, 34, 9, 25, 41, 3, 26, 2, 6, 45},
}
//
//牌序- A, K, Q, J,10, 9, 8, 7, 6, 5, 4, 3, 2
//黑桃-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
//data = [][13]int{
// //{31, 42, 14, 49, 23, 25, 12, 6, 33, 20, 34, 21, 7},
// {13, 23, 24, 36, 37, 38, 39, 51, 51, 50, 10, 11, 12},
//}
for _, v := range data {
cards := v
fmt.Println(PokersShow(cards[:]))
for k, v := range l.Suggest(cards) {
fmt.Println(k, SpecialName(k), v)
if k >= 1000000 {
continue
}
cs := make([]int, 0, 13)
for _, v := range v.Head {
if v >= 0 {
cs = append(cs, v)
}
}
for _, v := range v.Mid {
if v >= 0 {
cs = append(cs, v)
}
}
for _, v := range v.End {
if v >= 0 {
cs = append(cs, v)
}
}
sort.Ints(cards[:])
sort.Ints(cs)
if !arrEqual([][]int{cards[:]}, [][]int{cs}) {
fmt.Println("牌不对")
t.Fatal()
}
if l.IsDP(v.Head, v.Mid, v.End) {
fmt.Println("倒排")
t.Fatal()
}
}
}
}
func TestC(t *testing.T) {
for i := 0; i < 10; i++ {
rand.Shuffle(len(pokers2Test), func(i, j int) {
pokers2Test[i], pokers2Test[j] = pokers2Test[j], pokers2Test[i]
})
v := pokers2Test[:10]
buf := strings.Builder{}
buf.WriteString("{")
for m, n := range v {
buf.WriteString(fmt.Sprint(n))
if m < len(v)-1 {
buf.WriteString(",")
}
}
buf.WriteString(",-2},")
fmt.Println(buf.String())
}
}
func TestLogic_CompareHead(t *testing.T) {
l := new(Logic)
l.LaiZi = []int{52, 53}
data := [][]int{
// 比花色的
//{1, 27, 49, 50, 43, 42, 1},
//{47, 20, 23, 29, 36, 42, -1},
//{0, 2, 18, 31, 21, 29, -1},
//{45, 7, 18, 13, 15, 29, 1},
//{14, 4, 46, 9, 1, 11, -1},
//{7, 3, 24, 43, 50, 44, 1},
//{5, 4, 31, 15, 33, 14, 1},
//{21, 21, 32, 31, 38, 28, 1},
//{47, 38, 49, 30, 34, 23, 1},
//{14, 10, 16, 29, 30, 35, 1},
////
//{0, 52, 8, 7, 8, 9, 1},
//{0, 52, 52, 7, 8, 9, 1},
//{0, 52, 52, 7, 51, 53, 1},
//{0, 52, 51, 7, 51, 53, -1},
//{8, 52, 51, 7, 51, 53, 1},
//{7, 52, 51, 7, 51, 53, 0},
//{7, 9, 22, 22, 7, 53, -1},
//{7, 48, 22, 22, 7, 53, 1},
//{7, 48, 22, 22, 6, 53, 1},
//{7, 48, 22, 22, 20, 53, -1},
// 不比花色
{1, 27, 49, 50, 43, 42, 1},
{47, 20, 23, 29, 36, 42, -1},
{0, 2, 18, 31, 21, 29, -1},
{45, 7, 18, 13, 15, 29, 1},
{14, 4, 46, 9, 1, 11, -1},
{7, 3, 24, 43, 50, 44, 1},
{5, 4, 31, 15, 33, 14, 1},
{21, 21, 32, 31, 38, 28, 1},
{47, 38, 49, 30, 34, 23, 1},
{14, 10, 16, 29, 30, 35, 1},
//
{0, 52, 8, 7, 8, 9, 1},
{0, 52, 52, 7, 8, 9, 1},
{0, 52, 52, 7, 51, 53, 1},
{0, 52, 51, 7, 51, 53, -1},
{8, 52, 51, 7, 51, 53, 1},
{7, 52, 51, 7, 51, 53, 0},
{7, 9, 22, 22, 7, 53, 1},
{7, 48, 22, 22, 7, 53, 1},
{7, 48, 22, 22, 6, 53, 1},
{7, 48, 22, 22, 20, 53, 1},
}
for _, v := range data {
a := [3]int{}
b := [3]int{}
copy(a[:], v[:3])
copy(b[:], v[3:6])
R := -2
if len(v) > 6 {
R = v[6]
}
r := l.CompareHead(a, b)
if r != R {
t.Fatalf("比牌错误:%v and %v 结果%v 正确结果%v\n", PokersShow(a[:]), PokersShow(b[:]), r, R)
} else {
t.Logf("比牌日志:%v and %v 结果%v 正确结果%v\n", PokersShow(a[:]), PokersShow(b[:]), r, R)
}
}
}
func TestLogic_CompareFive(t *testing.T) {
l := new(Logic)
l.LaiZi = []int{52, 53}
data := [][]int{
{5, 23, 10, 6, 1, 45, 41, 20, 1, 13, 1},
{29, 31, 26, 1, 39, 31, 44, 17, 9, 34, -1},
{24, 26, 9, 10, 0, 16, 30, 7, 37, 3, -1},
{31, 30, 11, 33, 7, 18, 1, 36, 9, 3, 1},
// 牌型不同
{2, 15, 28, 0, 6, 12, 0, 1, 2, 3, -1},
// 点数不同
{2, 15, 28, 0, 6, 2, 15, 28, 0, 6, 0},
{2, 15, 28, 0, 6, 2, 15, 28, 0, 7, -1},
{0, 13, 4, 17, 6, 0, 13, 4, 17, 5, 1},
{0, 13, 5, 18, 6, 0, 13, 4, 17, 6, 1},
{1, 14, 4, 17, 6, 0, 13, 4, 17, 5, 1},
// 花色不同
{2, 15, 28, 0, 6, 2, 15, 28, 0, 19, 0},
{41, 15, 28, 0, 6, 2, 15, 28, 0, 6, 0},
{2, 15, 28, 0, 6, 2, 15, 28, 13, 6, 0},
{3, 4, 5, 6, 52, 3, 52, 5, 6, 53, 1},
{3, 17, 5, 6, 52, 3, 52, 5, 6, 53, -1},
{3, 4, 5, 6, 7, 16, 52, 18, 19, 53, 1},
{3, 52, 5, 6, 20, 3, 17, 18, 19, 53, 0},
{3, 52, 5, 6, 46, 3, 17, 18, 19, 53, 0},
// 癞子数不同
{52, 52, 7, 20, 12, 52, 7, 20, 33, 25, -1},
{52, 33, 7, 20, 12, 52, 7, 20, 33, 25, 0},
}
for _, v := range data {
a := [5]int{}
b := [5]int{}
copy(a[:], v[:5])
copy(b[:], v[5:10])
R := -2
if len(v) > 10 {
R = v[10]
}
r := l.CompareFive(a, b)
if r != R {
t.Fatalf("比牌错误:%v and %v 结果%v 正确结果%v\n", PokersShow(a[:]), PokersShow(b[:]), r, R)
} else {
t.Logf("比牌日志:%v and %v 结果%v 正确结果%v\n", PokersShow(a[:]), PokersShow(b[:]), r, R)
}
}
}
func TestLogic_IsDP(t *testing.T) {
}