83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
![]() |
package poker
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"samba/proto"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type Seat struct {
|
||
|
no int
|
||
|
pokers []*Poker
|
||
|
handPoker proto.CachetaHandPoker
|
||
|
}
|
||
|
|
||
|
func groupHighToHandPoker(groups []*GroupPokers, high []*Poker) proto.CachetaHandPoker {
|
||
|
var handPoker proto.CachetaHandPoker
|
||
|
for _, group := range groups {
|
||
|
g := proto.GroupPoker{}
|
||
|
for _, pk := range group.Pokers {
|
||
|
g.Pokers = append(g.Pokers, pk.ToInt())
|
||
|
}
|
||
|
handPoker.Groups = append(handPoker.Groups, &g)
|
||
|
}
|
||
|
for _, h := range high {
|
||
|
handPoker.Pokers = append(handPoker.Pokers, h.ToInt())
|
||
|
}
|
||
|
return handPoker
|
||
|
}
|
||
|
|
||
|
func checkPokersAndHandPoker(t *testing.T, handPoker proto.CachetaHandPoker, pokers []*Poker) bool {
|
||
|
num := 0
|
||
|
for _, g := range handPoker.Groups {
|
||
|
num += len(g.Pokers)
|
||
|
}
|
||
|
num += len(handPoker.Pokers)
|
||
|
if num != len(pokers) {
|
||
|
t.Log(HandPokersToString(handPoker))
|
||
|
return false
|
||
|
}
|
||
|
pks := HandPokersToPokers(handPoker)
|
||
|
pks = sortByStraight(pks)
|
||
|
pokers = sortByStraight(pokers)
|
||
|
str1 := PokersToString(pks)
|
||
|
str2 := PokersToString(pokers)
|
||
|
if str1 != str2 {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// 从手牌中找到三条
|
||
|
func testCachetaPokers(t *testing.T, z int) {
|
||
|
pokers := NewCachetaPokers()
|
||
|
pokers.Shuffle()
|
||
|
PlayerPokersNum := 9
|
||
|
begin := 0
|
||
|
seats := []*Seat{{no: 0}, {no: 1}, {no: 2}, {no: 3}}
|
||
|
//t.Log(PokersToString(pokers.Pokers()))
|
||
|
for _, seat := range seats {
|
||
|
seat.pokers = make([]*Poker, PlayerPokersNum)
|
||
|
tmp := pokers.Pokers()[begin : begin+PlayerPokersNum]
|
||
|
for i, p := range tmp {
|
||
|
seat.pokers[i] = p
|
||
|
}
|
||
|
//seat.pokers = append(seat.pokers, pokers.Pokers()[begin:begin+PlayerPokersNum]...)
|
||
|
// 调整手牌
|
||
|
groups, high := FindBestGroupsAndRemains(pokers.WildPoker(), seat.pokers)
|
||
|
seat.handPoker = groupHighToHandPoker(groups, high)
|
||
|
if !checkPokersAndHandPoker(t, seat.handPoker, seat.pokers) {
|
||
|
t.Log(fmt.Sprintf("玩家:%v 手牌:%v", seat.no, PokersToString(seat.pokers)))
|
||
|
t.Log(GroupsHighPokersToString(pokers.wildPoker, groups, high))
|
||
|
t.Log(z)
|
||
|
}
|
||
|
begin = begin + PlayerPokersNum
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Test_CachetaPokers(t *testing.T) {
|
||
|
for i := 0; i < 1000; i++ {
|
||
|
testCachetaPokers(t, i)
|
||
|
}
|
||
|
}
|