paycalc

package
v0.14.9 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 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 entries, buyin, guaranteed, rake = 88, 200000, 10000000, 0.15
	for _, typ := range []paycalc.Type{paycalc.Top10, paycalc.Top15, paycalc.Top20} {
		paid, row, col := typ.Paid(entries)
		fmt.Printf("%t (%d of %d):\n", typ, paid, entries)
		fmt.Printf("  l/e:   %s/%s\n", typ.MaxLevelTitle(paid), typ.EntriesTitle(entries))
		fmt.Printf("  short: %.2f%%\n", typ.Unallocated(paid, row, col)*100.0)
		fmt.Printf("  buyin: %d\n", buyin)
		fmt.Printf("  rake:  %.0f%%\n", rake*100.0)
		fmt.Printf("  gtd:   %d\n", guaranteed)
		fmt.Printf("  prize: %d\n", paycalc.Prize(entries, buyin, guaranteed, rake))
		levels, amounts, payouts, total := typ.Stakes(entries, buyin, guaranteed, rake)
		fmt.Printf("  total: %d\n", total)
		var sum int64
		var gsum, fsum float64
		for i := 0; i < len(levels); i++ {
			title := paycalc.LevelTitle(levels[i][0], levels[i][1])
			g := amounts[i] * float64(levels[i][1]-levels[i][0])
			f := float64(payouts[i]) / float64(total) * float64(levels[i][1]-levels[i][0])
			fmt.Printf("  %5s: %8d (%6.2f%% -> %6.2f%%)\n", title, payouts[i], g*100.0, f*100.0)
			sum, gsum, fsum = sum+payouts[i]*int64(levels[i][1]-levels[i][0]), gsum+g, fsum+f
		}
		fmt.Printf("  Total: %8d (%6.2f%%    %6.2f%%)\n\n", sum, gsum*100.0, fsum*100.0)
	}
}
Output:

Top 10% (9 of 88):
  l/e:   9th/76-100
  short: 2.50%
  buyin: 200000
  rake:  15%
  gtd:   10000000
  prize: 14960000
  total: 14960004
    1st:  4603077 ( 30.00% ->  30.77%)
    2nd:  3068718 ( 20.00% ->  20.51%)
    3rd:  1841231 ( 12.00% ->  12.31%)
    4th:  1457642 (  9.50% ->   9.74%)
    5th:  1227488 (  8.00% ->   8.21%)
    6th:   920616 (  6.00% ->   6.15%)
    7th:   767180 (  5.00% ->   5.13%)
    8th:   613744 (  4.00% ->   4.10%)
    9th:   460308 (  3.00% ->   3.08%)
  Total: 14960004 ( 97.50%    100.00%)

Top 15% (14 of 88):
  l/e:   11-14/76-100
  short: 1.86%
  buyin: 200000
  rake:  15%
  gtd:   10000000
  prize: 14960000
  total: 14960007
    1st:  4344406 ( 28.50% ->  29.04%)
    2nd:  2515183 ( 16.50% ->  16.81%)
    3rd:  1554841 ( 10.20% ->  10.39%)
    4th:  1295701 (  8.50% ->   8.66%)
    5th:  1143265 (  7.50% ->   7.64%)
    6th:   914612 (  6.00% ->   6.11%)
    7th:   762177 (  5.00% ->   5.09%)
    8th:   533524 (  3.50% ->   3.57%)
    9th:   381089 (  2.50% ->   2.55%)
   10th:   381089 (  2.50% ->   2.55%)
  11-14:   283530 (  7.44% ->   7.58%)
  Total: 14960007 ( 98.14%    100.00%)

Top 20% (18 of 88):
  l/e:   16-18/76-100
  short: 2.60%
  buyin: 200000
  rake:  15%
  gtd:   10000000
  prize: 14960000
  total: 14960010
    1st:  4300617 ( 28.00% ->  28.75%)
    2nd:  2611089 ( 17.00% ->  17.45%)
    3rd:  1290185 (  8.40% ->   8.62%)
    4th:  1151951 (  7.50% ->   7.70%)
    5th:   998358 (  6.50% ->   6.67%)
    6th:   844764 (  5.50% ->   5.65%)
    7th:   660452 (  4.30% ->   4.41%)
    8th:   445421 (  2.90% ->   2.98%)
    9th:   399343 (  2.60% ->   2.67%)
   10th:   276469 (  1.80% ->   1.85%)
  11-15:   276469 (  9.00% ->   9.24%)
  16-18:   199672 (  3.90% ->   4.00%)
  Total: 14960010 ( 97.40%    100.00%)
Example (Payouts)
package main

import (
	"fmt"

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

func main() {
	const entries, buyin, guaranteed, rake = 110, 1000, 60000, 0.15
	for _, typ := range []paycalc.Type{paycalc.Top10, paycalc.Top15, paycalc.Top20} {
		paid, _, _ := typ.Paid(entries)
		fmt.Printf("%t (%d of %d):\n", typ, paid, entries)
		payouts, total := typ.Payouts(entries, buyin, guaranteed, rake)
		for i := 0; i < len(payouts); i++ {
			fmt.Printf("   %2d: %5d\n", i+1, payouts[i])
		}
		fmt.Printf("Total: %5d\n\n", total)
	}
}
Output:

Top 10% (11 of 110):
    1: 28581
    2: 17353
    3: 10820
    4:  8779
    5:  7758
    6:  5410
    7:  4390
    8:  3369
    9:  2757
   10:  2144
   11:  2144
Total: 93505

Top 15% (17 of 110):
    1: 27500
    2: 15911
    3:  9134
    4:  7170
    5:  6188
    6:  5206
    7:  4125
    8:  2750
    9:  2063
   10:  1719
   11:  1719
   12:  1719
   13:  1719
   14:  1719
   15:  1719
   16:  1572
   17:  1572
Total: 93505

Top 20% (22 of 110):
    1: 26067
    2: 15930
    3:  7917
    4:  6951
    5:  5986
    6:  5021
    7:  3862
    8:  2607
    9:  2317
   10:  1545
   11:  1545
   12:  1545
   13:  1545
   14:  1545
   15:  1545
   16:  1111
   17:  1111
   18:  1111
   19:  1111
   20:  1111
   21:  1014
   22:  1014
Total: 93511

Index

Examples

Constants

This section is empty.

Variables

View Source
var Epsilon = 0.0000000001

Epsilon is the epsilon value used for for [EpsilonEqual].

View Source
	return int(PaidRound(f * float64(entries)))
}

Paid returns the number of paid rankings, uses PaidRound.

View Source
var PaidRound = math.Ceil

PaidRound by default is math.Ceil and is used by [PaidMax] to determine the number of paid rankings.

View Source
var Precision float64 = 10000

Precision is the precision amount used by Calc.

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

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

Functions

func Calc

func Calc(f float64, total int64, unallocated float64) int64

Calc calculates the amount scaled by unallocated. Uses Round to round to Precision.

func EntriesTitle added in v0.14.1

func EntriesTitle(last, entries int) string

EntriesTitle formats the entries title of last, n.

func Equal added in v0.14.1

func Equal[S, T Ordered](a S, b T) bool

Equal returns true when a and b are within Epsilon.

func EqualEpsilon added in v0.14.1

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

EqualEpsilon 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, level int) string

LevelTitle formats the levels title of last, n.

func Prize added in v0.14.1

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

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

func Register

func Register(typ Type, t *Table) error

Register registers a tournament payout table.

func RegisterBytes

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

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

func RegisterReader

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

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

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(name string, top float64, buf []byte) (*Table, error)

LoadBytes loads CSV formatted tournament payout table from buf.

func LoadReader

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

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

func New

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

New creates a new tournament payout table.

func (*Table) Amount

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

Amount returns the amount for the level and entries from the tournament payout table.

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 column for the entries 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) Level added in v0.14.1

func (t *Table) Level(level int) int

Level returns the row for the level in the tournament payout table.

func (*Table) LevelTitle added in v0.14.1

func (t *Table) LevelTitle(level int) string

LevelTitle returns the row title for the level in the tournament payout table.

func (*Table) MaxLevelTitle added in v0.14.1

func (t *Table) MaxLevelTitle(level int) string

MaxLevelTitle returns the row title for the max level in tournament payout table.

func (*Table) Name

func (t *Table) Name() string

Name returns the name of the tournament payout table.

func (*Table) Paid added in v0.14.1

func (t *Table) Paid(entries int) (int, int, int)

Paid returns the paid rankings, level (row) and corresponding entries column for the tournament payout table.

func (*Table) Payouts

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

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

func (*Table) Stakes

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

Stakes returns the paid levels as [low, high), the tournament table value per level, the calculated payouts per level, and the total amount paid.

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) Unallocated added in v0.14.1

func (t *Table) Unallocated(paid, row, col int) float64

Unallocated returns the unallocated amount for the paid rankings, row, and col from 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(level, entries int) float64

Amount returns the amount for the level and entries from the tournament payout table.

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) Level added in v0.14.1

func (typ Type) Level(level int) int

Level returns the level (row) in the tournament payout table.

func (Type) LevelTitle added in v0.14.1

func (typ Type) LevelTitle(level int) string

LevelTitle 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) MaxLevelTitle added in v0.14.1

func (typ Type) MaxLevelTitle(level int) string

MaxLevelTitle returns the row title for the max level in tournament payout table.

func (Type) Name

func (typ Type) Name() string

Name returns the name of the tournament payout table.

func (Type) Paid added in v0.14.1

func (typ Type) Paid(entries int) (int, int, int)

Paid returns the paid rankings, level (row) and corresponding entries column for the tournament payout table.

func (Type) Payouts

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

Payouts returns the tournament paid rankings.

func (Type) Stakes

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

Stakes returns the paid levels as [low, high), the tournament table value per level, the calculated payouts per level, and the total amount paid.

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) Unallocated added in v0.14.1

func (typ Type) Unallocated(paid, row, col int) float64

Unallocated returns the unallocated amount for the paid rankings, row, and col from 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