-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fairly distribute exact deterministic pot remainder
- Loading branch information
1 parent
f6b6ed4
commit 6d413c0
Showing
13 changed files
with
144 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Chips(n, frac) | ||
A stack of chips struct. This type is | ||
backed by `Int`s and performs exact | ||
arithmetic operations by using Rational | ||
numbers to track remainders (fractions | ||
of a chip). `frac` is always internally | ||
stored as less than 1. | ||
Players can only bet/call with whole | ||
chips (`n`), and are not allowed to | ||
bet/call with a fraction of a chip. | ||
We track the fractions of chips so that | ||
we can assert exact money conservation | ||
on the table until a player busts, at which | ||
point, that money is lost. | ||
""" | ||
struct Chips | ||
n::Int | ||
frac::Rational{Int} | ||
function Chips(n::Int, frac::Rational) | ||
if frac ≥ 1 | ||
whole = div(frac.num, frac.den) | ||
r = Rational(rem(frac.num, frac.den), frac.den) | ||
return new(n+whole, r) | ||
else | ||
return new(n, frac) | ||
end | ||
end | ||
end | ||
|
||
Chips(c::Chips) = c | ||
Chips(n::Int) = Chips(n, Rational(0)) | ||
|
||
Base.isless(a::Chips, b::Chips) = Base.isless(a.n+a.frac, b.n+b.frac) | ||
Base.isless(a::Int, b::Chips) = Base.isless(a, b.n+b.frac) | ||
Base.isless(a::Chips, b::Int) = Base.isless(a.n+a.frac, b) | ||
|
||
Base.:(+)(a::Chips, b::Chips) = Chips(a.n+b.n, a.frac+b.frac) | ||
Base.:(-)(a::Chips, b::Chips) = Chips(a.n-b.n, a.frac-b.frac) | ||
Base.:(+)(a::Chips, b::Int) = Chips(a.n+b, a.frac) | ||
Base.:(-)(a::Chips, b::Int) = Chips(a.n-b, a.frac) | ||
|
||
Base.zero(::Type{Chips}) = Chips(0) | ||
Base.zero(::Chips) = Chips(0) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TexasHoldem | ||
using Test | ||
|
||
@testset "Chips" begin | ||
a = Chips(1, 0//1) | ||
b = Chips(2, 3//2) | ||
@test a + b == Chips(4, 1//2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.