User Tools

Site Tools


notes:discrete:fall2023:projects:bjm0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:discrete:fall2023:projects:bjm0 [2023/10/26 20:21] – [GAMEPLAY] wgates1notes:discrete:fall2023:projects:bjm0 [2023/11/02 01:53] (current) – [Ace Logic] cfoster8
Line 22: Line 22:
 In past documentation pages we implemented a way to shuffle cards but that way made it hard/impossible to assign values to your cards. This way fixes that. We are still using the same logic but are calling more arrays in the Fisher-Yates shuffle algorithm. In past documentation pages we implemented a way to shuffle cards but that way made it hard/impossible to assign values to your cards. This way fixes that. We are still using the same logic but are calling more arrays in the Fisher-Yates shuffle algorithm.
  
 +The following 2 arrays are needed:
 +<code C>
 +// Values to be assigned to each card
 +int[52] cardValues = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
 +                      2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
 +                      2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
 +                      2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11};
 +
 +
 +// All cards before they are randomized
 +int[52] cardOrder = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
 +                     16,17,18,19,20,21,22,23,24,25,26,27,28,
 +                     29,30,31,32,33,34,35,36,37,38,39,40,41,
 +                     42,43,44,45,46,47,48,49,50,51,52};
 +</code>
 +
 +Once you have created your arrays you will want to make the following for loop:
 +<code C>
 +// Fisher-Yates shuffle algorithm
 +for (int i = 51; i > 0; i--)
 +{
 +    // Generate a random index between 0 and i
 +    int j = rand() % (i + 1);
 +
 +    // Swaps cardOrder[i] and cardOrder[j], cardValues[i] and cardValues[j]
 +    int temp = cardOrder[i];
 +    int temp2 = cardValues[i];
 +    cardOrder[i] = cardOrder[j];
 +    cardValues[i] = cardValues[j];
 +    cardOrder[j] = temp;
 +    cardValues[j] = temp2;
 +}
 +</code>
  
 +In this version of the shuffle, we also shuffle the card values making it so they still line up and are assigned correctly. This version does not include suits but you can also do the same thing. Create an array of numbers 0-3. the numbers represent a suit so heart could be 0, diamond as 1, spade as 2, and clubs as 3.
 ====Ace Logic==== ====Ace Logic====
 One of the unique aspects of Black Jack is that an Ace can either be 11 or 1 depending on what the player decides. Here is an example of a hand involving an Ace. One of the unique aspects of Black Jack is that an Ace can either be 11 or 1 depending on what the player decides. Here is an example of a hand involving an Ace.
Line 60: Line 94:
  
  
 +====Dealer Strategy====
  
 +The dealer in blackjack always hits until hitting at least 17, and goes after the player does. A simple way of doing this is to out a check for if the player stands or busts towards the end of the loop, and set a flag if they do.
  
 +    if(stand == true || playerbust == true){}
 + 
 +Next you need a check to see if the dealer's cards already add up to 17 or greater, and if not then have them draw a card. You repeat this until the dealer has the correct value of cards, check if they bust or not, and if not then compare it to the player.
 =====CHANCES===== =====CHANCES=====
  
notes/discrete/fall2023/projects/bjm0.1698351664.txt.gz · Last modified: 2023/10/26 20:21 by wgates1