Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with loops in MatLAB Write a MATLAB script (blackjack. m) that plays the dice game Blackjack. The player begins by drawing 2 cards and

Help with loops in MatLABimage text in transcribedimage text in transcribed

Write a MATLAB script (blackjack. m) that plays the dice game Blackjack. The player begins by drawing 2 cards and the computer draws one card, the suit does not matter. The cards are drawn from an infinite deck and are numbered 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, and A. They occur with equal frequency. The cards J, Q, and K all have a value of 10. The card A has a value of 1 or 11 depending on the situation. Your script should display the one card dealt to the computer and the two cards dealt to the player, along with the point total of the two player cards. It then should ask the player if they want an additional card. If yes, then show the three cards and the total. If your total is greater than 21, you lose regardless of what happens. If your total is still less 21, ask if the player wants another card. Remember to check the value of an A and make it 1 if it prevents going over 21. Once the player no longer wants another card, deal a second card to the computer and check its total. If the total is 16 or less, the computer MUST draw another card, if it is 17 or greater it cannot draw another card. If it is 22 or greater the computer loses (unless there is an A in which case the value becomes 1 and the game continues). Once the computer stops drawing cards, your script should print out a message declaring who wins: the computer, the player, or a tie. Advance modification (optional): Card Counting. Rather than play 1 hand, play until 150 cards have been dealt. Keep a running "count" of what has been played. Cards 2-6 are worth 1 point, while 10, J, Q, K, A are worth -1 point. At the end of each hand, ask the player what the deck count is and report how accurate they are, then start the next hand. In general, the higher the total, the more favorable the deck is to the player

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions