User Tools

Site Tools


notes:discrete:fall2023:projects:cgf0

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:cgf0 [2023/09/30 15:47] – [SUITES] wgates1notes:discrete:fall2023:projects:cgf0 [2023/10/05 02:09] (current) – [SUITES] cfoster8
Line 5: Line 5:
 ====VALUES==== ====VALUES====
  
-A standard deck of playing cards has 52 cards from each of the four suits. There are 13 cards in each suit: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King.+A standard deck of playing cards has 52 cards from each of the four suits. 
 +There are 13 cards in each suit: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and King, from lowest to highest value, and then it loops around.
 ====SUITES==== ====SUITES====
  
-The four suits in a standard deck include hearts, diamonds, spades, and clubs.+The four suits in a standard deck include hearts, diamonds, spades, and clubs. Spades and clubs are black colored cards, and hearts and diamonds are red. These make up the sub-classes of card types, beyond just their face value.
  
 ===Structure For Doubly Linked List=== ===Structure For Doubly Linked List===
Line 17: Line 18:
 { {
     bool Active;     bool Active;
-    int Rcard;         // Card id to call for displaying+    int cardID;         // Card id to call for displaying
     cardnode* next;    // Pointer to the next card node     cardnode* next;    // Pointer to the next card node
     cardnode* prev;    // Pointer to the previous card node     cardnode* prev;    // Pointer to the previous card node
Line 24: Line 25:
  
 We originally had just a pointer next for a single linked list but now we have added a pointer for prev. We originally had just a pointer next for a single linked list but now we have added a pointer for prev.
 +
 +===Creating a Doubly-linked List===
 +To create our doubly-linked list, we'll undergo a similar process to how we handled our singly-linked list in ttb1. First, we create the first node in our list, then we append onto it.
 +
 +Creating the first node of the doubly-linked list is almost identical to our previous projects. The only change is that we need to set ''current->prev'' (our pointer to the currently selected node on the list) to ''NULL''. Since this is the first node in our list, ''current->prev'' will always be equal to ''NULL''.
 +
 +Adding additional nodes is where it gets more complicated. Before allocating the memory for the next node and moving the current pointer, we'll need to create a temporary pointer (called ''temp'' in these examples). This will be used to link up ''current->prev'' once we move past the first node. With ''temp'' created, the general order you'll want to follow is:
 +  - Set temp equal to the current pointer
 +  - Allocate the structure memory into ''current->next''.
 +  - Move the current pointer to the next node.
 +  - Use ''temp'' to link back up to ''current->prev''.
 +  - Set ''current->next'' to ''NULL''.
 +  - Free the memory of ''temp''.
 +To create additional nodes, just repeat these steps.
 +
  
 ===Setting Up Buttons=== ===Setting Up Buttons===
Line 47: Line 63:
 if (nextcard) if (nextcard)
 { {
-    // Next card in deck is displayed+    // Next card in the deck is displayed
 } }
 </code> </code>
 +If button "a" is clicked then the next card in the deck is displayed.
 +
 +Alternatively, you can use the arrow keys to do the same thing, reading XDirection or YDirection respectively in place of "a" or "b".
 +
 +==Randomizing Your Deck==
 +
 +To randomize your deck you can use arrays.
 +
 +<code C>
 +int array[a]
 +
 +for (int i = 0; i < a; i++) {
 +     array[i] = i;
 +     }
 +     
 +for (int i = 0; i < a; i++) {
 +     int temp = array[i];
 +     int randomIndex = rand() % 13;
 +     array[i] = array[randomIndex];
 +     array[randomIndex] = temp;
 +}
 +
 +</code>
 +
 +     
notes/discrete/fall2023/projects/cgf0.1696088875.txt.gz · Last modified: 2023/09/30 15:47 by wgates1