github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/game/poker/landlordsort.go (about)

     1  package poker
     2  
     3  import "common"
     4  
     5  func ReSortLandlordCards(cards []int) []int {
     6  	cardsType := GetLandlordCardsType(cards)
     7  	switch cardsType {
     8  	// 三带一、三带一对、飞机、飞机带小翼、飞机带大翼、四带两单、四带两对
     9  	case TrioSolo, TrioPair, AirplaneChain, TrioSoloAirplane, TrioPairChain, FourDualsolo, FourDualpair:
    10  		newCards := []int{}
    11  		for _, card := range cards {
    12  			if CountCardValue(cards, card) > 2 {
    13  				newCards = append(newCards, card)
    14  			}
    15  		}
    16  		newCards = append(newCards, common.Remove(cards, newCards)...)
    17  		return newCards
    18  	}
    19  	return cards
    20  }
    21  
    22  func ReSortHint(hintType int, melds [][]int, cards []int) [][]int {
    23  	if len(melds) == 0 {
    24  		return [][]int{}
    25  	}
    26  	cardValueMarker := make(map[int]int)
    27  	for _, card := range cards {
    28  		cardValueMarker[CardValue(card)]++
    29  	}
    30  	newMelds := [][]int{}
    31  	m := make(map[int]bool)
    32  	var count int
    33  	switch hintType {
    34  	case Solo:
    35  		count = 1
    36  	case Pair:
    37  		count = 2
    38  	case Trio, TrioSolo, TrioPair:
    39  		count = 3
    40  	}
    41  NEXT:
    42  	for _, meld := range melds {
    43  		value := CardValue(meld[0])
    44  		if !m[value] && cardValueMarker[value] == count {
    45  			newMelds = append(newMelds, meld)
    46  			m[value] = true
    47  		}
    48  	}
    49  	count++
    50  	if count < 5 {
    51  		goto NEXT
    52  	}
    53  	return newMelds
    54  }