-
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.
227: Add printing of ascii objects r=charleskawczynski a=charleskawczynski Closes #198. Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
- Loading branch information
Showing
12 changed files
with
247 additions
and
34 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
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,61 @@ | ||
import PlayingCards | ||
const PC = PlayingCards | ||
using PlayingCards | ||
|
||
""" | ||
ascii_card(cards...; to_string=true) | ||
ASCII cards. | ||
""" | ||
# ascii_card(cards...; kwargs...) = ascii_card(cards; kwargs...) | ||
function ascii_card(cards::NTuple;to_string=true, rbuffer=" ") | ||
lines = map(enumerate(cards)) do (i, c) | ||
_rbuffer = iseven(i) ? rbuffer : "" | ||
if c isa Card | ||
r = PC.rank_string(PC.rank(c)) | ||
# space = PC.rank(c)==10 ? "" : " " | ||
space = " " | ||
# get the cards suit in two steps | ||
s = string(PC.suit(c)) | ||
l1 = "┌─────────┐$_rbuffer" | ||
l2 = "│$r$space │$_rbuffer" | ||
l3 = "│ │$_rbuffer" | ||
l4 = "│ │$_rbuffer" | ||
l5 = "│ $s │$_rbuffer" | ||
l6 = "│ │$_rbuffer" | ||
l7 = "│ │$_rbuffer" | ||
l8 = "│ $space$(r)│$_rbuffer" | ||
l9 = "└─────────┘$_rbuffer" | ||
l1,l2,l3,l4,l5,l6,l7,l8,l9 | ||
else | ||
["┌─────────┐$_rbuffer", map(x->"│░░░░░░░░░│$_rbuffer", 1:7)..., "└─────────┘$_rbuffer"] | ||
end | ||
end | ||
strs = map(1:9) do j | ||
join( | ||
map(1:length(cards)) do i | ||
getindex(lines[i],j) | ||
end, | ||
"" | ||
) | ||
end | ||
return to_string ? join(strs, "\n") : strs | ||
end | ||
|
||
""" | ||
ascii_card_dealer(cards; to_string=true) | ||
Similar to `ascii_card`, except that it hides | ||
cards of type `card::Nothing`. | ||
""" | ||
function ascii_card_dealer(cards; to_string=true) | ||
all_lines = map(_->"", 1:9) | ||
for card in cards | ||
card_lines = ascii_card((card,); to_string=false, rbuffer="") | ||
all_lines = [x * y for (x, y) in zip(all_lines, card_lines)] | ||
end | ||
card_str = to_string ? join(all_lines, "\n") : all_lines | ||
width = length(all_lines[1]) | ||
height = length(all_lines) | ||
return (card_str, width, height) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import PokerHandEvaluator | ||
const PHE = PokerHandEvaluator | ||
|
||
function ascii_player(table, player, player_cards; to_string=false, rbuffer="") | ||
showdown = table.winners.declared | ||
tm = table.transactions | ||
card_lines = ascii_card(player_cards; to_string, rbuffer) | ||
width = length(card_lines[1]) | ||
net_winnings = showdown ? "Net winnings: $(profit(player, tm))" : "" | ||
hand = if !isnothing(player_cards[1]) && showdown | ||
"$(PHE.hand_type(PHE.CompactHandEval((player_cards..., table.cards...))))" | ||
else | ||
"" | ||
end | ||
info = [ | ||
name(player), | ||
"pot investment: $(pot_investment(player))", | ||
"bank roll: $(bank_roll(player))", | ||
"pot-eligible: $(pot_eligible(player) ? "yes" : "no")", | ||
net_winnings, | ||
hand, | ||
] | ||
lines = [i * repeat(" ", (width - length(i))) for i in info] | ||
lines = vcat(lines, card_lines) | ||
return to_string ? join(lines, "\n") : lines | ||
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.
f9e3fb4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
f9e3fb4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/90528
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: