poker

package
v0.0.0-...-efc32f0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2017 Andrew Medworth

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

This file is part of Gopoker, a set of miscellaneous poker-related functions written in the Go programming language (http://golang.org).

Gopoker is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Gopoker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with Gopoker. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllCardCombinations

func AllCardCombinations(pack []Card, numRequired int) [][]Card

Compute all unique subsets of a set of cards, of a given size.

func Beats

func Beats(h1 HandLevel, h2 HandLevel) bool

Compares two hands to see if one beats the other. All this needs to do is compare the levels; if they match, we compare the tiebreak ranks lexicographically.

func BeatsAceToFiveLow

func BeatsAceToFiveLow(l1, l2 HandLevel) bool

Determine whether one hand beats another using the ace-to-five low system.

func CardsEqual

func CardsEqual(c1, c2 []Card) bool

Check equality of sets of cards, ignoring ordering (mutates inputs)

func IsRankLess

func IsRankLess(rank1, rank2 Rank, aceLow bool) bool

func PotOddsBreakEven

func PotOddsBreakEven(totalPotsWon float64, handCount int) float64

Calculate the largest bet which would have a positive expected value, relative to the size of the pot.

func SortCards

func SortCards(cards []Card, aceLow bool)

func TestAssertPotsWonSanity

func TestAssertPotsWonSanity(winCount int, potsWon float64, description string, t *testing.T)

func TestAssertSimSanity

func TestAssertSimSanity(sim *Simulator, players, simulations int, t *testing.T)

func TestMakeHands

func TestMakeHands(hands ...[]Card) [][]Card

func TestPackPermutation

func TestPackPermutation(pack *Pack, t *testing.T)

Assert that the pack contains exactly one of every card

Types

type Card

type Card struct {
	Rank
	Suit
}

func C

func C(c string) Card

Abbreviated constructor function for a card, to save typing.

func MakeCard

func MakeCard(c string) (Card, error)

Construct a card from text, e.g. "QD" for queen of diamonds

func TestMakeHand

func TestMakeHand(cards ...string) []Card

func (Card) HTML

func (c Card) HTML() string

func (Card) String

func (c Card) String() string

type HandClass

type HandClass int8

Classification of a poker hand (e.g. "straight flush"). For any two hands with different classifications, the higher-classified hand will always beat the lower.

const (
	HighCard HandClass = iota
	OnePair
	TwoPair
	ThreeOfAKind
	Straight
	Flush
	FullHouse
	FourOfAKind
	StraightFlush
	MAX_HANDCLASS // Just a convenience value for iteration
)

func (HandClass) String

func (hc HandClass) String() string

type HandLevel

type HandLevel struct {
	Class     HandClass
	Tiebreaks []Rank
}

The full information needed to determine whether one hand beats another. Tiebreak ranks are used to determine which hand wins if both are in the same class. For example, two full houses are compared first by the three-card set, then by the two-card set, so e.g. for threes-over-Jacks, the tiebreaks should be {Three,Jack}.

func ClassifyAceToFiveLow

func ClassifyAceToFiveLow(cards []Card) HandLevel

Ace-to-five low classification is very similar to standard classification - we just ignore straights and flushes.

func ClassifyHand

func ClassifyHand(cards []Card) HandLevel

Classify a hand of five cards

func MinLevel

func MinLevel() HandLevel

Function which returns a hand level beaten by any legitimate level

func TestMakeHandLevel

func TestMakeHandLevel(handClassStr string, tieBreakRankStrs ...string) HandLevel

func TestMakeHandLevels

func TestMakeHandLevels(levels ...HandLevel) []HandLevel

func (HandLevel) PrettyPrint

func (hl HandLevel) PrettyPrint() string

func (HandLevel) PrettyTiebreaks

func (hl HandLevel) PrettyTiebreaks() string

func (HandLevel) String

func (hl HandLevel) String() string

type HandOutcome

type HandOutcome struct {
	Won, OpponentWon, RandomOpponentWon                      bool
	PotFractionWon                                           float64
	BestOpponentPotFractionWon, RandomOpponentPotFractionWon float64
	OurLevel, BestOpponentLevel, RandomOpponentLevel         HandLevel
}

type Pack

type Pack struct {
	Cards [52]Card
}

func NewPack

func NewPack() Pack

func (*Pack) IndexOf

func (p *Pack) IndexOf(card Card) int

func (*Pack) Shuffle

func (p *Pack) Shuffle(randGen *rand.Rand)

Shuffle the pack

type Rank

type Rank int8
const (
	Two Rank = iota
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
	Ace
)

func MakeRank

func MakeRank(r string) (Rank, error)

Construct a rank from text

func (Rank) String

func (r Rank) String() string

type Simulator

type Simulator struct {
	Players                int
	HandCount              int
	WinCount               int
	JointWinCount          int
	BestOpponentWinCount   int
	RandomOpponentWinCount int
	PotsWon                float64
	BestOpponentPotsWon    float64
	RandomOpponentPotsWon  float64

	OurClassCounts            []int
	BestOpponentClassCounts   []int
	RandomOpponentClassCounts []int

	ClassWinCounts        []int
	ClassJointWinCounts   []int
	ClassBestOppWinCounts []int
	ClassRandOppWinCounts []int

	BestHand          HandLevel
	BestOppHand       HandLevel
	ClassBestHands    []HandLevel
	ClassBestOppHands []HandLevel
}

func (*Simulator) PotOddsBreakEven

func (s *Simulator) PotOddsBreakEven() float64

func (*Simulator) ProcessHand

func (s *Simulator) ProcessHand(outcome *HandOutcome)

func (*Simulator) Reset

func (s *Simulator) Reset(players, handsToPlay int)

type Suit

type Suit int8
const (
	Heart Suit = iota
	Diamond
	Spade
	Club
)

func (Suit) HTML

func (s Suit) HTML() string

Render as suitable HTML Unicode

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