poker

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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

主要特性:

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

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

Card 扑克牌

func NewCard

func NewCard(point Point, color Color) Card

NewCard 创建一张扑克牌

  • 当 point 为 PointBlackJoker 或 PointRedJoker 时,color 将没有效果
Example
package main

import (
	"fmt"
	"github.com/kercylan98/minotaur/game/poker"
)

func main() {
	card := poker.NewCard(poker.PointA, poker.ColorSpade)
	fmt.Println(card)

}
Output:

(A Spade)

func (Card) Equal

func (slf Card) Equal(card Card) bool

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

func (Card) EqualColor

func (slf Card) EqualColor(card Card) bool

EqualColor 比较与另一张扑克牌的花色是否相同

func (Card) EqualPoint

func (slf Card) EqualPoint(card Card) bool

EqualPoint 比较与另一张扑克牌的点数是否相同

func (Card) GetColor

func (slf Card) GetColor() Color

GetColor 返回扑克牌的花色

func (Card) GetPoint

func (slf Card) GetPoint() Point

GetPoint 返回扑克牌的点数

func (Card) GetPointAndColor

func (slf Card) GetPointAndColor() (Point, Color)

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

func (Card) String

func (slf Card) String() string

String 将扑克牌转换为字符串形式

type CardPile

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

CardPile 扑克牌堆

func NewCardPile

func NewCardPile(size int, options ...CardPileOption) *CardPile

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

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

import (
	"fmt"
	"github.com/kercylan98/minotaur/game/poker"
)

func main() {
	var pile = poker.NewCardPile(1,
		poker.WithCardPileExcludeCard(poker.NewCard(poker.PointBlackJoker, poker.ColorNone)),
	)

	fmt.Println(pile.Cards())

}
Output:

[(R None) (K Spade) (K Heart) (K Club) (K Diamond) (Q Spade) (Q Heart) (Q Club) (Q Diamond) (J Spade) (J Heart) (J Club) (J Diamond) (10 Spade) (10 Heart) (10 Club) (10 Diamond) (9 Spade) (9 Heart) (9 Club) (9 Diamond) (8 Spade) (8 Heart) (8 Club) (8 Diamond) (7 Spade) (7 Heart) (7 Club) (7 Diamond) (6 Spade) (6 Heart) (6 Club) (6 Diamond) (5 Spade) (5 Heart) (5 Club) (5 Diamond) (4 Spade) (4 Heart) (4 Club) (4 Diamond) (3 Spade) (3 Heart) (3 Club) (3 Diamond) (2 Spade) (2 Heart) (2 Club) (2 Diamond) (A Spade) (A Heart) (A Club) (A Diamond)]

func (*CardPile) Cards

func (slf *CardPile) Cards() []Card

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

func (*CardPile) Count

func (slf *CardPile) Count() int

Count 获取牌堆剩余牌量

func (*CardPile) IsExclude

func (slf *CardPile) IsExclude(point Point, color Color) bool

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

func (*CardPile) IsExcludeWithCard

func (slf *CardPile) IsExcludeWithCard(card Card) bool

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

func (*CardPile) IsFree

func (slf *CardPile) IsFree() bool

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

func (*CardPile) Pull

func (slf *CardPile) Pull(index int) Card

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

func (*CardPile) PullBottom

func (slf *CardPile) PullBottom() Card

PullBottom 从牌堆底部抽出一张牌

func (*CardPile) PullTop

func (slf *CardPile) PullTop() Card

PullTop 从牌堆顶部抽出一张牌

func (*CardPile) Push

func (slf *CardPile) Push(index int, card Card)

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

func (*CardPile) PushBottom

func (slf *CardPile) PushBottom(card Card)

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

func (*CardPile) PushTop

func (slf *CardPile) PushTop(card Card)

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

func (*CardPile) Reset

func (slf *CardPile) Reset()

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

func (*CardPile) Shuffle

func (slf *CardPile) Shuffle()

Shuffle 洗牌

type CardPileOption

type CardPileOption func(pile *CardPile)

func WithCardPileExcludeCard

func WithCardPileExcludeCard(cards ...Card) CardPileOption

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

func WithCardPileExcludeColor

func WithCardPileExcludeColor(colors ...Color) CardPileOption

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

func WithCardPileExcludePoint

func WithCardPileExcludePoint(points ...Point) CardPileOption

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

func WithCardPileShuffle

func WithCardPileShuffle(shuffleHandle func(pile []Card) []Card) CardPileOption

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

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

type Color

type Color int

Color 扑克牌花色

const (
	ColorNone    Color = 0 // 无花色,通常为大小王
	ColorSpade   Color = 1 // 黑桃
	ColorHeart   Color = 2 // 红桃
	ColorClub    Color = 3 // 梅花
	ColorDiamond Color = 4 // 方片
)

func GetCardsColor

func GetCardsColor(cards ...Card) []Color

GetCardsColor 获取一组扑克牌的花色

func (Color) InBounds

func (slf Color) InBounds() bool

InBounds 扑克牌花色是否在界限内

  • 将检查花色是否在黑桃、红桃、梅花、方片之间

func (Color) String

func (slf Color) String() string

type HandHandle

type HandHandle func(poker *Poker, cards []Card) bool

HandHandle 扑克牌型验证函数

func HandFlushPairs

func HandFlushPairs() HandHandle

HandFlushPairs 同花对子

func HandPairs

func HandPairs() HandHandle

HandPairs 对子

func HandSingle

func HandSingle() HandHandle

HandSingle 单牌

func HandThreeOfKind

func HandThreeOfKind() HandHandle

HandThreeOfKind 三张

type Option

type Option func(poker *Poker)

func WithColorValue

func WithColorValue(colorValues map[Color]int) Option

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

func WithHand

func WithHand(pokerHand string, handle HandHandle) Option

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

func WithPointSort

func WithPointSort(pointSort map[Point]int) Option

WithPointSort 通过特定的扑克点数顺序创建扑克玩法

func WithPointValue

func WithPointValue(pointValues map[Point]int) Option

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

type Point

type Point int

Point 扑克点数

const (
	PointA          Point = 1
	Point2          Point = 2
	Point3          Point = 3
	Point4          Point = 4
	Point5          Point = 5
	Point6          Point = 6
	Point7          Point = 7
	Point8          Point = 8
	Point9          Point = 9
	Point10         Point = 10
	PointJ          Point = 11
	PointQ          Point = 12
	PointK          Point = 13
	PointBlackJoker Point = 14
	PointRedJoker   Point = 15
)

func GetCardsPoint

func GetCardsPoint(cards ...Card) []Point

GetCardsPoint 获取一组扑克牌的点数

func (Point) String

func (slf Point) String() string

type Poker

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

func New

func New(pile *CardPile, options ...Option) *Poker

func (*Poker) CardValue

func (slf *Poker) CardValue(cards ...Card) int

CardValue 获取扑克牌的牌值

func (*Poker) Compare

func (slf *Poker) Compare(cards1 []Card, expression maths.CompareExpression, cards2 []Card) bool

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

func (*Poker) GetPile

func (slf *Poker) GetPile() *CardPile

GetPile 获取牌堆

func (*Poker) IsContinuity

func (slf *Poker) IsContinuity(cards ...Card) bool

IsContinuity 检查一组扑克牌是否连续

func (*Poker) PokerHand

func (slf *Poker) PokerHand(cards ...Card) (cardType string, hit bool)

PokerHand 获取一组扑克的牌型

参数:

  • cards: 扑克牌切片,类型为 []builtin.Card,表示一组扑克牌。

返回值:

  • string: 命中的牌型名称。
  • bool: 是否命中牌型。

Jump to

Keyboard shortcuts

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