poker

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package poker 提供了一组用于处理扑克牌游戏的函数和数据结构。该包旨在简化扑克牌游戏的开发过程,并提供一致的接口和易于使用的功能。

主要特性:

  • 扑克牌操作:"poker"包支持处理扑克牌的各种操作,如洗牌、发牌、比较牌面大小等。您可以使用这些操作来模拟和实现各种扑克牌游戏。
  • 扑克牌规则:该包提供了一系列函数,用于执行常见的扑克牌规则,如判断是否是同花顺、计算牌面点数等。这些函数旨在提供准确和可靠的规则判断和计算结果。
  • 扑克牌算法:"poker"包还提供了一些算法,用于解决扑克牌游戏中的问题,如计算最佳牌型、判断是否存在顺子等。这些算法旨在提供高效和优化的解决方案。
  • 简化接口:该包的设计目标之一是提供简化的接口,使扑克牌游戏的开发变得更加直观和易于使用。您可以轻松地创建和操作扑克牌对象,而无需处理繁琐的底层细节。

Deprecated: 从 Minotaur 0.0.25 开始,由于设计原因已弃用,请尝试考虑使用 utils/combination 和 utils/deck 代替

Index

Constants

View Source
const (
	HandNone = "None" // 无牌型
)

Variables

This section is empty.

Functions

func ColorDifference added in v0.0.20

func ColorDifference[P, C generic.Number, T Card[P, C]](card1 T, card2 T) int

ColorDifference 计算两张扑克牌的花色差

func Equal added in v0.0.20

func Equal[P, C generic.Number, T Card[P, C]](card1 T, card2 T) bool

Equal 比较两张扑克牌的点数和花色是否相同

func EqualColor added in v0.0.20

func EqualColor[P, C generic.Number, T Card[P, C]](card1 T, card2 T) bool

EqualColor 比较两张扑克牌的花色是否相同

func EqualPoint added in v0.0.20

func EqualPoint[P, C generic.Number, T Card[P, C]](card1 T, card2 T) bool

EqualPoint 比较两张扑克牌的点数是否相同

func GetCardsColor

func GetCardsColor[P, C generic.Number, T Card[P, C]](cards ...T) []C

GetCardsColor 获取一组扑克牌的花色

func GetCardsPoint

func GetCardsPoint[P, C generic.Number, T Card[P, C]](cards ...T) []P

GetCardsPoint 获取一组扑克牌的点数

func GetPointAndColor added in v0.0.20

func GetPointAndColor[P, C generic.Number, T Card[P, C]](card T) (P, C)

GetPointAndColor 返回扑克牌的点数和花色

func GroupByColor added in v0.0.3

func GroupByColor[P, C generic.Number, T Card[P, C]](cards ...T) map[C][]T

GroupByColor 将扑克牌按照花色分组

func GroupByPoint added in v0.0.3

func GroupByPoint[P, C generic.Number, T Card[P, C]](cards ...T) map[P][]T

GroupByPoint 将扑克牌按照点数分组

func IsContain added in v0.0.20

func IsContain[P, C generic.Number, T Card[P, C]](cards []T, card T) bool

IsContain 一组扑克牌是否包含某张牌

func IsContainAll added in v0.0.20

func IsContainAll[P, C generic.Number, T Card[P, C]](cards []T, cards2 []T) bool

IsContainAll 一组扑克牌是否包含另一组扑克牌

func IsContainJoker added in v0.0.3

func IsContainJoker[P, C generic.Number, T Card[P, C]](pile *CardPile[P, C, T], cards ...T) bool

IsContainJoker 检查扑克牌是否包含大小王

func IsFlush added in v0.0.3

func IsFlush[P, C generic.Number, T Card[P, C]](cards ...T) bool

IsFlush 判断是否是同花

func IsJoker added in v0.0.20

func IsJoker[P, C generic.Number, T Card[P, C]](pile *CardPile[P, C, T], card T) bool

IsJoker 判断扑克牌是否为大小王

func IsNeighborColor added in v0.0.20

func IsNeighborColor[P, C generic.Number, T Card[P, C]](card1 T, card2 T) bool

IsNeighborColor 判断两张扑克牌是否为相邻的花色

func IsNeighborPoint added in v0.0.20

func IsNeighborPoint[P, C generic.Number, T Card[P, C]](card1 T, card2 T) bool

IsNeighborPoint 判断两张扑克牌是否为相邻的点数

func IsRocket added in v0.0.3

func IsRocket[P, C generic.Number, T Card[P, C]](pile *CardPile[P, C, T], cardA, cardB T) bool

IsRocket 两张牌能否组成红黑 Joker

func Max added in v0.0.20

func Max[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

Max 返回两张扑克牌中点数和花色较大的一张

func MaxColor added in v0.0.20

func MaxColor[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

MaxColor 返回两张扑克牌中花色较大的一张

func MaxPoint added in v0.0.20

func MaxPoint[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

MaxPoint 返回两张扑克牌中点数较大的一张

func Min added in v0.0.20

func Min[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

Min 返回两张扑克牌中点数和花色较小的一张

func MinColor added in v0.0.20

func MinColor[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

MinColor 返回两张扑克牌中花色较小的一张

func MinPoint added in v0.0.20

func MinPoint[P, C generic.Number, T Card[P, C]](card1 T, card2 T) T

MinPoint 返回两张扑克牌中点数较小的一张

func PointDifference added in v0.0.20

func PointDifference[P, C generic.Number, T Card[P, C]](card1 T, card2 T) int

PointDifference 计算两张扑克牌的点数差

Types

type Card

type Card[P, C generic.Number] interface {
	// GetGuid 获取扑克牌的唯一标识
	GetGuid() int64
	// GetPoint 获取扑克牌的点数
	GetPoint() P
	// GetColor 获取扑克牌的花色
	GetColor() C
}

Card 扑克牌

type CardPile

type CardPile[P, C generic.Number, T Card[P, C]] struct {
	// contains filtered or unexported fields
}

CardPile 扑克牌堆

func NewCardPile deprecated

func NewCardPile[P, C generic.Number, T Card[P, C]](size int, jokers [2]P, points [13]P, colors [4]C, generateCard func(guid int64, point P, color C) T, options ...CardPileOption[P, C, T]) *CardPile[P, C, T]

NewCardPile 返回一个新的牌堆,其中 size 表示了该牌堆由多少副牌组成

  • 在不洗牌的情况下,默认牌堆顶部到底部为从大到小排列

Deprecated: 从 Minotaur 0.0.25 开始,由于设计原因已弃用,请尝试考虑使用 deck.Deck 或 deck.Group 代替,构建函数为 deck.NewDeck 或 deck.NewGroup

func (*CardPile[P, C, T]) Cards

func (slf *CardPile[P, C, T]) Cards() []T

Cards 获取当前牌堆的所有扑克牌

func (*CardPile[P, C, T]) Count

func (slf *CardPile[P, C, T]) Count() int

Count 获取牌堆剩余牌量

func (*CardPile[P, C, T]) GetCard added in v0.0.20

func (slf *CardPile[P, C, T]) GetCard(guid int64) T

GetCard 通过 guid 获取一张牌

func (*CardPile[P, C, T]) IsExclude

func (slf *CardPile[P, C, T]) IsExclude(point P, color C) bool

IsExclude 检查特定点数和花色是否被排除在外

func (*CardPile[P, C, T]) IsExcludeWithCard

func (slf *CardPile[P, C, T]) IsExcludeWithCard(card T) bool

IsExcludeWithCard 检查特定扑克牌是否被排除在外

func (*CardPile[P, C, T]) IsFree

func (slf *CardPile[P, C, T]) IsFree() bool

IsFree 返回牌堆是否没有扑克牌了

func (*CardPile[P, C, T]) Pull

func (slf *CardPile[P, C, T]) Pull(index int) T

Pull 从牌堆特定位置抽出一张牌

func (*CardPile[P, C, T]) PullBottom

func (slf *CardPile[P, C, T]) PullBottom() T

PullBottom 从牌堆底部抽出一张牌

func (*CardPile[P, C, T]) PullTop

func (slf *CardPile[P, C, T]) PullTop() T

PullTop 从牌堆顶部抽出一张牌

func (*CardPile[P, C, T]) Push

func (slf *CardPile[P, C, T]) Push(index int, card T)

Push 将扑克牌插入到牌堆特定位置

func (*CardPile[P, C, T]) PushBottom

func (slf *CardPile[P, C, T]) PushBottom(card T)

PushBottom 将扑克牌插入到牌堆底部

func (*CardPile[P, C, T]) PushTop

func (slf *CardPile[P, C, T]) PushTop(card T)

PushTop 将扑克牌插入到牌堆顶部

func (*CardPile[P, C, T]) Reset

func (slf *CardPile[P, C, T]) Reset()

Reset 重置牌堆的扑克牌数量及顺序

func (*CardPile[P, C, T]) Shuffle

func (slf *CardPile[P, C, T]) Shuffle()

Shuffle 洗牌

type CardPileOption

type CardPileOption[P, C generic.Number, T Card[P, C]] func(pile *CardPile[P, C, T])

func WithCardPileExcludeCard

func WithCardPileExcludeCard[P, C generic.Number, T Card[P, C]](cards ...Card[P, C]) CardPileOption[P, C, T]

WithCardPileExcludeCard 通过排除特定扑克牌的方式创建牌堆

func WithCardPileExcludeColor

func WithCardPileExcludeColor[P, C generic.Number, T Card[P, C]](colors ...C) CardPileOption[P, C, T]

WithCardPileExcludeColor 通过排除特定花色的方式创建牌堆

func WithCardPileExcludePoint

func WithCardPileExcludePoint[P, C generic.Number, T Card[P, C]](points ...P) CardPileOption[P, C, T]

WithCardPileExcludePoint 通过排除特定点数的方式创建牌堆

func WithCardPileShuffle

func WithCardPileShuffle[P, C generic.Number, T Card[P, C]](shuffleHandle func(pile []T) []T) CardPileOption[P, C, T]

WithCardPileShuffle 通过特定的洗牌算法创建牌堆

  • 需要保证洗牌后的牌堆剩余扑克数量与之前相同,否则将会引发 panic

type HandHandle

type HandHandle[P, C generic.Number, T Card[P, C]] func(rule *Rule[P, C, T], cards []T) bool

HandHandle 扑克牌型验证函数

func HandBomb added in v0.0.3

func HandBomb[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandBomb 炸弹

func HandFlush added in v0.0.3

func HandFlush[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandFlush 同花

  • 表示所有牌的花色都相同

func HandFlushStraight added in v0.0.3

func HandFlushStraight[P, C generic.Number, T Card[P, C]](count, lower, limit int) HandHandle[P, C, T]

HandFlushStraight 同花顺

  • count: 顺子的对子数量,例如当 count = 2 时,可以是 334455、445566、556677、667788、778899
  • lower: 顺子的最小连续数量
  • limit: 顺子的最大连续数量

func HandFourWithOne added in v0.0.3

func HandFourWithOne[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandFourWithOne 四带一

func HandFourWithThree added in v0.0.3

func HandFourWithThree[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandFourWithThree 四带三

func HandFourWithTwo added in v0.0.3

func HandFourWithTwo[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandFourWithTwo 四带二

func HandFourWithTwoPairs added in v0.0.3

func HandFourWithTwoPairs[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandFourWithTwoPairs 四带两对

func HandLeopard added in v0.0.3

func HandLeopard[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandLeopard 豹子

  • 表示三张点数相同的牌
  • 例如:333、444、555、666、777、888、999、JJJ、QQQ、KKK、AAA
  • 大小王不能用于豹子,因为他们没有点数

func HandOrderFourWithOne added in v0.0.3

func HandOrderFourWithOne[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderFourWithOne 四带一顺子

func HandOrderFourWithThree added in v0.0.3

func HandOrderFourWithThree[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderFourWithThree 四带三顺子

func HandOrderFourWithTwo added in v0.0.3

func HandOrderFourWithTwo[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderFourWithTwo 四带二顺子

func HandOrderPairs added in v0.0.3

func HandOrderPairs[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderPairs 对子顺子

func HandOrderSingle added in v0.0.3

func HandOrderSingle[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderSingle 顺子

func HandOrderSingleFour added in v0.0.3

func HandOrderSingleFour[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderSingleFour 四张顺子

func HandOrderSingleThree added in v0.0.3

func HandOrderSingleThree[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderSingleThree 三张顺子

func HandOrderThreeWithOne added in v0.0.3

func HandOrderThreeWithOne[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderThreeWithOne 三带一顺子

func HandOrderThreeWithTwo added in v0.0.3

func HandOrderThreeWithTwo[P, C generic.Number, T Card[P, C]](count int) HandHandle[P, C, T]

HandOrderThreeWithTwo 三带二顺子

func HandPairs

func HandPairs[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandPairs 对子

func HandPlane added in v0.0.3

func HandPlane[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandPlane 飞机

  • 表示三张点数相同的牌组成的连续的牌

func HandPlaneWithOne added in v0.0.3

func HandPlaneWithOne[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandPlaneWithOne 飞机带单

func HandRocket added in v0.0.3

func HandRocket[P, C generic.Number, T Card[P, C]](pile *CardPile[P, C, T]) HandHandle[P, C, T]

HandRocket 王炸

  • 表示一对王牌,即大王和小王

func HandSingle

func HandSingle[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandSingle 单牌

func HandStraightPairs added in v0.0.3

func HandStraightPairs[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandStraightPairs 连对

func HandThreeOfKind

func HandThreeOfKind[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandThreeOfKind 三张

func HandThreeOfKindWithOne added in v0.0.3

func HandThreeOfKindWithOne[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandThreeOfKindWithOne 三带一

func HandThreeOfKindWithTwo added in v0.0.3

func HandThreeOfKindWithTwo[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandThreeOfKindWithTwo 三带二

func HandTwoWithOne added in v0.0.3

func HandTwoWithOne[P, C generic.Number, T Card[P, C]]() HandHandle[P, C, T]

HandTwoWithOne 二带一

  • 表示两张点数相同的牌,加上一张其他点数的牌
  • 例如:334、445、556、667、778、889、99J、TTQ、JJK、QQA、AA2
  • 大小王不能用于二带一,因为他们没有点数
  • 通常用于炸金花玩法中检查对子

type Option

type Option[P, C generic.Number, T Card[P, C]] func(rule *Rule[P, C, T])

func WithColorSort added in v0.0.3

func WithColorSort[P, C generic.Number, T Card[P, C]](colorSort map[C]int) Option[P, C, T]

WithColorSort 通过特定的扑克花色顺序创建扑克玩法,顺序必须为连续的

func WithColorValue

func WithColorValue[P, C generic.Number, T Card[P, C]](colorValues map[C]int) Option[P, C, T]

WithColorValue 通过特定的扑克花色牌值创建扑克玩法

func WithExcludeContinuityPoint added in v0.0.3

func WithExcludeContinuityPoint[P, C generic.Number, T Card[P, C]](points ...P) Option[P, C, T]

WithExcludeContinuityPoint 排除连续的点数

func WithHand

func WithHand[P, C generic.Number, T Card[P, C]](pokerHand string, value int, handle HandHandle[P, C, T]) Option[P, C, T]

WithHand 通过绑定特定牌型的方式创建扑克玩法

  • 牌型顺序决定了牌型的优先级

func WithHandRestraint added in v0.0.3

func WithHandRestraint[P, C generic.Number, T Card[P, C]](pokerHand, restraint string) Option[P, C, T]

WithHandRestraint 通过绑定特定克制牌型的方式创建扑克玩法

func WithHandRestraintFull added in v0.0.3

func WithHandRestraintFull[P, C generic.Number, T Card[P, C]](pokerHand string) Option[P, C, T]

WithHandRestraintFull 通过绑定所有克制牌型的方式创建扑克玩法

  • 需要确保在牌型声明之后调用

func WithPointSort

func WithPointSort[P, C generic.Number, T Card[P, C]](pointSort map[P]int) Option[P, C, T]

WithPointSort 通过特定的扑克点数顺序创建扑克玩法,顺序必须为连续的

func WithPointValue

func WithPointValue[P, C generic.Number, T Card[P, C]](pointValues map[P]int) Option[P, C, T]

WithPointValue 通过特定的扑克点数牌值创建扑克玩法

type Rule added in v0.0.3

type Rule[P, C generic.Number, T Card[P, C]] struct {
	// contains filtered or unexported fields
}

func NewRule deprecated added in v0.0.3

func NewRule[P, C generic.Number, T Card[P, C]](options ...Option[P, C, T]) *Rule[P, C, T]

Deprecated: 从 Minotaur 0.0.25 开始,由于设计原因已弃用,请尝试考虑使用 combination.Combination、combination.Matcher、combination.Validator 代替

func (*Rule[P, C, T]) CompareValueWithCards added in v0.0.3

func (slf *Rule[P, C, T]) CompareValueWithCards(cards1 []T, expression maths.CompareExpression, cards2 []T) bool

CompareValueWithCards 根据特定的条件表达式比较两组扑克牌的牌值

func (*Rule[P, C, T]) GetCardCount added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCount(cards []T, card T) int

GetCardCount 获取指定牌的数量

func (*Rule[P, C, T]) GetCardCountWithColor added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCountWithColor(cards []T, color C) int

GetCardCountWithColor 获取指定花色的牌的数量

func (*Rule[P, C, T]) GetCardCountWithColorMaximumNumber added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCountWithColorMaximumNumber(cards []T, color C, maximumNumber int) int

GetCardCountWithColorMaximumNumber 获取指定花色的牌的数量

func (*Rule[P, C, T]) GetCardCountWithMaximumNumber added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCountWithMaximumNumber(cards []T, card T, maximumNumber int) int

GetCardCountWithMaximumNumber 获取指定牌的数量

func (*Rule[P, C, T]) GetCardCountWithPoint added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCountWithPoint(cards []T, point P) int

GetCardCountWithPoint 获取指定点数的牌的数量

func (*Rule[P, C, T]) GetCardCountWithPointMaximumNumber added in v0.0.4

func (slf *Rule[P, C, T]) GetCardCountWithPointMaximumNumber(cards []T, point P, maximumNumber int) int

GetCardCountWithPointMaximumNumber 获取指定点数的牌的数量

func (*Rule[P, C, T]) GetValueWithCards added in v0.0.3

func (slf *Rule[P, C, T]) GetValueWithCards(cards ...T) int

GetValueWithCards 获取扑克牌的牌值

func (*Rule[P, C, T]) GetValueWithColor added in v0.0.3

func (slf *Rule[P, C, T]) GetValueWithColor(color C) int

GetValueWithColor 获取扑克牌的花色牌值

func (*Rule[P, C, T]) GetValueWithPoint added in v0.0.3

func (slf *Rule[P, C, T]) GetValueWithPoint(point P) int

GetValueWithPoint 获取扑克牌的点数牌值

func (*Rule[P, C, T]) GetValueWithPokerHand added in v0.0.3

func (slf *Rule[P, C, T]) GetValueWithPokerHand(hand string, cards ...T) int

GetValueWithPokerHand 获取扑克牌的牌型牌值

func (*Rule[P, C, T]) IsPointContinuity added in v0.0.3

func (slf *Rule[P, C, T]) IsPointContinuity(count int, cards ...T) bool

IsPointContinuity 检查一组扑克牌点数是否连续,count 表示了每个点数的数量

func (*Rule[P, C, T]) IsSameColor added in v0.0.3

func (slf *Rule[P, C, T]) IsSameColor(cards ...T) bool

IsSameColor 检查一组扑克牌是否同花

func (*Rule[P, C, T]) IsSamePoint added in v0.0.3

func (slf *Rule[P, C, T]) IsSamePoint(cards ...T) bool

IsSamePoint 检查一组扑克牌是否同点

func (*Rule[P, C, T]) PokerHand added in v0.0.3

func (slf *Rule[P, C, T]) PokerHand(cards ...T) (pokerHand string, hit bool)

PokerHand 获取一组扑克的牌型

func (*Rule[P, C, T]) PokerHandIsMatch added in v0.0.3

func (slf *Rule[P, C, T]) PokerHandIsMatch(cardsA, cardsB []T) bool

PokerHandIsMatch 检查两组扑克牌牌型是否匹配

func (*Rule[P, C, T]) SortByColorAsc added in v0.0.3

func (slf *Rule[P, C, T]) SortByColorAsc(cards []T) []T

SortByColorAsc 将扑克牌按照花色从小到大排序

func (*Rule[P, C, T]) SortByColorDesc added in v0.0.3

func (slf *Rule[P, C, T]) SortByColorDesc(cards []T) []T

SortByColorDesc 将扑克牌按照花色从大到小排序

func (*Rule[P, C, T]) SortByPointAsc added in v0.0.3

func (slf *Rule[P, C, T]) SortByPointAsc(cards []T) []T

SortByPointAsc 将扑克牌按照点数从小到大排序

func (*Rule[P, C, T]) SortByPointDesc added in v0.0.3

func (slf *Rule[P, C, T]) SortByPointDesc(cards []T) []T

SortByPointDesc 将扑克牌按照点数从大到小排序

Jump to

Keyboard shortcuts

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