斗地主,服務端代碼

斗地主服務端的主要邏輯

出牌判斷

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    // 這張牌在這負牌創(chuàng)建時的位置
    Current  int    // 在當前牌中的位置
    Color    string // 這張牌的花色
    Size     int    // 這張牌對應的大小
    UsedUser int    // 這張牌是誰打掉的,用于記牌器,防止客戶端篡改牌
}

// 最后一次出牌
type LastCards struct {
    PokerType        int         // 牌型
    CountSameCardMax int         // 便于快速判斷
    SortCard         []int       // 排序后的出牌
    CountCard        map[int]int // 統(tǒng)計的出牌(包含所有的牌)
}

// 單次出牌
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() {
    // 創(chuàng)建牌
    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或以上的順子,不符合規(guī)則")
    }
    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 {
        // 極限情況判斷,注意一副牌的斗地主不會出現(xiàn)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
    }
    // 飛機帶單 注意單中有可能是對拆開的,這時候判斷牌的數(shù)量即可
    if len(poker.Cards) == len(sortCard)*4 {
        return PokerTypeFlayBeltsOne, nil
    }
    return PokerTypeError, errors.New("未知的牌類型,不允許的牌規(guī)則")
}

// 炸彈
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
}

// 判斷牌是否連續(xù)
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("不合理的牌,非連續(xù)的牌")
    }
    return nil
}

// 創(chuàng)建撲克牌
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 {
        // 獲取隨機數(shù),通過取余的方法讓其落在范圍內
        // 交換目標位置和當前位置的值
        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) {
    // 創(chuàng)建一副牌,取前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>

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 斗地主的深度學習方案 原論文出處:https://openreview.net/pdf?id=rJzoujRct7...
    歌莫信息閱讀 7,263評論 3 4
  • 設計目標 要取得良好效果,首先要搞清楚一個問題:我們想得到一個什么樣的斗地主AI?我們的AI是用在手游產品當中,在...
    longhuihu閱讀 12,592評論 5 4
  • 兩人斗地主 一、體系結構圖 通訊模型 大功能模塊切換關系 二、邏輯流程圖 登錄login.PNG 主頁面開始界面....
    wuyumumu閱讀 613評論 0 0
  • 專業(yè)考題類型管理運行工作負責人一般作業(yè)考題內容選項A選項B選項C選項D選項E選項F正確答案 變電單選GYSZ本規(guī)程...
    小白兔去釣魚閱讀 10,582評論 0 13
  • 是誰灑下那熱情的汗水,走向夢的彼岸? 是誰迷戀這途中的玫瑰,逗留一地余歡? 也許來日的悲歡并非今日注定,但滿眼淚花...
    醉紅顏傾南城閱讀 432評論 0 4

友情鏈接更多精彩內容