Documentation ¶
Index ¶
- Constants
- Variables
- func AddPlayer(name string) (string, bool)
- func Auth(room string, uuid string) bool
- func CreateRoom()
- func Disconnect(socket socketio.Socket) int
- func Exec()
- func FindGroups(suitSet SuitSet, Components *[]int32, result *[]Groups, tmp []uint32, ...)
- func FindPlayerByName(name string) int
- func FindPlayerBySocket(socket socketio.Socket) int
- func FindPlayerByUUID(uuid string) int
- func GetNameList(list []*IPlayer) []string
- func GetServer() *socketio.Server
- func GetUUIDList(list []IPlayer) []string
- func HaveComponent(suit int32, component int32) bool
- func IF(condition bool, trueVal, falseVal interface{}) interface{}
- func IsValidTile(tile string) bool
- func Login(name string, socket *socketio.Socket) (string, bool)
- func Logout(index int)
- func Match() []string
- func NewGameManager() bool
- func RemovePlayer(id int)
- func RemoveRoom(name string)
- func SocketConnect(so socketio.Socket)
- func SocketError(so socketio.Socket, err error)
- func WaitingNum(isBot int) int
- type Action
- type ActionInfo
- type ActionSet
- type EatAction
- type GameManager
- type GameResult
- type GossipInfo
- type GossipLog
- type Groups
- type HonorsTable
- type HonorsTaiTable
- type HuInfo
- type HuTable
- type IPlayer
- type Player
- func (player *Player) CheckEat(tile Tile) bool
- func (player *Player) CheckHu(tile Tile, isZimo uint, tai *TaiData) bool
- func (player *Player) CheckPon(tile Tile) bool
- func (player *Player) CheckTing() bool
- func (player *Player) Command(actionSet ActionSet, command int, idx int) Action
- func (player *Player) Draw(currentIdx int) (Action, bool, bool)
- func (player *Player) Eat(eatAction EatAction)
- func (player *Player) Fail(command int)
- func (player *Player) Gon(tile Tile, Type int, fromID int)
- func (player *Player) Hu(tile Tile, tai TaiData, Type int, robGon bool, addToRoom bool, fromID int) int
- func (player *Player) Init()
- func (player Player) Name() string
- func (player *Player) Pon(tile Tile)
- func (player Player) Room() string
- func (player Player) Socket() socketio.Socket
- func (player *Player) Success(from int, command int, tile interface{}, score int)
- func (player *Player) Throw(currentIdx int, drawTile Tile) Tile
- type PlayerManager
- type Room
- func (room *Room) Accept(uuid string, callback func(int))
- func (room *Room) AddPlayer(playerList []string)
- func (room Room) BroadcastBanker(id int, keepWin int)
- func (room Room) BroadcastBuHua(flowers [][]string)
- func (room Room) BroadcastCommand(from int, to int, command int, tile string, score int)
- func (room Room) BroadcastCoversation(id int, sentence string)
- func (room Room) BroadcastDraw(id int, num uint)
- func (room Room) BroadcastEnd(data []GameResult)
- func (room Room) BroadcastGameEnd()
- func (room Room) BroadcastGameStart()
- func (room Room) BroadcastHua(id int, tile Tile)
- func (room Room) BroadcastOpenDoor(idx int, dice int)
- func (room Room) BroadcastReady(name string)
- func (room Room) BroadcastRemainTile(num uint)
- func (room Room) BroadcastRobGon(id int, tile Tile)
- func (room Room) BroadcastSetSeat(idx int)
- func (room Room) BroadcastStopWaiting()
- func (room Room) BroadcastThrow(id int, tile Tile)
- func (room Room) BroadcastTing(id int)
- func (room Room) BroadcastWindAndRound(wind int, round int)
- func (room Room) CountDeadCard() SuitSet
- func (room Room) GetCurrentIdx() int
- func (room Room) GetDoor(id int) ([][][]string, []int, bool)
- func (room Room) GetFlower() ([][]string, bool)
- func (room Room) GetHandCount() []int
- func (room Room) GetPlayerList() []string
- func (room Room) GetReadyPlayers() []string
- func (room Room) GetRemainCount() int
- func (room Room) GetScore() []int
- func (room Room) GetSea() ([][]string, bool)
- func (room Room) GetTing() []bool
- func (room Room) GetWindAndRound() (int, int)
- func (room Room) GossipTalk(action string, card string, id int)
- func (room Room) NumPlayer() int
- func (room Room) Record(action string, card Tile, currentIdx int, actionIdx int)
- func (room *Room) RemovePlayer(id int)
- func (room *Room) Run()
- func (room *Room) StopWaiting()
- func (room *Room) WaitToStart()
- type ScoreCalc
- type ScoreRecord
- type Sentence
- type SimplesTable
- type SimplesTaiTable
- type Suit
- type SuitSet
- func (suitSet *SuitSet) Add(input interface{})
- func (suitSet SuitSet) At(idx int) Tile
- func (suitSet SuitSet) Count() uint
- func (suitSet SuitSet) CountStepsToHu() int
- func (suitSet *SuitSet) Draw() Tile
- func (suitSet SuitSet) Have(tile Tile) bool
- func (suitSet SuitSet) IsContainColor(color int) bool
- func (suitSet SuitSet) IsEmpty() bool
- func (suitSet *SuitSet) Sub(input interface{})
- func (suitSet SuitSet) ToStringArray() []string
- type TaiData
- type TaiTable
- type ThrowCardInfo
- type Tile
- type Wind
Constants ¶
const ( BeforeStart = iota DealTile BuHua IdxTurn )
Game State
const ( WAITING = 0 MATCHED = 1 READY = 2 PLAYING = 4 LEAVE = 8 )
Player's state
const ( CanHu = uint(1) HasEye = uint(2) OnlyHasEye = uint(4) TingOnlyOne = uint(8) Clean = uint(16) PingHu = uint(32) MixSuit = uint(64) SameSuit = uint(128) PonPair = uint(256) ConcealedPonCnt = uint(3584) Zimo = uint(4096) East = uint(16) South = uint(32) West = uint(64) North = uint(128) Bonus = uint(256) Red = uint(512) Green = uint(1024) White = uint(2048) LittleFourWinds = uint(4096) BigFourWinds = uint(8192) LittleThreeDragons = uint(16384) BigThreeDragons = uint(32768) EyeNumber = uint(61440) )
Feature
const BASE = 3
BASE represents base score
const (
MONGODB_URL = "127.0.0.1:27017"
)
const SIZE = 76695844
SIZE represents table size
const TAI = 1
TAI represents base tai
Variables ¶
var COMMAND = map[string]int{
"NONE": 0,
"PON": 1,
"GON": 2,
"ONGON": 4,
"PONGON": 8,
"HU": 16,
"ZIMO": 32,
"EAT": 64,
"TING": 128,
}
COMMAND is a map of command type
var Condition = map[string]int{
"Eat": 0,
"Pon": 1,
"Gon": 2,
"OnGon": 3,
"PonGon": 4,
"Hu": 5,
"Zimo": 6,
"Tin": 7,
}
var GroupMask = [40]int32{
02, 020, 0200, 02000, 020000, 0200000, 02000000, 020000000, 0200000000,
03, 030, 0300, 03000, 030000, 0300000, 03000000, 030000000, 0300000000,
0111, 01110, 011100, 0111000, 01110000, 011100000, 0111000000,
011, 0110, 01100, 011000, 0110000, 01100000, 011000000, 0110000000,
0101, 01010, 010100, 0101000, 01010000, 010100000, 0101000000,
}
var SuitTileCount = [5]uint{9, 9, 9, 7, 8}
SuitTileCount represents each suit's tile count
Functions ¶
func Disconnect ¶
func Disconnect(socket socketio.Socket) int
Disconnect handles the player's socket disconnect
func FindGroups ¶
func FindPlayerByName ¶
FindPlayerByName gets player's index by player's name
func FindPlayerBySocket ¶
func FindPlayerBySocket(socket socketio.Socket) int
FindPlayerBySocket gets player's index by player's socket
func FindPlayerByUUID ¶
FindPlayerByUUID gets player's index by player's uuid
func GetNameList ¶
GetNameList returns the list of player's name
func GetUUIDList ¶
GetUUIDList returns the list of player's uuid
func HaveComponent ¶
func IF ¶
func IF(condition bool, trueVal, falseVal interface{}) interface{}
IF implements ternary conditional operator
func SocketConnect ¶
SocketConnect is callback of socket connect event
func SocketError ¶
SocketError is callback of socket error event
func WaitingNum ¶
WaitingNum returns the number of player which state are waiting
Types ¶
type Action ¶
Action represents a command made by player
func JSONToAction ¶
JSONToAction converts json string to action
type GameManager ¶
type GameManager struct { Rooms map[string]*Room Server *socketio.Server Locker sync.Mutex //GossipDB *mgo.Database GossipDealer socketio.Socket }
GameManager represents a gameManager
type GameResult ¶
type GameResult struct { Hand []string Door [][]string Score int ScoreLog ScoreRecord }
GameResult represents the result of mahjong
type GossipInfo ¶
type GossipLog ¶
type GossipLog struct { Name string `bson:"Name,omitempty"` Actions []ActionInfo `bson:"Actions,omitempty"` Sentence string `bson:"Sentence,omitempty"` }
type Groups ¶
func CountSteps ¶
type HonorsTable ¶
type HonorsTable struct {
// contains filtered or unexported fields
}
HonorsTable represenpts honors huTable.table
func NewHonorsTable ¶
func NewHonorsTable() *HonorsTable
NewHonorsTable creates a new honors huTable.table
type HonorsTaiTable ¶
HonorsTaiTable represents honors tai table
func NewHonorsTaiTable ¶
func NewHonorsTaiTable() *HonorsTaiTable
NewHonorsTaiTable creates a new simples tai table
func (*HonorsTaiTable) Get ¶
func (honorsTaiTable *HonorsTaiTable) Get(idx uint) TaiData
Get gets honorsTaiTable data
type HuInfo ¶
type HuInfo struct { Hand SuitSet Door SuitSet Winds Wind IsZimo uint IsClean uint AllPon uint AllChow uint NoBonus uint CertainTile Tile }
HuInfo represents information of hu
type HuTable ¶
type HuTable struct { Melds []uint AllEyes []uint AllSingle []uint PreTable *[]uint Table map[uint]uint }
HuTable represents hu table
type IPlayer ¶
type IPlayer struct { Name string UUID string Room string Socket *socketio.Socket State int Index int IsBot bool LeaveCount int }
IPlayer represents the player's info
func FindPlayerListInRoom ¶
FindPlayerListInRoom gets list of player which in the same room
func FindPlayerListIsSameState ¶
FindPlayerListIsSameState gets list of player which are same state
func NewIPlayer ¶
NewIPlayer creates a new player info
type Player ¶
type Player struct { Hand SuitSet EatTiles []EatAction PonTiles SuitSet GonTiles SuitSet OngonTiles SuitSet Flowers SuitSet DiscardTiles SuitSet ScoreLog ScoreRecord Credit int JustGon bool FirstDraw bool ID int UUID string ThrowTimes int //哈拉加的 StepsToHu int IsTing bool OtherTing bool SafeBefore []string Actions []ActionInfo // contains filtered or unexported fields }
Player represents a player in mahjong
func (*Player) Hu ¶
func (player *Player) Hu(tile Tile, tai TaiData, Type int, robGon bool, addToRoom bool, fromID int) int
Hu hus tile tile
type PlayerManager ¶
type PlayerManager []*IPlayer
PlayerManager represents the array of pointer of IPlayer
var PlayerList PlayerManager
PlayerList is a PlayerManager
type Room ¶
type Room struct { Players []*Player Deck SuitSet Turn int Waiting bool IO *socketio.Server Name string State int Info HuInfo KeepWin bool NumKeepWin int Banker int SevenFlower bool SevenID int Wind int Round int OpenIdx int EastIdx int }
Room represents a round of mahjong
func (Room) BroadcastBanker ¶
BroadcastBanker broadcasts banker ID
func (Room) BroadcastBuHua ¶
BroadcastBuHua broadcasts the player's flower
func (Room) BroadcastCommand ¶
BroadcastCommand broadcasts the player's id and the command he made
func (Room) BroadcastCoversation ¶
BroadcastConversation broadcasts when player have something to say
func (Room) BroadcastDraw ¶
BroadcastDraw broadcasts the player's id who draw a tile
func (Room) BroadcastEnd ¶
func (room Room) BroadcastEnd(data []GameResult)
BroadcastEnd broadcasts the game result
func (Room) BroadcastGameEnd ¶
func (room Room) BroadcastGameEnd()
BroadcastGameEnd broadcasts when the game end
func (Room) BroadcastGameStart ¶
func (room Room) BroadcastGameStart()
BroadcastGameStart broadcasts player list
func (Room) BroadcastHua ¶
BroadcastHua broadcasts the player's draw flower
func (Room) BroadcastOpenDoor ¶
BroadcastOpenDoor broadcasts poen door index and dice number
func (Room) BroadcastReady ¶
BroadcastReady broadcasts the player's name who is ready
func (Room) BroadcastRemainTile ¶
BroadcastRemainTile broadcasts remain tile
func (Room) BroadcastRobGon ¶
BroadcastRobGon broadcasts rob gon
func (Room) BroadcastSetSeat ¶
BroadcastSetSeat broadcasts east seat idx
func (Room) BroadcastStopWaiting ¶
func (room Room) BroadcastStopWaiting()
BroadcastStopWaiting broadcasts stop waiting signal
func (Room) BroadcastThrow ¶
BroadcastThrow broadcasts the player's id and the tile he threw
func (Room) BroadcastTing ¶
BroadcastTing broadcasts the player's id which is ting
func (Room) BroadcastWindAndRound ¶
BroadcastWindAndRound broadcasts wind and round index
func (Room) CountDeadCard ¶
func (Room) GetCurrentIdx ¶
GetCurrentIdx returns current index
func (Room) GetHandCount ¶
GetHandCount returns each player's amount of hand
func (Room) GetPlayerList ¶
GetPlayerList returns the list of player's name
func (Room) GetReadyPlayers ¶
GetReadyPlayers returns the name list of ready player
func (Room) GetRemainCount ¶
GetRemainCount returns amount of deck
func (Room) GetWindAndRound ¶
GetWindAndRound returns the wind and round
func (*Room) RemovePlayer ¶
RemovePlayer reomves id th player from this room
func (*Room) WaitToStart ¶
func (room *Room) WaitToStart()
WaitToStart checks if all player in this room are ready and run the mahjong logic
type ScoreCalc ¶
type ScoreCalc struct { TaiTable *TaiTable SimplesTable *SimplesTable HonorsTable *HonorsTable }
ScoreCalc represents score calculator
type ScoreRecord ¶
ScoreRecord represents the record of score
func NewScoreRecord ¶
func NewScoreRecord(message string, score int, tile string) ScoreRecord
NewScoreRecord creates a new scoreRecord
type SimplesTable ¶
type SimplesTable struct {
// contains filtered or unexported fields
}
SimplesTable represents simples table
func NewSimplesTable ¶
func NewSimplesTable() *SimplesTable
NewSimplesTable creates a new simples table
type SimplesTaiTable ¶
SimplesTaiTable represents simples tai table
func NewSimpleTaiTable ¶
func NewSimpleTaiTable() *SimplesTaiTable
NewSimpleTaiTable creates a new simples tai table
func (*SimplesTaiTable) Get ¶
func (simplesTaiTable *SimplesTaiTable) Get(idx uint) TaiData
Get gets simplesTaiTable data
type SuitSet ¶
type SuitSet [5]Suit
SuitSet represents a set of suit
func ArrayToSuitSet ¶
ArrayToSuitSet converts tile array to suit set
func (*SuitSet) Add ¶
func (suitSet *SuitSet) Add(input interface{})
Add adds a tile or a suit set to a suit set
func (SuitSet) CountStepsToHu ¶
func (SuitSet) IsContainColor ¶
IsContainColor return if suit set contain color
func (*SuitSet) Sub ¶
func (suitSet *SuitSet) Sub(input interface{})
Sub subs a tile or a suit set from a suit set
func (SuitSet) ToStringArray ¶
ToStringArray converts suit set to string array
type TaiTable ¶
type TaiTable struct {
// contains filtered or unexported fields
}
TaiTable represents tai table
type ThrowCardInfo ¶
type Tile ¶
Tile represents a mahjong tile
func StringArrayToTileArray ¶
StringArrayToTileArray converts string array to tile array