Black jack function for hiding dealers card

2 views (last 30 days)
I have the game pretty much completed. its a text based version of blackjack just focusing on random integers since suits dont really matter.
I need a function to store the hole card, display an empty string (ex: __ / 9 / 2) and then display the value once the player "stays".
Thank you!

Accepted Answer

Benjamin
Benjamin on 1 Dec 2021
I'll assume the dealer's cards are stored as an array with the hole card being first. Then here's a function that takes two input arguments: (1) dealer's card array, (2) a logical indicating whether to hide the hole card, and returns a character array representing the cards:
function str = get_str(d,do_hide)
d = num2cell(d);
str = sprintf('%2d / ',d{:});
str(end-2:end) = [];
if do_hide
str([1 2]) = '_';
end
end

More Answers (1)

Image Analyst
Image Analyst on 1 Dec 2021
Wouldn't that be sprintf() or fprintf()?
  2 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!