cactuskev

package module
v0.0.0-...-4e45ecf Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2014 License: BSD-3-Clause Imports: 6 Imported by: 1

README

cactuskev-go

An implementation of Cactus Kev's hand evaluator (http://suffecool.net/poker/evaluator.html) in golang.

Documentation

Overview

Credit: http://suffecool.net/poker/evaluator.html

Index

Constants

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

Variables

View Source
var Flushes = [...]Score{}/* 7937 elements not displayed */

** this is a table lookup for all "flush" hands (e.g. both ** flushes and straight-flushes. entries containing a zero ** mean that combination is not possible with a five-card ** flush hand.

View Source
var Perm7 = [21][5]int{
	{0, 1, 2, 3, 4},
	{0, 1, 2, 3, 5},
	{0, 1, 2, 3, 6},
	{0, 1, 2, 4, 5},
	{0, 1, 2, 4, 6},
	{0, 1, 2, 5, 6},
	{0, 1, 3, 4, 5},
	{0, 1, 3, 4, 6},
	{0, 1, 3, 5, 6},
	{0, 1, 4, 5, 6},
	{0, 2, 3, 4, 5},
	{0, 2, 3, 4, 6},
	{0, 2, 3, 5, 6},
	{0, 2, 4, 5, 6},
	{0, 3, 4, 5, 6},
	{1, 2, 3, 4, 5},
	{1, 2, 3, 4, 6},
	{1, 2, 3, 5, 6},
	{1, 2, 4, 5, 6},
	{1, 3, 4, 5, 6},
	{2, 3, 4, 5, 6}}
View Source
var Primes = [...]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41}

** each of the thirteen card ranks has its own prime number ** ** deuce = 2 ** trey = 3 ** four = 5 ** five = 7 ** ... ** king = 37 ** ace = 41

View Source
var Unique5 = [...]Score{}/* 7937 elements not displayed */

** this is a table lookup for all non-flush hands consisting ** of five unique ranks (i.e. either Straights or High Card ** hands). it's similar to the above "flushes" array.

Functions

func AllFive

func AllFive(t *testing.T, handfn func() Hand, zerofn func(Hand) Hand)

func AllSeven

func AllSeven(t *testing.T, handfn func() Hand, zerofn func(Hand) Hand)

func RandomizeHand

func RandomizeHand(h Hand)

Types

type Card

type Card int32

func NewCard

func NewCard(s Suit, r Rank) Card

func (Card) Bit

func (c Card) Bit() int

func (Card) Prime

func (c Card) Prime() int

func (Card) Rank

func (c Card) Rank() Rank

func (Card) String

func (c Card) String() string

func (Card) Suit

func (c Card) Suit() Suit

type Category

type Category int
const (
	StraightFlush Category = iota
	FourOfAKind
	FullHouse
	Flush
	Straight
	ThreeOfAKind
	TwoPair
	OnePair
	HighCard
)

func (Category) String

func (c Category) String() string

type Deck

type Deck []Card

func NewDeck

func NewDeck() Deck

func (*Deck) Draw

func (d *Deck) Draw() (Card, bool)

Draw, if any cards are available, removes a card from the end of the deck and returns it and true. If deck is empty it false is returned.

func (Deck) Len

func (d Deck) Len() int

func (Deck) Less

func (d Deck) Less(i, j int) bool

func (*Deck) MustDraw

func (d *Deck) MustDraw() Card

func (Deck) Randomize

func (d Deck) Randomize()

func (*Deck) Remove

func (d *Deck) Remove(c Card)

Remove removes c from Deck.

func (Deck) Swap

func (d Deck) Swap(i, j int)

type FiveCardHand

type FiveCardHand struct {
	A, B, C, D, E, F Card
}

func NewFiveCardHand

func NewFiveCardHand() *FiveCardHand

func (*FiveCardHand) Bit

func (h *FiveCardHand) Bit() int

func (*FiveCardHand) Card

func (h *FiveCardHand) Card(n int) Card

func (*FiveCardHand) Cards

func (h *FiveCardHand) Cards() []Card

func (*FiveCardHand) Eval

func (h *FiveCardHand) Eval() Score

func (*FiveCardHand) IsSuited

func (h *FiveCardHand) IsSuited() bool

IsSuited returns true if entire hand is of the same Suit.

func (FiveCardHand) Len

func (h FiveCardHand) Len() int

func (*FiveCardHand) Prime

func (h *FiveCardHand) Prime() int

func (*FiveCardHand) SetCard

func (h *FiveCardHand) SetCard(n int, c Card)

func (*FiveCardHand) String

func (h *FiveCardHand) String() string

type Hand

type Hand interface {
	Eval() Score
	SetCard(int, Card)
	Card(int) Card
	Len() int
	Cards() []Card
	Prime() int
	Bit() int
}

func NewHand

func NewHand(n int) Hand

func RandomHand

func RandomHand(n int) Hand

type Rank

type Rank uint16
const (
	Deuce Rank = iota
	Trey
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
	Ace
)

func (Rank) String

func (r Rank) String() string

type Score

type Score int16

func (Score) Category

func (s Score) Category() Category

func (Score) Less

func (s Score) Less(other Score) bool

func (Score) String

func (s Score) String() string

type SevenCardHand

type SevenCardHand struct{ A, B, C, D, E, F, G Card }

func NewSevenCardHand

func NewSevenCardHand() *SevenCardHand

func (*SevenCardHand) Bit

func (h *SevenCardHand) Bit() int

func (*SevenCardHand) Card

func (h *SevenCardHand) Card(n int) Card

func (*SevenCardHand) Cards

func (h *SevenCardHand) Cards() []Card

func (*SevenCardHand) Eval

func (h *SevenCardHand) Eval() Score

func (SevenCardHand) Len

func (h SevenCardHand) Len() int

func (*SevenCardHand) Prime

func (h *SevenCardHand) Prime() int

func (*SevenCardHand) SetCard

func (h *SevenCardHand) SetCard(n int, c Card)

func (*SevenCardHand) String

func (h *SevenCardHand) String() string

type Suit

type Suit uint16

func (Suit) String

func (s Suit) String() string

Jump to

Keyboard shortcuts

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