Question: Project 1 : Card Dealer CS 2 0 0 2 0 0 Points Total Due Wednesday, December 6 , 2 0 2 3 Objectives Create
Project : Card Dealer
CS Points Total
Due Wednesday, December
Objectives
Create a program to shuffle and deal an array of cards.
Practice IO loops and handling.
Practice array manipulation.
Practice simple subroutine calls.
Overview
Randomizing a deck of cards is different than creating an array of random numbers. With a card
deck, or similar data set, the problem is that each value is unique and cannot be used more than
once. So just choosing a random value wont do The brute force techniques take one card at a
time and fit it into a randomized array, which involves problems dealing with variable length arrays,
finding an empty space in a fixed length array or pick a random card and trying again if it has
already been selected. The latter two techniques end up doing a lot of thrashing as the choices get
fewer and fewer.
Instead, a deceptively easy method has been found to work. Simply iterate through the array and
swap each card with another random card. Some cards wont swap or rather, the random choice to
swap with is the card itself while others may swap to a new spot only to be swapped again when
that spot is iterated to Oddly enough, iterating through the deck once in this way is enough to make
the deck unpredictably shuffled. The more you do it the more time you spend swapping already
shuffled cards, so it is recommended not to do it more than three times.
With this as the background, our task will be to shuffle a deck array of cards and then deal them
out one at a time. The deck can be reshuffled anytime at user request. Use subroutines to do the
shuffle and to draw cards and place them in a discard array. The shuffle routine will need to use
random generation code you modify from the first project. Dont forget to save the $ra register in
the shuffle routine before you call the random routine. More details are in the comments in the
skeleton code I gave you, called dealer.s
Preparation
dealer.s already has the cards and an unshuffled deck defined, as well as some code to initialize the
Cards array and print it out. Im also allowing you to use System Service which returns the time
in $a and date in $a Use $a as your random seed so you dont have to ask the user for it all the
time. Ive already got that code in the skeleton for you. You can use my code to see how to iterate
through an array if you are still getting used to it but be sure to remove the print loop before
submitting your project.
I havent included much pseudocode in the skeleton file. This time, you should make up your own
and then code to that. Otherwise, you might find it difficult to decide how to start coding on this
problem, though I do hope the comments and descriptions will help you.
Requirements
Write a MIPS assembly language program that takes user input ShuffleDraw and Quit You
can use just the letter or the whole word.
On Shuffle, the deck is copied from the Cards array and the discard array is cleared. Current draw
index will be set to by the main program. Shuffle is available any time.
Draw can only be selected if the deck is not empty the program should start with an empty deck
and current draw index set to Draw removes a value from the bottom of the deck array, adds it
to the discard array, and returns the value to the main program so the main program can print the
card. The main program should decrement the index on each draw until it is after which only
Shuffle or Quit may be selected.
On Quit, the program ends and Quit may be selected at any time.
Here are some tips and requirements:
Use the MIPS syscalls to print out prompts and read in characters. There is an example
program that demonstrates the various syscalls in the Supplemental Material section in
Canvas. Do NOT use syscalls higher than with the exception of in this project.
Do NOT use a routine you found online to generate random numbers or use the system
service to get a random number. You must implement the Linear Congruence algorithm
yourself, modified from Project
Start by calling the shuffle routine from main, having it only copy the Cards array and
modifying my print loop to print your copy.
Once that works, try shuffling the array. If that works, the print loop should show the
shuffled deck.
Next clear the discard deck. You can test that code by copying the shuffled deck to the
discard deck, clearing it and then checking that all the values in the discard deck are
With your shuffle routine working, add the IO loop. When draw is called for, simply call
the draw routine, which should just have a couple of lines of code to print a messages like
Drawing a card... Quit should now work.
Now you can implement the draw subroutine. Make sure the selected value by index from
main is removed from the deck. Then make sure it gets written to the discard array.
Finally, be sure it is returned by the s
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
