poker

package
v0.0.0-...-9b1b795 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 4 Imported by: 0

README

poker 牌组封装


ctrl c/v永不过时 !!!

├─cardCombos.go     获取可用牌组,用于游戏中获取可以接或者出的牌
├─cards.go          牌组封装,找牌,出牌,卡牌当前状态等
├─cards_type.go     牌型判断
├─feature.go        特征值的计算
├─laizi.go          设置牌组中的癞子
├─poker.go          牌组封装类
├─shuffle.go        洗牌,支持可以通过牌型出现概率来洗牌内容(避免发出的牌过于零散)
├─value_set.go      牌值计算方式,用于从手牌中找到可用牌型

Documentation

Index

Constants

View Source
const (
	Single         int64 = 1 // 单张
	OnePair        int64 = 2 // 对子
	Trio           int64 = 3 // 三张
	TrioWithSingle int64 = 4 // 三带单
	TrioWithPair   int64 = 5 // 三张带对子

	FourWithTwoSingle int64 = 8 // 四带两张单
	FourWithTwoPair   int64 = 9 // 四带两对

	SingleStraight         int64 = 21 // 单顺
	PairStraight           int64 = 22 // 连对
	TrioStraight           int64 = 23 // 飞机(不带牌)
	TrioStraightWithSingle int64 = 24 // 飞机带单张
	TrioStraightWithPair   int64 = 25 // 飞机带对子

	Bomb     int64 = 41 // 炸弹
	JokePair int64 = 51 // 王炸
)
View Source
const (
	LastUnConf int64 = -100 // 上家出牌不符合(游戏bug)
	Less       int64 = -1   // 出牌比上家小
	UnConf     int64 = 0    // 不符合牌型规则
	Greater    int64 = 1    // 出牌比上家大

	// fix: 1:带有癞子牌,2:混合纯软炸,3:纯癞子,4:默认没有癞子牌
	FixHave  int64 = 1
	FixBlend int64 = 2
	FixAll   int64 = 3
	FixNo    int64 = 4
)

Variables

View Source
var Cards = []int64{31, 32, 33, 34, 41, 42, 43, 44, 51, 52, 53, 54, 61, 62, 63, 64, 71, 72, 73, 74, 81, 82, 83, 84,
	91, 92, 93, 94, 101, 102, 103, 104, 111, 112, 113, 114, 121, 122, 123, 124, 131, 132, 133, 134, 141, 142, 143, 144,
	151, 152, 153, 154, 160, 170}

Functions

This section is empty.

Types

type Card

type Card struct {
	Type    int64 // 牌的类型, 1:方块♦,2:梅花♣,3:红桃♥,4:黑桃♠,5:小王🃏,6:大王🃏
	Value   int64 // 牌的值 小王:160,大王:170
	IsLaizi bool  // 是否癞子牌
	IsUse   bool  // 是否已经使用,复合牌型需要判断牌是否被使用
}

Card 扑克牌对象,牌值 121 方块 Q -> 牌对象(类型 1, 值 12) 支持单张或多张

type CardCombo

type CardCombo struct {
	Feature int64   // 特征
	Cards   []int64 // 具体使用的卡牌
}

CardCombo 列举出可用的牌型组合

type Poker

type Poker struct {
	// contains filtered or unexported fields
}

func NewPokerAlgorithm

func NewPokerAlgorithm() *Poker

func (*Poker) AppendLaizi

func (p *Poker) AppendLaizi(data []int64)

func (*Poker) AutoLaizi

func (p *Poker) AutoLaizi(num int64)

自动生成癞子牌

func (*Poker) CardBinarySearch

func (p *Poker) CardBinarySearch(cards []*Card, target int64) *Card

CardBinarySearch cards的二分查找

func (*Poker) CardToNum

func (p *Poker) CardToNum(cards interface{}) []int64

CardToNum 扑克牌对象转换为数字表示方式的值 cards: 扑克牌对象。可以是单个卡牌对象,也可以是卡牌类型的切片 []*Card return: 扑克牌对象数字表示方式的值,因为可以有多个输入值,所以返回的是一个数组

func (*Poker) CardsAssignPop

func (p *Poker) CardsAssignPop(num []int64) bool

pop指定类型

func (*Poker) CardsAssignValuePop

func (p *Poker) CardsAssignValuePop(num []int64) ([]*Card, bool)

pop指定类型

func (*Poker) CardsGetByValue

func (p *Poker) CardsGetByValue(v int64) []*Card

func (*Poker) CardsPop

func (p *Poker) CardsPop(num int64) []*Card

func (*Poker) CompareFeature

func (p *Poker) CompareFeature(curFeature, lastFeature int64) int64

CompareFeature 比较特征值 curFeature: 要使用牌型组合的特征值 lastFeature: 要对比的特征值 return: 大 (可以出牌) = 1;小 (不能出牌)=-1;牌型不符 = 0

func (*Poker) ContainLaizi

func (p *Poker) ContainLaizi(cards interface{}) int64

包含癞子数量

func (*Poker) DecodeFeature

func (p *Poker) DecodeFeature(feature int64) (int64, int, int64, int64)

DecodeFeature 解析特征值 feature: 特征值 return: 1: 卡牌组合类型;2: 节数;3: 牌值;4:癞子牌

func (*Poker) Disrupt

func (p *Poker) Disrupt(nums []*Card)

牌组打乱

func (*Poker) EncodeFeature

func (p *Poker) EncodeFeature(cardType int64, section int, cardValue int64, fix int64) int64

EncodeFeature 计算特征值 cardType:卡牌组合类型 section: 节数 cardValue: 牌值 fix: 1:带有癞子牌,3:纯癞子,4:默认没有癞子牌

func (*Poker) GetCards

func (p *Poker) GetCards(cards []*Card, target int64, num int) []*Card

GetCards 获取拥有的卡牌

func (*Poker) GetCardsFeature

func (p *Poker) GetCardsFeature(nCards []int64, comboType int64) int64

GetCardsFeature 获取牌型特征值 nCards: 计算牌型的卡牌数据 comboType: 牌的类型 return: 牌型特征值

func (*Poker) GetCardsForLaizi

func (p *Poker) GetCardsForLaizi(cards []*Card, target int64) []*Card

GetCards 获取n张癞子牌

func (*Poker) GetLaizi

func (p *Poker) GetLaizi() []int64

func (*Poker) GetMaxNoJoker

func (p *Poker) GetMaxNoJoker(cards []*Card) int64

func (*Poker) GetMinBomb

func (p *Poker) GetMinBomb(cards []*Card, feature int64, isJoker bool) *cardCombo

GetMinBomb 获取最小的炸弹

func (*Poker) GetMinFourWithTwoPair

func (p *Poker) GetMinFourWithTwoPair(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinFourWithTwoPair 四带两对 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinFourWithTwoSingle

func (p *Poker) GetMinFourWithTwoSingle(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinFourWithTwoSingle 四带单 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinLaizi

func (p *Poker) GetMinLaizi(cards []*Card, num int64) []*Card

GetMinLaizi 获取最小的癞子

func (*Poker) GetMinOnePair

func (p *Poker) GetMinOnePair(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinOnePair 获取对子 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinPairStraight

func (p *Poker) GetMinPairStraight(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinPairStraight 获取连对 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinSingle

func (p *Poker) GetMinSingle(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinSingle 获取单张牌型,优先给出最多只有一张的牌 单张顺序:硬单张、拆一对的硬单张、拆三条的硬单张、硬炸,拆同一硬炸的硬单张、再硬炸,拆同一硬炸的硬单张,

func (*Poker) GetMinSingleStraight

func (p *Poker) GetMinSingleStraight(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinSingleStraight 获取单顺 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrio

func (p *Poker) GetMinTrio(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrio 获取三张组合 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrioStraight

func (p *Poker) GetMinTrioStraight(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrioStraight 飞机不带 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrioStraightWithPair

func (p *Poker) GetMinTrioStraightWithPair(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrioStraightWithPair 飞机带对子 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrioStraightWithSingle

func (p *Poker) GetMinTrioStraightWithSingle(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrioStraightWithSingle 飞机带单牌 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrioWithPair

func (p *Poker) GetMinTrioWithPair(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrioWithPair 获取三带两张组合 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) GetMinTrioWithSingle

func (p *Poker) GetMinTrioWithSingle(cards []*Card, feature int64, bomb, divide, laizi bool) *cardCombo

GetMinTrioWithSingle 获取三张带单组合 cards: 卡牌数据 feature: 调用传入的特征值 bomb:是否使用炸弹,divide:是否拆牌,laizi:是否使用癞子

func (*Poker) HaveJoker

func (p *Poker) HaveJoker(cards []*Card) bool

HaveJoker 拥有王炸

func (*Poker) HintCardCombo

func (p *Poker) HintCardCombo(numCards []int64, feature int64) *CardCombo

HintCardCombo 返回传入的牌中所有可用的牌型组合 numCards: 传入的牌的值 feature: 需要对比的牌的特征值。如果为 0 则表示所有的牌型都可以使用。

func (*Poker) IsLaizi

func (p *Poker) IsLaizi(card int64) bool

func (*Poker) IsUse

func (p *Poker) IsUse(cards []*Card) bool

清楚卡组使用状态

func (*Poker) NumToCard

func (p *Poker) NumToCard(num interface{}) []*Card

NumToCard 牌值转换为卡牌对象 num: 可以是数组,也可以是单张牌的牌值 return: 卡牌对象

func (*Poker) RandomGet

func (p *Poker) RandomGet(nums []*Card, n int) []*Card

从牌组中随机几张牌

func (*Poker) RandomGetDifferent

func (p *Poker) RandomGetDifferent(nums []*Card, n int) []*Card

从牌组中随机几张不相同的牌

func (*Poker) SetLaizi

func (p *Poker) SetLaizi(data []int64)

func (*Poker) ShuffleProbability

func (p *Poker) ShuffleProbability(data [][3]int64)

通过配置牌型出现概率来洗牌 data:牌型出现的概率, 0:牌型,1:出现的概率,2:出现的数量 userNum:游戏人数 handNum:手牌数量

func (*Poker) ShuffleRandom

func (p *Poker) ShuffleRandom()

func (*Poker) SortCards

func (p *Poker) SortCards(cards []*Card)

牌组排序

func (*Poker) StorageBaseCards

func (p *Poker) StorageBaseCards(baseCards []int64)

存储默认手牌

func (*Poker) UnUse

func (p *Poker) UnUse(cards []*Card)

清楚卡组使用状态

func (*Poker) Use

func (p *Poker) Use(cards []*Card, target []*Card)

清楚卡组使用状态

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL