poker

package
v0.0.0-...-241bd35 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HgihCard = iota + 1
	OnePair
	TwoPair
	ThreeOfAKind
	Straight
	Flush
	FullHouse
	FourOfAKind
	StraightFlush
	RoyalFlush
)
View Source
const (
	Deuce = iota
	Trey
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
	Ace

	RankMask = 0xF
)

rank

View Source
const (
	Club    = 0x8000
	Diamond = 0x4000
	Heart   = 0x2000
	Spade   = 0x1000

	SuitMask = 0xF000
)

suit

View Source
const (
	MsgIQ       = "iq"
	MsgPresence = "presence"
	MsgMessage  = "message"

	ActGet    = "get"
	ActSet    = "set"
	ActResult = "result"

	ActPreflop  = "preflop"
	ActFlop     = "flop"
	ActTurn     = "turn"
	ActRiver    = "river"
	ActShowdown = "showdown"
	ActPot      = "pot"

	ActActive = "active"
	ActJoin   = "join"
	ActLeave  = "gone"
	ActBet    = "bet"
	ActButton = "button"
	ActState  = "state"

	ActAction = "action"
	ActReady  = "ready"
	ActCall   = "call"
	ActCheck  = "check"
	ActRaise  = "raise"
	ActFold   = "fold"
	ActAllin  = "allin"
)
View Source
const (
	MaxN = 10
)
View Source
const NilCard = Card(0)
View Source
const (
	NumCard = 52
)

Variables

This section is empty.

Functions

func DelRoom

func DelRoom(room *Room)

func Eva5Hand

func Eva5Hand(cards [5]Card) int

func Eva6Hand

func Eva6Hand(cards [6]Card) int

func Eva7Hand

func Eva7Hand(cards [7]Card) int

func NewRoomList

func NewRoomList() *roomlist

func SetRoom

func SetRoom(room *Room)

Types

type Auth

type Auth struct {
	Mechanism string `json:"mechanism"`
	Text      string `json:"text"`
}

type AuthResp

type AuthResp struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	Level int    `json:"level"`
	Chips int    `json:"chips"`
}

type Card

type Card uint32

func ParseCard

func ParseCard(c string) Card

func (Card) MarshalJSON

func (card Card) MarshalJSON() ([]byte, error)

func (Card) Rank

func (card Card) Rank() int

func (Card) String

func (card Card) String() string

func (Card) Suit

func (card Card) Suit() int

func (*Card) UnmarshalJSON

func (card *Card) UnmarshalJSON(b []byte) error

type Conn

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

func NewConn

func NewConn(ws *websocket.Conn, sendBuffer int) *Conn

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) ReadJSON

func (c *Conn) ReadJSON(v interface{}) error

func (*Conn) ReadJSONTimeout

func (c *Conn) ReadJSONTimeout(v interface{}, timeout time.Duration) error

func (*Conn) WriteJSON

func (c *Conn) WriteJSON(v interface{}) error

type Deck

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

func NewDeck

func NewDeck() *Deck

func (*Deck) Find

func (deck *Deck) Find(rank, suit int) Card

func (*Deck) Init

func (deck *Deck) Init()

This routine initializes the deck. A deck of cards is simply an integer array of length 52 (no jokers). This array is populated with each card, using the following scheme:

An integer is made up of four bytes. The high-order bytes are used to hold the rank bit pattern, whereas the low-order bytes hold the suit/rank/prime value of the card.

+--------+--------+--------+--------+ |xxxbbbbb|bbbbbbbb|cdhsrrrr|xxpppppp| +--------+--------+--------+--------+

p = prime number of rank (deuce=2,trey=3,four=5,five=7,...,ace=41) r = rank of card (deuce=0,trey=1,four=2,five=3,...,ace=12) cdhs = suit of card b = bit turned on depending on rank of card

func (*Deck) Shuffle

func (deck *Deck) Shuffle()

func (*Deck) Take

func (deck *Deck) Take() Card

type Error

type Error struct {
	Code int    `json:"code,omitempty"`
	Err  string `json:"error,omitempty"`
}

func NewError

func NewError(code int, err string) *Error

func (*Error) Error

func (e *Error) Error() string

type Message

type Message struct {
	Id       string    `json:"id,omitempty"`
	Type     string    `json:"type"`
	From     string    `json:"from,omitempty"`
	To       string    `json:"to,omitempty"`
	Action   string    `json:"action"`
	Class    string    `json:"class,omitempty"`
	Occupant *Occupant `json:"occupant,omitempty"`
	Room     *Room     `json:"room,omitempty"`
	Rooms    []*Room   `json:"rooms,omitempty"`
}

type Occupant

type Occupant struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Profile string `json:"profile"`
	Level   int    `json:"level"`
	Chips   int    `json:"chips"`

	Pos    int    `json:"index,omitempty"`
	Bet    int    `json:"bet,omitempty"`
	Action string `json:"action,omitempty"`
	Cards  []Card `json:"cards,omitempty"`
	Hand   int    `json:"hand,omitempty"`

	Room *Room `json:"-"`

	Actions chan *Message `json:"-"`
	// contains filtered or unexported fields
}

func NewOccupant

func NewOccupant(id string, conn *Conn) *Occupant

func (*Occupant) Betting

func (o *Occupant) Betting(n int) (raised bool)

func (*Occupant) Broadcast

func (o *Occupant) Broadcast(message *Message)

func (*Occupant) GetAction

func (o *Occupant) GetAction(timeout time.Duration) (*Message, error)

func (*Occupant) GetMessage

func (o *Occupant) GetMessage(timeout time.Duration) (*Message, error)

func (*Occupant) Join

func (o *Occupant) Join(rid string) (room *Room)

func (*Occupant) Leave

func (o *Occupant) Leave() (room *Room)

func (*Occupant) Next

func (o *Occupant) Next() *Occupant

func (*Occupant) SendError

func (o *Occupant) SendError(code int, err string) error

func (*Occupant) SendMessage

func (o *Occupant) SendMessage(message *Message) error

type Poker

type Poker struct {
	WebRoot string
	Addr    string
	OnAuth  func(conn *Conn, mechanism, text string) (*Occupant, error)
	OnExit  func(o *Occupant)
}

func (*Poker) ListenAndServe

func (p *Poker) ListenAndServe() error

type Room

type Room struct {
	Id        string      `json:"id"`
	SB        int         `json:"sb"`
	BB        int         `json:"bb"`
	Cards     []Card      `json:"cards,omitempty"`
	Pot       []int       `json:"pot,omitempty"`
	Timeout   int         `json:"timeout,omitempty"`
	Button    int         `json:"button,omitempty"`
	Occupants []*Occupant `json:"occupants,omitempty"`
	Chips     []int       `json:"chips,omitempty"`
	Bet       int         `json:"bet,omitempty"`
	N         int         `json:"n"`
	Max       int         `json:"max"`
	MaxChips  int         `json:"maxchips"`
	MinChips  int         `json:"minchips"`

	EndChan chan int `json:"-"`
	// contains filtered or unexported fields
}

func GetRoom

func GetRoom(id string) *Room

func NewRoom

func NewRoom(id string, max int, sb, bb int) *Room

func Rooms

func Rooms() (r []*Room)

func (*Room) AddOccupant

func (room *Room) AddOccupant(o *Occupant) int

func (*Room) Broadcast

func (room *Room) Broadcast(message *Message)

func (*Room) Cap

func (room *Room) Cap() int

func (*Room) DelOccupant

func (room *Room) DelOccupant(o *Occupant)

func (*Room) Each

func (room *Room) Each(start int, f func(o *Occupant) bool)

start starts from 0

func (*Room) Occupant

func (room *Room) Occupant(id string) *Occupant

type Version

type Version struct {
	//Id  string `json:"id"`
	Ver string `json:"version"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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