Skip to content

Commit

Permalink
Restructure, fix deal and split pot logic
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed May 4, 2021
1 parent 1b7bbc3 commit 885ae94
Show file tree
Hide file tree
Showing 14 changed files with 937 additions and 423 deletions.
2 changes: 2 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# API

```@docs
NoLimitHoldem
NoLimitHoldem.move_button!
NoLimitHoldem.play
```
22 changes: 22 additions & 0 deletions src/NoLimitHoldem.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
"""
NoLimitHoldem
A no-limit hold-em simulator.
# Terminology
- `game` a single "game", where players are dealt hands,
winner(s) are declared once.
- `state` a point or process in the game, including
`PreFlop`, `Flop`, `Turn`, `River`.
- `round` the process of each player deciding which
actions to take, until no further actions are taking.
"""
module NoLimitHoldem

using PlayingCards
Expand All @@ -6,8 +19,17 @@ using PokerHandEvaluator.HandTypes
using UnPack
using Printf

export PreFlop, Flop, Turn, River

abstract type AbstractGameState end
struct PreFlop <: AbstractGameState end
struct Flop <: AbstractGameState end
struct Turn <: AbstractGameState end
struct River <: AbstractGameState end

include("player_types.jl")
include("transactions.jl")
include("table.jl")
include("game.jl")
include("player_actions.jl")
include("player_options.jl")
Expand Down
24 changes: 7 additions & 17 deletions src/config_game.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,18 @@ end
function configure_basic_heads_up_game()
bank_roll = 100
blinds = Blinds(1, 2)
deck = ordered_deck()
shuffle!(deck)
players = (
Player(Human(), 1, pop!(deck, 2); bank_roll=bank_roll),
Player(BotRandom(), 2, pop!(deck, 2); bank_roll=bank_roll)
Player(Human(), 1; bank_roll=bank_roll),
Player(BotRandom(), 2; bank_roll=bank_roll)
)
return Game(;
players=players,
deck=deck,
return Game(players;
blinds=blinds,
)
end

function configure_human_players(n_players)
options = string.(1:n_players)
menu = MultiSelectMenu(options; charset=:unicode)
menu = MultiSelectMenu(options) # charset=:unicode is not supported in earlier Julia versions
choices = request("Select which players are human:", menu)
println("$(length(choices)) human players ($(join(sort(collect(choices)), ", ")))")
length(choices) > 0 || println("Menu canceled.")
Expand All @@ -90,21 +86,15 @@ function configure_custom_game()
human_player_ids = configure_human_players(n_players)
bank_roll = cofigure_bank_roll(blinds)

deck = ordered_deck()
shuffle!(deck)
players = ntuple(n_players) do i
if i in human_player_ids
Player(Human(), i, pop!(deck, 2); bank_roll=bank_roll)
Player(Human(), i; bank_roll=bank_roll)
else
Player(BotRandom(), i, pop!(deck, 2); bank_roll=bank_roll)
Player(BotRandom(), i; bank_roll=bank_roll)
end
end

return Game(;
players=players,
deck=deck,
blinds=blinds,
)
return Game(players; blinds=blinds)
end

function configure_game()
Expand Down
Loading

0 comments on commit 885ae94

Please sign in to comment.