-
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
10 changed files
with
236 additions
and
26 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,60 @@ | ||
import PlayingCards as PC | ||
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,25 @@ | ||
import PokerHandEvaluator as PHE | ||
|
||
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
Oops, something went wrong.