斗地主,服務(wù)端代碼

斗地主服務(wù)端的主要邏輯

出牌判斷

package main

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

// 簡單的斗地主程序

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

// 單張牌的結(jié)構(gòu)
type Card struct {
    Name     string // 撲克牌的名稱
    Number   int    // 這張牌在這負(fù)牌創(chuàng)建時的位置
    Current  int    // 在當(dāng)前牌中的位置
    Color    string // 這張牌的花色
    Size     int    // 這張牌對應(yīng)的大小
    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  // 飛機(jī)666777888
    PokerTypeFlayBeltsOne  = 9  // 飛機(jī)帶單
    PokerTypeFlayBeltsTwo  = 10 // 飛機(jī)帶隊
    PokerTypeBoomBeltsOne  = 11 // 炸彈帶單張,兩個單張或者一個對子
    PokerTypeBoomBeltsTwo  = 12 // 炸彈帶對子
    PokerTypeBoom          = 13 // 炸彈
    PokerTypeBoomKing      = 99 // 王炸
)

func main() {
    // 創(chuàng)建牌
    cards, _ := CreatePoker()
    // 洗牌
    cards.ShuffleToPoker()
    // 判斷牌的大小

}

// 判斷牌是否合理低飒,順子 三帶一 四帶二
// 判斷牌的類型
func (poker *PlayingCards) CheckType() (*CurrentCards, error) {
    // 對牌進(jìn)行判斷许昨,判斷牌型
    // 單 雙 三 三帶1  三帶2 連對  順子 飛機(jī)(帶1 帶二) 炸彈  王炸
    list := make([]int, len(poker.Cards))
    for key, card := range poker.Cards {
        list[key] = card.Size
    }
    // 對牌進(jìn)行排序,[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  飛機(jī)帶  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  飛機(jī)帶
        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("錯誤的牌")
    }
}

// 最大值是一張牌的判斷(重復(fù)牌)
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 {
        // 未達(dá)到最小值
        return PokerTypeError, errors.New("未達(dá)到5或以上的順子,不符合規(guī)則")
    }
    return PokerTypeShunZi, nil
}

// 最大值是兩張牌的判斷(重復(fù)牌)
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("未達(dá)到連隊要求车要,三隊及以上")
    }
    return PokerTypeLianDui, nil
}

// 最大值是三張牌的判斷(重復(fù)牌)
func (poker *PlayingCards) countSameCardMaxThree(countCard map[int]int) (int, error) {
    // 3 三帶一 三帶2  飛機(jī)帶
    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)
        }
    }
    // 飛機(jī)帶判斷,注意極限情況 三帶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) {
        // 飛機(jī)啥也沒帶
        return PokerTypeFlay, nil
    }
    // 判斷帶的是否正常
    // 飛機(jī)帶隊
    difference := len(countCard) - len(sortCard)
    if difference == len(sortCard) && count == (len(sortCard)*3+(difference*2)) {
        return PokerTypeFlayBeltsTwo, nil
    }
    // 飛機(jī)帶單 注意單中有可能是對拆開的允粤,這時候判斷牌的數(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
}

// 隨機(jī)洗牌 Fisher–Yates
func (poker *OneDeckOfCards) ShuffleToPoker() {
    for key, value := range poker.Intact {
        // 獲取隨機(jī)數(shù)类垫,通過取余的方法讓其落在范圍內(nèi)
        // 交換目標(biāo)位置和當(dāng)前位置的值
        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 未達(dá)到連隊要求悉患,三隊及以上

    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>

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末残家,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子售躁,更是在濱河造成了極大的恐慌坞淮,老刑警劉巖茴晋,帶你破解...
    沈念sama閱讀 217,084評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異回窘,居然都是意外死亡诺擅,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評論 3 392
  • 文/潘曉璐 我一進(jìn)店門啡直,熙熙樓的掌柜王于貴愁眉苦臉地迎上來烁涌,“玉大人,你說我怎么就攤上這事酒觅〈橹矗” “怎么了?”我有些...
    開封第一講書人閱讀 163,450評論 0 353
  • 文/不壞的土叔 我叫張陵舷丹,是天一觀的道長抒钱。 經(jīng)常有香客問我,道長颜凯,這世上最難降的妖魔是什么继效? 我笑而不...
    開封第一講書人閱讀 58,322評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮装获,結(jié)果婚禮上瑞信,老公的妹妹穿的比我還像新娘。我一直安慰自己穴豫,他們只是感情好凡简,可當(dāng)我...
    茶點故事閱讀 67,370評論 6 390
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著精肃,像睡著了一般秤涩。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上司抱,一...
    開封第一講書人閱讀 51,274評論 1 300
  • 那天筐眷,我揣著相機(jī)與錄音,去河邊找鬼习柠。 笑死匀谣,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的资溃。 我是一名探鬼主播武翎,決...
    沈念sama閱讀 40,126評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼溶锭!你這毒婦竟也來了宝恶?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,980評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎垫毙,沒想到半個月后霹疫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,414評論 1 313
  • 正文 獨居荒郊野嶺守林人離奇死亡综芥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,599評論 3 334
  • 正文 我和宋清朗相戀三年更米,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片毫痕。...
    茶點故事閱讀 39,773評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡征峦,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出消请,到底是詐尸還是另有隱情栏笆,我是刑警寧澤,帶...
    沈念sama閱讀 35,470評論 5 344
  • 正文 年R本政府宣布臊泰,位于F島的核電站蛉加,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏缸逃。R本人自食惡果不足惜针饥,卻給世界環(huán)境...
    茶點故事閱讀 41,080評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望需频。 院中可真熱鬧丁眼,春花似錦、人聲如沸昭殉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽挪丢。三九已至蹂风,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間乾蓬,已是汗流浹背惠啄。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留任内,地道東北人撵渡。 一個月前我還...
    沈念sama閱讀 47,865評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像族奢,于是被迫代替她去往敵國和親姥闭。 傳聞我的和親對象是個殘疾皇子丹鸿,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,689評論 2 354

推薦閱讀更多精彩內(nèi)容

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