paycalc

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package paycalc contains a tournament payout tables.

Example
package main

import (
	"fmt"

	"github.com/cardrank/cardrank/paycalc"
)

func main() {
	const typ, entries, buyin, guaranteed, rake = paycalc.Top10, 110, 1000, 60000, 0.15
	levels, amounts, payouts := typ.Stakes(entries, buyin, guaranteed, rake)
	for i := 0; i < len(levels); i++ {
		title := paycalc.LevelTitle(levels[i][0], levels[i][1])
		fmt.Printf("%s (%0.2f%%): %d\n", title, amounts[i]*100, payouts[i])
	}
}
Output:

1st (28.00%): 26180
2nd (17.00%): 15895
3rd (10.60%): 9911
4th (8.60%): 8041
5th (7.60%): 7106
6th (5.30%): 4955
7th (4.30%): 4020
8th (3.30%): 3085
9th (2.70%): 2524
10th (2.10%): 1963
11-15 (2.10%): 1963
Example (Payout)
package main

import (
	"fmt"

	"github.com/cardrank/cardrank/paycalc"
)

func main() {
	const typ, entries, buyin, guaranteed, rake = paycalc.Top10, 110, 1000, 60000, 0.15
	for i := 0; i < 15; i++ {
		payout := typ.Payout(i, entries, buyin, guaranteed, rake)
		fmt.Printf("%d: %d\n", i+1, payout)
	}
}
Output:

1: 26180
2: 15895
3: 9911
4: 8041
5: 7106
6: 4955
7: 4020
8: 3085
9: 2524
10: 1963
11: 1963
12: 1963
13: 1963
14: 1963
15: 1963

Index

Examples

Constants

This section is empty.

Variables

View Source
var Precision = int(math.Pow(10, 2))

Precision is the precision amount used by Calc.

View Source
var Round = func(f float64) float64 {
	return math.Round(f*float64(Precision)) / float64(Precision)
}

Round is the round implementation used by Calc. Rounds to Precision.

Functions

func Calc

func Calc(f float64, entries int, buyin, guaranteed int64, rake float64) int64

Calc calculates a payout for the percentage f, based on entries, buyin, guaranteed amount, and rake. Uses Round to round to Precision.

func EpsilonEqual

func EpsilonEqual[R, S, T Ordered](a R, b S, epsilon T) bool

EpsilonEqual returns true when a and b are within epsilon.

func Init

func Init() error

Init initializes the tournament payout tables.

func LevelTitle

func LevelTitle(last, n int) string

LevelTitle formats the level of last, n.

func Register

func Register(typ Type, t *Table) error

Register registers a tournament payout table.

func RegisterBytes

func RegisterBytes(typ Type, buf []byte, top float64, name string) error

RegisterBytes registers a tournament payout table read as CSV from buf.

func RegisterReader

func RegisterReader(typ Type, r io.Reader, top float64, name string) error

RegisterReader registers a tournament payout table read as CSV from the reader.

func Total

func Total(entries int, buyin, guaranteed int64, rake float64) int64

Total calculates the total payout based on entries, buyin, guaranteed amount, and rake. Uses Round to round to Precision.

Types

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64
}

Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.

Note that floating-point types may contain NaN ("not-a-number") values. An operator such as == or < will always report false when comparing a NaN value with any other value, NaN or not. See the [Compare] function for a consistent way to compare NaN values.

type Table

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

Table is a tournament payout table.

func LoadBytes

func LoadBytes(buf []byte, top float64, name string) (*Table, error)

LoadBytes loads CSV formatted tournament payout table from buf.

func LoadReader

func LoadReader(rdr io.Reader, top float64, name string) (*Table, error)

LoadReader loads a CSV formatted tournament payout table from the reader.

func New

func New(top float64, name string, levels, entries []int, amounts [][]float64) (*Table, error)

New creates a new tournament payout table.

func (*Table) Amount

func (t *Table) Amount(n, entries int) float64

Amount returns the tournament payout amount for position n.

func (*Table) Amounts

func (t *Table) Amounts(start, end, entries int) []float64

Amounts returns the tournament payout amounts for positions for [start, end) as determined by the number of entries.

func (*Table) At

func (t *Table) At(row, col int) float64

At returns the amount at row, col of the tournament payout table.

func (*Table) Entries

func (t *Table) Entries(entries int) int

Entries returns the entries column in the tournament payout table.

func (*Table) EntriesMax

func (t *Table) EntriesMax() int

EntriesMax returns the max entries for the tournament payout table.

func (*Table) EntriesTitle

func (t *Table) EntriesTitle(entries int) string

EntriesTitle returns the column title for the specified entries in the tournament payout table.

func (*Table) Format

func (t *Table) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

func (*Table) Levels

func (t *Table) Levels(start, end int) []int

Levels returns the levels (rows) of the tournament table from [start, end).

func (*Table) LevelsMax

func (t *Table) LevelsMax(entries int) int

LevelsMax returns the max levels for the tournament payout table for the specified entries.

func (*Table) LevelsTitle

func (t *Table) LevelsTitle(n int) string

LevelsTitle returns the level (row) title for rank n in the tournament payout table.

func (*Table) Name

func (t *Table) Name() string

Name returns the name of the tournament payout table.

func (*Table) Payout

func (t *Table) Payout(n, entries int, buyin, guaranteed int64, rake float64) int64

Payout returns the tournament payout for position n.

func (*Table) Payouts

func (t *Table) Payouts(start, end, entries int, buyin, guaranteed int64, rake float64) []int64

Payouts returns the tournament payouts for positions from [start, end) based on the number of entries.

func (*Table) RankingMax

func (t *Table) RankingMax() int

RankingMax returns the max ranking for the tournament payout table.

func (*Table) Rankings

func (t *Table) Rankings(start, end int) []int

Rankings returns the levels for rankings from [start, end).

func (*Table) Stakes

func (t *Table) Stakes(entries int, buyin, guaranteed int64, rake float64) ([][2]int, []float64, []int64)

Stakes returns slice of the ranges of the paid levels in the form of [low, high), table amount, and calculated payouts for each position.

func (*Table) Title

func (t *Table) Title() string

Title returns the title of the tournament payout table.

func (*Table) Top

func (t *Table) Top() float64

Top returns the proportion of paid rankings for the tournament payout table.

func (*Table) WriteCSV

func (t *Table) WriteCSV(w io.Writer) error

WriteCSV writes a CSV version of the tournament payout table to w.

func (*Table) WriteMarkdown

func (t *Table) WriteMarkdown(w io.Writer, header int) error

WriteMarkdown writes a Markdown formatted version of the tournament payout table to w.

func (*Table) WriteTable

func (t *Table) WriteTable(w io.Writer, title bool) error

WriteTable writes a plain text version of the tournament payout table, along with optional title, to w.

func (*Table) WriteTo

func (t *Table) WriteTo(w io.Writer, f func(interface{}, int, bool) string, divider func(int, int) string, early bool) error

WriteTo writes the tournament payout table to w, formatting cells with f, breaking line output when early is true.

type Type

type Type int

Type is a tournament payout table type.

const (
	Top00 Type = iota
	Top10
	Top15
	Top20
)

Top tournament payout table types.

func (Type) Amount

func (typ Type) Amount(n, entries int) float64

Amount returns the tournament payout value for position n.

func (Type) Amounts

func (typ Type) Amounts(start, end, entries int) []float64

Amounts returns the tournament payout amounts for positions for [start, end) as determined by the number of entries.

func (Type) At

func (typ Type) At(row, col int) float64

At returns the amount at row, col of the tournament payout table.

func (Type) Entries

func (typ Type) Entries(entries int) int

Entries returns the entries column in the tournament payout table.

func (Type) EntriesMax

func (typ Type) EntriesMax() int

EntriesMax returns the max entries for the tournament payout table.

func (Type) EntriesTitle

func (typ Type) EntriesTitle(entries int) string

EntriesTitle returns the column title for the specified entries in the tournament payout table.

func (Type) Format

func (typ Type) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

func (Type) Levels

func (typ Type) Levels(start, end int) []int

Levels returns the levels (rows) of the tournament table from [start, end).

func (Type) LevelsMax

func (typ Type) LevelsMax(entries int) int

LevelsMax returns the max levels for the tournament payout table for the specified entries.

func (Type) LevelsTitle

func (typ Type) LevelsTitle(n int) string

LevelsTitle returns the level (row) title for rank n in the tournament payout table.

func (Type) MarshalText

func (typ Type) MarshalText() ([]byte, error)

MarshalText satisfies the encoding.TextMarshaler interface.

func (Type) Name

func (typ Type) Name() string

Name returns the name of the tournament payout table.

func (Type) Payout

func (typ Type) Payout(n, entries int, buyin, guaranteed int64, rake float64) int64

Payout returns the tournament payout for position n.

func (Type) Payouts

func (typ Type) Payouts(start, end, entries int, buyin, guaranteed int64, rake float64) []int64

Payouts returns the tournament payouts for positions from [start, end) based on the number of entries.

func (Type) RankingMax

func (typ Type) RankingMax() int

RankingMax returns the max ranking for the tournament payout table.

func (Type) Rankings

func (typ Type) Rankings(start, end int) []int

Rankings returns the levels for rankings from [start, end).

func (Type) Stakes

func (typ Type) Stakes(entries int, buyin, guaranteed int64, rake float64) ([][2]int, []float64, []int64)

Stakes returns slice of the ranges of the paid levels in the form of [low, high), corresponding tournament payout table amount f, and calculated amount for each position.

func (Type) Title

func (typ Type) Title() string

Title returns the title of the tournament payout table.

func (Type) Top

func (typ Type) Top() float64

Top returns the proportion of paid rankings for the tournament payout table.

func (*Type) UnmarshalText

func (typ *Type) UnmarshalText(buf []byte) error

UnmarshalText satisfies the encoding.TextUnmarshaler interface.

func (Type) WriteCSV

func (typ Type) WriteCSV(w io.Writer) error

WriteCSV writes a CSV version of the tournament payout table to w.

func (Type) WriteMarkdown

func (typ Type) WriteMarkdown(w io.Writer, header int) error

WriteMarkdown writes a Markdown formatted version of the tournament payout table to w.

func (Type) WriteTable

func (typ Type) WriteTable(w io.Writer, title bool) error

WriteTable writes a plain text version of the tournament payout table, along with optional title, to w.

func (Type) WriteTo

func (typ Type) WriteTo(w io.Writer, f func(interface{}, int, bool) string, divider func(int, int) string, early bool) error

WriteTo writes the tournament payout table to w, formatting cells with f, breaking line output when early is true.

Jump to

Keyboard shortcuts

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