algorithm

package
v0.0.0-...-f84f93e Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WILDCARD byte   = 255  // 万能牌(财神牌)
	BAI      byte   = 0x53 // 白板
	TOTAL    uint32 = 136  //一副麻将的总数
	FENG     byte   = 4    //风牌类型
	ZI       byte   = 5    //字牌类型
	HAND     uint32 = 13   //手牌数量

	// 吃、碰、杠、胡掩码,用无符号32位每个二进制位代表不同的操作状态
	PENG      int64 = 2 << 0 // 碰
	MING_KONG int64 = 2 << 1 // 明杠
	AN_KONG   int64 = 2 << 2 // 暗杠
	BU_KONG   int64 = 2 << 3 // 补杠
	KONG      int64 = 2 << 4 // 杠(代表广义的杠)
	CHOW      int64 = 2 << 5 // 吃
	HU        int64 = 2 << 6 // 鸡胡(也代表广义的胡)

	HU_BAO_TOU1       int64 = 2 << 7  // 爆头(敲响,摸到普通牌),已经有十二张牌顺刻组合,剩下一张牌为财神,并无将牌,抓到任意一张则为敲响。普通牌2倍,
	HU_BAO_TOU2       int64 = 2 << 8  // 爆头(敲响,摸到摸到白板),已经有十二张牌顺刻组合,剩下一张牌为财神,并无将牌,抓到任意一张则为敲响。摸到白板4倍
	HU_BAO_TOU3       int64 = 2 << 9  // 爆头(敲响,摸到财神),已经有十二张牌顺刻组合,剩下一张牌为财神,并无将牌,抓到任意一张则为敲响。摸到财神6倍
	HU_LUAN_FENG      int64 = 2 << 11 // 乱风,手牌都由风字牌组成,无需胡牌牌型
	HU_QING_FENG      int64 = 2 << 30 // 清风,手牌都由风字牌组成,需胡牌牌型
	HU_QUAN_QIU_REN   int64 = 2 << 13 // 全求人(单吊)
	ZIMO              int64 = 2 << 17 // 自摸
	PAOHU             int64 = 2 << 18 // 炮胡,也叫放充
	QIANG_GANG        int64 = 2 << 19 // 抢杠,其他家胡你补杠那张牌
	HU_KONG_FLOWER    int64 = 2 << 20 // 杠上开花,杠完牌抓到的第一张牌自摸了
	HU_HAI_LAO        int64 = 2 << 21 // 海底捞月,每杠一次牌要从牌墙中除去8张牌,所以有杠牌的情况没有海底捞
	TIAN_HU           int64 = 2 << 23 // 天胡
	DI_HU             int64 = 2 << 24 // 地胡
	HU_SINGLE         int64 = 2 << 25 // 13不靠(风未齐)
	HU_SINGLE_ZI      int64 = 2 << 26 // 13不靠
	HU_CAI_1          int64 = 2 << 27 // 一财一刻,1个财神加2个白板组成一副刻子,2倍
	HU_CAI_2          int64 = 2 << 28 // 两财一刻,2个财神加1个白板组成一副刻子,4倍
	HU_CAI_3          int64 = 2 << 29 // 三财一刻,3个财神组成一副刻子,6倍
	HU_GUI_WEI1       int64 = 2 << 14 // 一个财神归位,1个财神扮演其本身牌,2倍
	HU_GUI_WEI2       int64 = 2 << 15 // 两个财神归位,2个财神扮演其本身牌,4倍
	HU_GUI_WEI3       int64 = 2 << 16 // 三个财神归位,3个财神扮演其本身牌,6倍
	HU_3_CAI_SHEN     int64 = 2 << 22 // 三个财神额外加1倍
	HU_SEVEN_PAIR     int64 = 2 << 31 // 小七对(无财神)
	HU_SEVEN_PAIR_CAI int64 = 2 << 32 // 小七对(有财神)
	HU_ONE_SUIT       int64 = 2 << 33 // 清一色(无财神)
	HU_ONE_SUIT_CAI   int64 = 2 << 34 // 清一色(有财神)
	HU_PENG_PENG      int64 = 2 << 35 // 碰碰胡(无财神)
	HU_PENG_PENG_CAI  int64 = 2 << 36 // 碰碰胡(有财神)
)

胡牌方式:自摸,放冲,枪杠胡,杠上开花,天胡,地胡等 胡牌牌型:平胡,碰碰胡,小七对,清一色,13不靠,财神归位等 牌墙只剩4张牌的情况下,如果有人放炮,放炮家要负责其他两家的分值 放炮胡时闲家的付出为放炮家的一半 牌型番值叠加最高不超过番

Variables

View Source
var CARDS = []byte{}/* 136 elements not displayed */

全部牌值, 高四位表示色值(0:万,1:条,2:饼,4:风,5:字), 低四位表示1-9的牌值

Functions

func DecodeChow

func DecodeChow(value uint32) (c1, c2, c3 byte)

func DecodeChow2

func DecodeChow2(value uint32) (c1, c2 byte)

func DecodeKong

func DecodeKong(value uint32) (seat uint32, card byte, v uint32)

func DecodePeng

func DecodePeng(value uint32) (seat uint32, card byte)

func DetectKong

func DetectKong(cs []byte, ps []uint32, wildcard byte) (status int64)

func DiscardChow

func DiscardChow(s1, s2 uint32, card byte, cs []byte, wildcard byte) (status int64)

打牌检测,吃

func DiscardPong

func DiscardPong(card byte, cs []byte, wildcard byte) (status int64)

打牌检测,明杠/碰牌

func EncodeChow

func EncodeChow(c1, c2, c3 byte) (value uint32)

func EncodeKong

func EncodeKong(seat uint32, card byte, value uint32) uint32

func EncodePeng

func EncodePeng(seat uint32, card byte) uint32

碰杠吃数据

func Exist

func Exist(c byte, cs []byte, n int) bool

是否存在n个牌

func ExistBaoTou

func ExistBaoTou(cards []byte, ch, ps, ks []uint32, wildcard byte, card byte, draw bool, hu int64) int64

爆头检测(敲响): 已经有十二张牌组合好,剩下一张牌为财神,并无将牌,抓到任意一张则为敲响。普通牌2倍,摸到白板4倍,摸到财神6倍。 (已经有十二张牌组合好,剩下一张牌为财神,并无将牌,别人打出财神牌,或者白板算放炮吗) (此种情况为爆头,只能自摸,别人打出牌一律不能胡) (该种情况可与其他胡牌情况倍数累加)

func ExistCaiShen

func ExistCaiShen(cards []byte, hu int64, wildcard byte, card byte, draw bool) int64

清一色/碰碰和/小七对 牌型有无财神对 检测

func ExistHu

func ExistHu(cards []byte, ch, ps, ks []uint32, wildcard byte, card byte, color int64, luanfeng int64) int64

判断是否胡牌,0表示不胡牌,非0用32位表示不同的胡牌牌型

func ExistLuanFeng

func ExistLuanFeng(cards []byte) int64

乱风胡检测 所有牌都为风牌(东南西北中发白),无需成胡牌型 碰杠牌要加入检测

func ExistNCaiNKe

func ExistNCaiNKe(cs []byte, ch, ps, ks []uint32, wildcard byte, luanfeng int64) int64

func ExistOneSuit

func ExistOneSuit(cards []byte, wildcard byte) int64

清一色检测

func ExistPengPeng

func ExistPengPeng(cs []byte, wildcard byte) int64

碰碰胡 有序slices cs

func GetHandPongKong

func GetHandPongKong(cards []byte, ch, ps, ks []uint32, wildcard byte) []byte

合并手牌、杠牌、碰牌

func HuType

func HuType(value int64, ante uint32) uint32

算番(牌型) 多个牌型时相加

func Legal(card byte) bool

验证给定的牌是否是有效的麻将牌值

func NextSeat

func NextSeat(seat uint32) uint32

正常流程走牌令牌移到下一家

func Remove

func Remove(c byte, cs []byte) []byte

移除一个牌

func RemoveN

func RemoveN(c byte, cs []byte, n int) []byte

移除n个牌

func SearchDirtyCard

func SearchDirtyCard(cs []byte, wildcard byte) byte

func Sort

func Sort(arr []byte, start, end int)

对牌值从小到大排序,采用快速排序算法

func ThreeWildcard

func ThreeWildcard(handcard []byte, wildcard byte) int64

三个财神加倍

func VerifyChow

func VerifyChow(cards []byte, c1, c2, c3 byte, wildcard byte) bool

验证吃, c1,c2,c3有序

Types

This section is empty.

Jump to

Keyboard shortcuts

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