mahjong

package
v0.0.0-...-19e6259 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 7 Imported by: 0

README

   条        筒
----------------------
0 1条    |   36 1筒   |
1 1条    |   37 1筒   |
2 1条    |   38 1筒   |
3 1条    |   39 1筒   |
4 2条    |   40 2筒   |
5 2条    |   41 2筒   |
6 2条    |   42 2筒   |
7 2条    |   43 2筒   |
8 3条    |   44 3筒   |
9 3条    |   45 3筒   |
10 3条   |   46 3筒   |
11 3条   |   47 3筒   |
12 4条   |   48 4筒   |   
13 4条   |   49 4筒   |   
14 4条   |   50 4筒   |   
15 4条   |   51 4筒   |   
16 5条   |   52 5筒   |   
17 5条   |   53 5筒   |   
18 5条   |   54 5筒   |   
19 5条   |   55 5筒   |   
20 6条   |   56 6筒   |   
21 6条   |   57 6筒   |   
22 6条   |   58 6筒   |   
23 6条   |   59 6筒   |   
24 7条   |   60 7筒   |   
25 7条   |   61 7筒   |   
26 7条   |   62 7筒   |   
27 7条   |   63 7筒   |   
28 8条   |   64 8筒   |   
29 8条   |   65 8筒   |   
30 8条   |   66 8筒   |   
31 8条   |   67 8筒   |   
32 9条   |   68 9筒   |   
33 9条   |   69 9筒   |   
34 9条   |   70 9筒   |   
35 9条   |   71 9筒   |   

Documentation

Index

Constants

View Source
const (
	PingHu   = iota
	PongPong // 碰碰胡:由4副刻子(或杠)、将牌组成的胡牌
	QiDui    // 七对: 7个对子组成的的胡牌
	LongQiDui
	ShuangLongQiDui
	HaoHuaLongQiDui
	QYS          // 清一色:由一种花色的牌组成的胡牌
	HaiDiLao     // 海底捞:抓棹面上最后一张牌的人正好能胡牌
	GangShangHua // 杠上花: 杠来自己要胡的牌胡牌
)
View Source
const (
	MaxFan = -1 // 极品
	MeiHu  = -2 // 没胡牌
)
View Source
const (
	IllegalIndex = -1
)
View Source
const MaxTileIndex = 29

每种花色(条,筒)最多9种牌型,但牌是没有0点的共计 9+9 1-9: 条 11-19: 筒 21-29: 万

Variables

This section is empty.

Functions

func CanHu

func CanHu(onHand Indexes, discard int) bool

func CheckWin

func CheckWin(indexes Indexes) bool

func IndexFromID

func IndexFromID(id int) int

func IsTing

func IsTing(onHand Indexes) bool

func MaxMultiple

func MaxMultiple(opts *protocol.DeskOptions, onHand, pongKong Indexes) (multiple int, index int)

返回听牌最大番数

func Multiple

func Multiple(ctx *Context, onHand, pongKong Indexes) int

返回番数

func RemoveId

func RemoveId(m *Mahjong, tid int)

Types

type Context

type Context struct {
	WinningID         int      //自己要和的牌
	PrevOp            int      //上一个操作
	NewDrawingID      int      //最新上手的牌
	NewOtherDiscardID int      //上家打出的最新一张牌
	LastDiscardId     int      // 最新打过的牌
	Desc              []string // 描述

	IsLastTile bool //自己上手的最新一张牌,是否是桌面上的最后一张

	LastHint *protocol.Hint //最后一次提示

	ResultType int

	Opts   *protocol.DeskOptions
	DeskNo string
	Uid    int64

	Fan int // 番数, -1表示极品
	Que int // 定缺,0表示未定缺,1表示缺条/2缺筒/3缺万

	IsGangShangHua bool // 是不是杠上花
	IsGangShangPao bool // 是不是杠上炮
	IsQiangGangHu  bool // 是不是抢杠胡
}

func (*Context) Reset

func (c *Context) Reset()

func (*Context) SetPrevOp

func (c *Context) SetPrevOp(op int)

func (*Context) String

func (c *Context) String() string

type IndexInfo

type IndexInfo struct {
	Index int
	I     int
}

type Indexes

type Indexes []int // 麻将的index

func TingTiles

func TingTiles(onHand Indexes) Indexes

传入一副牌,返回所有的听牌

func (Indexes) Mark

func (indexes Indexes) Mark(is ...int)

func (Indexes) Reset

func (indexes Indexes) Reset()

func (Indexes) Sort

func (indexes Indexes) Sort()

func (Indexes) String

func (indexes Indexes) String() string

func (Indexes) TileString

func (indexes Indexes) TileString(i int) string

func (Indexes) Unmark

func (indexes Indexes) Unmark(is ...int)

func (Indexes) Unmarked

func (indexes Indexes) Unmarked() ([14]IndexInfo, int)

返回所有未使用的Index, 并返回数量

func (Indexes) UnmarkedCount

func (indexes Indexes) UnmarkedCount() int

func (Indexes) UnmarkedSequence

func (indexes Indexes) UnmarkedSequence() ([3]IndexInfo, int)

返回一个刻子, 并返回数量

func (Indexes) UnmarkedString

func (indexes Indexes) UnmarkedString() string

func (Indexes) UnmarkedTriplet

func (indexes Indexes) UnmarkedTriplet() ([3]IndexInfo, int)

type Mahjong

type Mahjong []*Tile

func FromID

func FromID(ids []int) Mahjong

根据id索引创建

func (Mahjong) Ids

func (m Mahjong) Ids() []int

func (Mahjong) Indexes

func (m Mahjong) Indexes() []int

func (Mahjong) Len

func (m Mahjong) Len() int

func (Mahjong) Less

func (m Mahjong) Less(i, j int) bool

func (Mahjong) Shuffle

func (m Mahjong) Shuffle()

func (Mahjong) Sort

func (m Mahjong) Sort()

func (Mahjong) String

func (m Mahjong) String() string

func (Mahjong) Swap

func (m Mahjong) Swap(i, j int)

type ReadyTile

type ReadyTile struct {
	Index  int //和牌的index
	Points int //番数
}

func (*ReadyTile) Equals

func (rt *ReadyTile) Equals(t *ReadyTile) bool

func (*ReadyTile) String

func (rt *ReadyTile) String() string

type Result

type Result []int

func (Result) String

func (res Result) String() string

type ScoreChangeType

type ScoreChangeType byte

type Stats

type Stats [MaxTileIndex + 1]byte

func NewStats

func NewStats(indexes ...Indexes) *Stats

func (*Stats) CountWithIndex

func (ms *Stats) CountWithIndex(idx int) int

func (*Stats) From

func (ms *Stats) From(mjs ...Mahjong)

func (*Stats) FromIndex

func (ms *Stats) FromIndex(tiles ...Indexes)

func (*Stats) String

func (ms *Stats) String() string

type Tile

type Tile struct {
	Id    int
	Suit  int //花色
	Rank  int //点数
	Index int //索引(1~9, 11~19)
}

func TileFromID

func TileFromID(id int) *Tile

id: 0~3 -> 1条 4~7 -> 2条 ... 0~35 =>条 36~71 =>筒

func TileFromIndex

func TileFromIndex(idx int) *Tile

func (*Tile) Equals

func (t *Tile) Equals(other *Tile) bool

func (*Tile) String

func (t *Tile) String() string

type Tiles

type Tiles []int //麻将内部表示(即72张牌的id号列表)

func New

func New(count int) Tiles

func (Tiles) Shuffle

func (m Tiles) Shuffle()

Jump to

Keyboard shortcuts

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