Tmoney2020 / assignments

assignments for suncoast developers guild
0 stars 0 forks source link

01 - 03 - All Cards On Deck #3

Closed Tmoney2020 closed 4 years ago

Tmoney2020 commented 4 years ago

In this project, you will use C# to model a deck of playing cards. You'll also add functionality such as shuffling and dealing.

Shuffling Cards

As we have seen, computers do exactly what we tell them to do. Thus, computers are bad at generating truly random numbers. Randomness is a deep and complex topic, but it's worth pointing out that most random numbers we use in computing are what we call "pseudorandom". That is, they generate numbers that appear to be random such that guessing the next random number the computer's fixed algorithm is going to generate is very difficult. This makes it good enough for most purposes. For this assignment, you will read about, then implement, a popular algorithm that shuffles the order of a finite set using C#'s built-in Random.Next() function as a pseudorandom number generator.

Objectives

Requirements

You will model these in code, in any way you see fit. It may require you to experiment and try several techniques. There are many valid solutions.

NOTE: The more you plan this out (focus on the algorithm) the better you will do.

To shuffle the cards, you should implement the Fisher–Yates shuffle algorithm. The shuffling algorithm starts with the last element in our collection (in our case a deck of cards) and swaps it with a randomly selected element that comes before it. This continues downward through the elements towards the first element. Watch the first few minutes of this video for a visual description of the algorithm.

If we were going to write an algorithm for this we would write something like:

make n = 52 since we are dealing with 52 elements

for firstIndex from n - 1 down to 1 do:
  secondIndex = random integer that is greater than or equal to 0 and LESS than firstIndex

  Now swap the values at firstIndex and secondIndex by doing this:
    firstValue = the value from items[firstIndex]
    secondValue = the value from items[secondIndex]
    items[firstIndex] = secondValue
    items[secondIndex] = firstValue

hint: understand the algorithm before you try to implement it.

Explorer Mode

Adventure Mode

Epic Mode

Resources

Tmoney2020 commented 4 years ago

https://github.com/Tmoney2020/cs-loops

Tmoney2020 commented 4 years ago

Your homework 01 - 03 - All Cards On Deck was marked: Meets Expectations

Well done!

“Well done!” — via Gavin Stark