斗地主,服务端代码

斗地主服务端的主要逻辑

出牌判断

package main

import (
    "errors"
    "math/rand"
    "sort"
)

// 简单的斗地主程序

// 一副牌
type OneDeckOfCards struct {
    Intact   map[int]*Card // 完整的牌
    Discard  map[int]*Card // 打过的牌
    LastPlay *LastCards    // 最后一次出的牌
}

// 单张牌的结构
type Card struct {
    Name     string // 扑克牌的名称
    Number   int    // 这张牌在这负牌创建时的位置
    Current  int    // 在当前牌中的位置
    Color    string // 这张牌的花色
    Size     int    // 这张牌对应的大小
    UsedUser int    // 这张牌是谁打掉的,用于记牌器,防止客户端篡改牌
}

// 最后一次出牌
type LastCards struct {
    PokerType        int         // 牌型
    CountSameCardMax int         // 便于快速判断
    SortCard         []int       // 排序后的出牌
    CountCard        map[int]int // 统计的出牌(包含所有的牌)
}

// 单次出牌
type PlayingCards struct {
    Cards []Card
}

const (
    PokerNumbers           = 54
    PokerKing              = 14 // 小王编号
    PokerBigKing           = 15 // 大王编号
    PokerTypeError         = -1 // 出牌错误
    PokerTypeEmpty         = 0  // 没人出牌,什么牌都可以出
    PokerTypeSingle        = 1  // 单牌
    PokerTypeDouble        = 2  // 对子
    PokerTypeThree         = 3  // 三张
    PokerTypeThreeBeltsOne = 4  // 三带一
    PokerTypeThreeBeltsTwo = 5  // 三带二
    PokerTypeShunZi        = 6  // 顺子678910
    PokerTypeLianDui       = 7  // 连对778899
    PokerTypeFlay          = 8  // 飞机666777888
    PokerTypeFlayBeltsOne  = 9  // 飞机带单
    PokerTypeFlayBeltsTwo  = 10 // 飞机带队
    PokerTypeBoomBeltsOne  = 11 // 炸弹带单张,两个单张或者一个对子
    PokerTypeBoomBeltsTwo  = 12 // 炸弹带对子
    PokerTypeBoom          = 13 // 炸弹
    PokerTypeBoomKing      = 99 // 王炸
)

func main() {
    // 创建牌
    cards, _ := CreatePoker()
    // 洗牌
    cards.ShuffleToPoker()
    // 判断牌的大小

}

// 判断牌是否合理,顺子 三带一 四带二
// 判断牌的类型
func (poker *PlayingCards) CheckType() (*CurrentCards, error) {
    // 对牌进行判断,判断牌型
    // 单 双 三 三带1  三带2 连对  顺子 飞机(带1 带二) 炸弹  王炸
    list := make([]int, len(poker.Cards))
    for key, card := range poker.Cards {
        list[key] = card.Size
    }
    // 对牌进行排序,[2 2 4 6 7 7 10 11 13 13]
    sort.Ints(list)
    // fmt.Println(list)
    // 开始判断牌型
    // 相同牌最多的是多少
    countSameCardMax := 1
    countCard := make(map[int]int, len(poker.Cards))
    sortCard := make([]int, 0)
    for _, value := range list {
        if _, ok := countCard[value]; !ok {
            countCard[value] = 1
            sortCard = append(sortCard, value)
            continue
        }
        countCard[value]++
        if countSameCardMax < countCard[value] {
            countSameCardMax = countCard[value]
        }
    }
    playPoker := &CurrentCards{
        CardTotal: len(poker.Cards),
        SortCard:  sortCard,
        CountCard: countCard,
    }
    // 1 单 或者顺子 王炸 2对子 连队  3 三带一 三带2  飞机带  4 炸弹
    var err error
    switch countSameCardMax {
    case 1:
        // 1 单,顺子 或者 王炸
        playPoker.PokerType, err = poker.countSameCardMaxOne(countCard, sortCard)
        return playPoker, err
    case 2:
        //  2对子 连队
        playPoker.PokerType, err = poker.countSameCardMaxTwo(countCard, sortCard)
        return playPoker, err
    case 3:
        // 3 三带一 三带2  飞机带
        playPoker.PokerType, err = poker.countSameCardMaxThree(countCard)
        return playPoker, err
    case 4:
        // 4 炸弹
        playPoker.PokerType, err = poker.bomb(countCard)
        return playPoker, err
    default:
        return playPoker, errors.New("错误的牌")
    }
}

// 最大值是一张牌的判断(重复牌)
func (poker *PlayingCards) countSameCardMaxOne(countCard map[int]int, sortCard []int) (int, error) {
    // 单牌
    if len(poker.Cards) == len(countCard) && len(countCard) == 1 {
        // 单牌,判断是否可以出牌
        return PokerTypeSingle, nil
    }
    _, king := countCard[PokerKing]
    _, bigKing := countCard[PokerBigKing]
    if king && bigKing {
        // 王炸
        return PokerTypeBoomKing, nil
    }
    if err := poker.checkContinuous(sortCard); err != nil {
        return PokerTypeError, err
    }
    if len(sortCard) < 5 {
        // 未达到最小值
        return PokerTypeError, errors.New("未达到5或以上的顺子,不符合规则")
    }
    return PokerTypeShunZi, nil
}

// 最大值是两张牌的判断(重复牌)
func (poker *PlayingCards) countSameCardMaxTwo(countCard map[int]int, sortCard []int) (int, error) {
    count := len(poker.Cards)
    if count/2 != len(countCard) {
        return PokerTypeError, errors.New("错误的牌,存在单张的牌")
    }
    if count == 2 {
        return PokerTypeDouble, nil
    }
    // 判断是否是连队
    if err := poker.checkContinuous(sortCard); err != nil {
        return PokerTypeError, err
    }
    // 至少要用三队才能是连队
    if len(countCard) < 3 {
        return PokerTypeError, errors.New("未达到连队要求,三队及以上")
    }
    return PokerTypeLianDui, nil
}

// 最大值是三张牌的判断(重复牌)
func (poker *PlayingCards) countSameCardMaxThree(countCard map[int]int) (int, error) {
    // 3 三带一 三带2  飞机带
    count := len(poker.Cards)
    if count == 3 {
        // 三 没带
        return PokerTypeThree, nil
    }
    if count == 4 {
        // 三带1
        return PokerTypeThreeBeltsOne, nil
    }
    if count == 5 && len(countCard) == 2 {
        // 三带二
        return PokerTypeThreeBeltsTwo, nil
    }
    sortCard := make([]int, 0)
    for key, value := range countCard {
        if value == 3 {
            sortCard = append(sortCard, key)
        }
    }
    // 飞机带判断,注意极限情况 三带1 那个1 就是四个三个的
    sort.Ints(sortCard)
    if err := poker.checkContinuous(sortCard); err != nil {
        // 极限情况判断,注意一副牌的斗地主不会出现6对带的情况
        // 头尾去除后都要不是连的情况才是失败的情况
        if len(sortCard) == 4 &&
            len(sortCard) == len(countCard) &&
            ((poker.checkContinuous(sortCard[1:]) != nil) ||
                (poker.checkContinuous(sortCard[:3]) != nil)) {
            return PokerTypeFlayBeltsOne, nil
        }
        return PokerTypeError, err
    }
    if len(sortCard) == len(countCard) {
        // 飞机啥也没带
        return PokerTypeFlay, nil
    }
    // 判断带的是否正常
    // 飞机带队
    difference := len(countCard) - len(sortCard)
    if difference == len(sortCard) && count == (len(sortCard)*3+(difference*2)) {
        return PokerTypeFlayBeltsTwo, nil
    }
    // 飞机带单 注意单中有可能是对拆开的,这时候判断牌的数量即可
    if len(poker.Cards) == len(sortCard)*4 {
        return PokerTypeFlayBeltsOne, nil
    }
    return PokerTypeError, errors.New("未知的牌类型,不允许的牌规则")
}

// 炸弹
func (poker *PlayingCards) bomb(countCard map[int]int) (int, error) {
    count := len(poker.Cards)
    if count == 4 {
        // 炸弹
        return PokerTypeBoom, nil
    }
    if count%2 != 0 || len(countCard) > 3 {
        return PokerTypeError, errors.New("错误的带牌")
    }
    if count == 6 {
        // 4 带 二 连张单 或者一个队都是 算为两张单
        return PokerTypeBoomBeltsOne, nil
    }
    // count == 8  四带两对
    return PokerTypeBoomBeltsTwo, nil
}

// 判断牌是否连续
func (poker *PlayingCards) checkContinuous(sortCard []int) error {
    tmp := 0
    for _, value := range sortCard {
        if value >= 13 {
            // 失败,有大于A的牌
            return errors.New("不合理的牌,存在大于A的牌")
        }
        if tmp == 0 {
            tmp = value
            continue
        }
        if value-1 == tmp {
            // 正常
            tmp = value
            continue
        }
        return errors.New("不合理的牌,非连续的牌")
    }
    return nil
}

// 创建扑克牌
func CreatePoker() (*OneDeckOfCards, error) {
    // 扑克的大小
    pokerNumbers := map[string]int{"3": 1, "4": 2, "5": 3, "6": 4, "7": 5, "8": 6, "9": 7, "10": 8, "J": 9, "Q": 10, "K": 11, "A": 12, "2": 13, "小王": 14, "大王": 15}
    // 扑克的花色,注意王的红比黑的大
    pokerColor := map[string]int{"黑桃": 1, "红桃": 2, "方块": 3, "梅花": 4}
    number := 1
    pokers := OneDeckOfCards{
        Intact:  make(map[int]*Card, PokerNumbers),
        Discard: make(map[int]*Card, PokerNumbers),
    }
    for key, value := range pokerNumbers {
        for k, v := range pokerColor {
            if value > 13 && v >= 2 {
                break
            }
            pokers.Intact[number] = &Card{
                Name:    key,
                Number:  number,
                Current: number,
                Color:   k,
                Size:    value,
            }
            number++
        }
    }
    return &pokers, nil
}

// 随机洗牌 Fisher–Yates
func (poker *OneDeckOfCards) ShuffleToPoker() {
    for key, value := range poker.Intact {
        // 获取随机数,通过取余的方法让其落在范围内
        // 交换目标位置和当前位置的值
        current := (rand.Int()) % PokerTotal
        if current == 0 {
            continue
        }
        // 洗牌后需要把编号也修改一下,方便记牌器和后面的判断牌是否被打出去的时候使用
        value.Current = current
        poker.Intact[key] = poker.Intact[current]
        poker.Intact[key].Current = key
        poker.Intact[current] = value
    }
    return
}

测试代码,测试牌型的判断

package main

import (
    "log"
    "testing"
)

func TestOneDeckOfCards_CheckType(t *testing.T) {
    // 创建一副牌,取前10张
    cards, _ := CreatePoker()
    cards.ShuffleToPoker()
    play := &PlayingCards{
        Cards: make([]Card, 10),
    }
    i := 0
    for _, value := range cards.Intact {
        if i > 9 {
            break
        }
        play.Cards[i] = *value
        i++
    }
    play.CheckType()
}

// 判断牌型
func TestPlayingCards_CheckType(t *testing.T) {
    var play PlayingCards
    play = PlayingCards{Cards: make([]Card, 1)}
    play.Cards[0] = Card{Name: "4", Number: 8, Current: 15, Color: "黑桃", Size: 2}
    log.Println(play.CheckType()) // 1 <nil> 单牌

    play = PlayingCards{Cards: make([]Card, 2)}
    play.Cards[0] = Card{Name: "3", Number: 8, Current: 15, Color: "黑桃", Size: 1}
    play.Cards[1] = Card{Name: "3", Number: 9, Current: 20, Color: "红桃", Size: 1}
    log.Println(play.CheckType()) // 2 <nil>  对子

    play = PlayingCards{Cards: make([]Card, 3)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 9, Current: 21, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 10, Current: 22, Color: "梅花", Size: 3}
    log.Println(play.CheckType()) // 3 <nil>

    play = PlayingCards{Cards: make([]Card, 4)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 9, Current: 21, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 10, Current: 22, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "9", Number: 25, Current: 26, Color: "梅花", Size: 7}
    log.Println(play.CheckType()) // 4 <nil>

    play = PlayingCards{Cards: make([]Card, 5)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 9, Current: 21, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 10, Current: 22, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "9", Number: 25, Current: 26, Color: "梅花", Size: 7}
    play.Cards[4] = Card{Name: "9", Number: 27, Current: 30, Color: "黑桃", Size: 7}
    log.Println(play.CheckType()) // 5 <nil>

    play = PlayingCards{Cards: make([]Card, 5)}
    play.Cards[0] = Card{Name: "3", Number: 8, Current: 15, Color: "黑桃", Size: 1}
    play.Cards[1] = Card{Name: "4", Number: 9, Current: 21, Color: "红桃", Size: 2}
    play.Cards[2] = Card{Name: "5", Number: 10, Current: 22, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 25, Current: 26, Color: "梅花", Size: 4}
    play.Cards[4] = Card{Name: "7", Number: 27, Current: 30, Color: "黑桃", Size: 5}
    log.Println(play.CheckType()) // 6 <nil>

    play = PlayingCards{Cards: make([]Card, 6)}
    play.Cards[0] = Card{Name: "10", Number: 8, Current: 15, Color: "黑桃", Size: 8}
    play.Cards[5] = Card{Name: "2", Number: 7, Current: 12, Color: "黑桃", Size: 13}
    play.Cards[1] = Card{Name: "J", Number: 9, Current: 21, Color: "红桃", Size: 9}
    play.Cards[2] = Card{Name: "Q", Number: 10, Current: 22, Color: "梅花", Size: 10}
    play.Cards[3] = Card{Name: "K", Number: 25, Current: 26, Color: "梅花", Size: 11}
    play.Cards[4] = Card{Name: "A", Number: 27, Current: 30, Color: "黑桃", Size: 12}
    log.Println(play.CheckType()) // -1 不合理的牌,存在大于A的牌

    play = PlayingCards{Cards: make([]Card, 4)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "6", Number: 9, Current: 21, Color: "红桃", Size: 4}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "梅花", Size: 4}
    log.Println(play.CheckType()) // -1 未达到连队要求,三队及以上

    play = PlayingCards{Cards: make([]Card, 6)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "6", Number: 9, Current: 21, Color: "红桃", Size: 4}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "梅花", Size: 4}
    play.Cards[4] = Card{Name: "7", Number: 12, Current: 25, Color: "红桃", Size: 5}
    play.Cards[5] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    log.Println(play.CheckType()) // 7 <nil>

    play = PlayingCards{Cards: make([]Card, 6)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 9, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "黑桃", Size: 4}
    play.Cards[4] = Card{Name: "6", Number: 12, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 15, Current: 30, Color: "梅花", Size: 4}
    log.Println(play.CheckType()) // 8 <nil>

    play = PlayingCards{Cards: make([]Card, 12)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 9, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "黑桃", Size: 4}
    play.Cards[4] = Card{Name: "6", Number: 12, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 15, Current: 30, Color: "梅花", Size: 4}
    play.Cards[6] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[7] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[8] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[9] = Card{Name: "8", Number: 15, Current: 30, Color: "梅花", Size: 6}
    play.Cards[10] = Card{Name: "8", Number: 15, Current: 30, Color: "梅花", Size: 6}
    play.Cards[11] = Card{Name: "8", Number: 15, Current: 30, Color: "梅花", Size: 6}
    log.Println(play.CheckType()) // 8 <nil>

    play = PlayingCards{Cards: make([]Card, 12)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 9, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "黑桃", Size: 4}
    play.Cards[4] = Card{Name: "6", Number: 12, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 15, Current: 30, Color: "梅花", Size: 4}
    play.Cards[6] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[7] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[8] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[9] = Card{Name: "10", Number: 15, Current: 30, Color: "梅花", Size: 8}
    play.Cards[10] = Card{Name: "10", Number: 15, Current: 30, Color: "梅花", Size: 8}
    play.Cards[11] = Card{Name: "10", Number: 15, Current: 30, Color: "梅花", Size: 8}
    log.Println(play.CheckType()) // 9 <nil>

    play = PlayingCards{Cards: make([]Card, 12)}
    play.Cards[0] = Card{Name: "5", Number: 8, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 7, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 9, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 10, Current: 22, Color: "黑桃", Size: 4}
    play.Cards[4] = Card{Name: "6", Number: 12, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 15, Current: 30, Color: "梅花", Size: 4}
    play.Cards[6] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[7] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[8] = Card{Name: "7", Number: 15, Current: 30, Color: "梅花", Size: 5}
    play.Cards[9] = Card{Name: "J", Number: 15, Current: 30, Color: "梅花", Size: 9}
    play.Cards[10] = Card{Name: "K", Number: 15, Current: 30, Color: "梅花", Size: 11}
    play.Cards[11] = Card{Name: "2", Number: 15, Current: 30, Color: "梅花", Size: 13}
    log.Println(play.CheckType()) // 9 <nil>

    play = PlayingCards{Cards: make([]Card, 10)}
    play.Cards[0] = Card{Name: "5", Number: 5, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 6, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 7, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "6", Number: 8, Current: 22, Color: "黑桃", Size: 4}
    play.Cards[4] = Card{Name: "6", Number: 9, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 10, Current: 26, Color: "梅花", Size: 4}
    play.Cards[6] = Card{Name: "7", Number: 11, Current: 27, Color: "梅花", Size: 5}
    play.Cards[7] = Card{Name: "7", Number: 12, Current: 28, Color: "梅花", Size: 5}
    play.Cards[8] = Card{Name: "K", Number: 13, Current: 29, Color: "梅花", Size: 11}
    play.Cards[9] = Card{Name: "K", Number: 15, Current: 30, Color: "梅花", Size: 11}
    log.Println(play.CheckType()) // 10 <nil>

    play = PlayingCards{Cards: make([]Card, 6)}
    play.Cards[0] = Card{Name: "5", Number: 5, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 6, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 7, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "5", Number: 8, Current: 22, Color: "黑桃", Size: 3}
    play.Cards[4] = Card{Name: "6", Number: 9, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 10, Current: 26, Color: "梅花", Size: 4}
    log.Println(play.CheckType()) // 11 <nil>

    play = PlayingCards{Cards: make([]Card, 6)}
    play.Cards[0] = Card{Name: "5", Number: 5, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 6, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 7, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "5", Number: 8, Current: 22, Color: "黑桃", Size: 3}
    play.Cards[4] = Card{Name: "6", Number: 9, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "7", Number: 10, Current: 26, Color: "梅花", Size: 5}
    log.Println(play.CheckType()) // 11 <nil>

    play = PlayingCards{Cards: make([]Card, 8)}
    play.Cards[0] = Card{Name: "5", Number: 5, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 6, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 7, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "5", Number: 8, Current: 22, Color: "黑桃", Size: 3}
    play.Cards[4] = Card{Name: "6", Number: 9, Current: 25, Color: "红桃", Size: 4}
    play.Cards[5] = Card{Name: "6", Number: 10, Current: 26, Color: "梅花", Size: 4}
    play.Cards[6] = Card{Name: "9", Number: 10, Current: 26, Color: "梅花", Size: 7}
    play.Cards[7] = Card{Name: "9", Number: 10, Current: 26, Color: "梅花", Size: 7}
    log.Println(play.CheckType()) // 12 <nil>

    play = PlayingCards{Cards: make([]Card, 4)}
    play.Cards[0] = Card{Name: "5", Number: 5, Current: 15, Color: "黑桃", Size: 3}
    play.Cards[1] = Card{Name: "5", Number: 6, Current: 12, Color: "红桃", Size: 3}
    play.Cards[2] = Card{Name: "5", Number: 7, Current: 21, Color: "梅花", Size: 3}
    play.Cards[3] = Card{Name: "5", Number: 8, Current: 22, Color: "黑桃", Size: 3}
    log.Println(play.CheckType()) // 13 <nil>

    play = PlayingCards{Cards: make([]Card, 2)}
    play.Cards[0] = Card{Name: "小王", Number: 5, Current: 15, Color: "黑桃", Size: 14}
    play.Cards[1] = Card{Name: "大王", Number: 6, Current: 12, Color: "红桃", Size: 15}
    log.Println(play.CheckType()) // 99 <nil>

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,898评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,401评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,058评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,539评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,382评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,319评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,706评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,370评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,664评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,715评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,476评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,326评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,730评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,003评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,275评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,683评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,877评论 2 335

推荐阅读更多精彩内容

  • 斗地主的深度学习方案 原论文出处:https://openreview.net/pdf?id=rJzoujRct7...
    歌莫信息阅读 6,846评论 3 4
  • 设计目标 要取得良好效果,首先要搞清楚一个问题:我们想得到一个什么样的斗地主AI?我们的AI是用在手游产品当中,在...
    longhuihu阅读 12,033评论 5 4
  • 两人斗地主 一、体系结构图 通讯模型 大功能模块切换关系 二、逻辑流程图 登录login.PNG 主页面开始界面....
    wuyumumu阅读 486评论 0 0
  • 专业考题类型管理运行工作负责人一般作业考题内容选项A选项B选项C选项D选项E选项F正确答案 变电单选GYSZ本规程...
    小白兔去钓鱼阅读 8,953评论 0 13
  • 是谁洒下那热情的汗水,走向梦的彼岸? 是谁迷恋这途中的玫瑰,逗留一地余欢? 也许来日的悲欢并非今日注定,但满眼泪花...
    醉红颜倾南城阅读 413评论 0 4