Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BlackJack with MATLab: How can I randomize and subtract elements from a main deck for 2 decks? I am required to make a simple text-based

BlackJack with MATLab: How can I randomize and subtract elements from a main deck for 2 decks?

I am required to make a simple text-based blackjack game for my engineering class using MATLab.

I am currently having trouble figuring how to access the card array deck so that a single player and computer will draw and randomly given 2 cards from the main deck. (Which would create/store those values in their own arrays.)

1.) How to initialize the main deck at the start of the program with the names of the cards, number of cards (4 each), and value of cards?

- I am not required to do this specifically for 1., so if you have a better method, feel free to explain.

2.) How to randomize the main deck?

3.) How to pass and decrement the main deck values into the arrays of the player and computer decks?

- This is what I currently have:

%----------------------------------------------------------------------

clear all clear variables clc

player = 1; dealer = 1; funds = 500; mainDeck = {'ONE',4,1; 'TWO',4,2; 'THREE',4,3; 'FOUR',4,4; 'FIVE',4,5; 'SIX',4,6; 'SEVEN',4,7; 'EIGHT',4,8; 'NINE',4,9; 'TEN',4,10; 'JACK',4,10; 'QUEEN',4,10; 'KING',4,10; 'ACE',4,11;}; playerDeck = []; compDeck = []; intro = ('Welcome to Blackjack!'); disp(intro) name = input('Challenger, what is your name? ','s');

while(funds > 0) fprintf('%s, your funds are $%.0f. ', name, funds) inBid = input('What would you like to bid? '); while (inBid > funds) fprintf('You cannot bid more than your funds... ') inBid = input('What would you like to bid? '); end funds = funds - inBid; fprintf('%s, your new funds are $%.0f. ', name, funds); fprintf('Beginning shuffle and draw... ') pause(2); end

%----------------------------------------------------------------------

Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago