solitaire_06.py Diff

solitaire_06.py
--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/2.6.1/doc/tutorials/card_game/solitaire_05.py
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/2.6.1/doc/tutorials/card_game/solitaire_06.py
@@ -1,6 +1,7 @@
 """
 Solitaire clone.
 """
+import random
 import arcade
 
 # Screen title and size
@@ -116,6 +117,8 @@
             pile = arcade.SpriteSolidColor(MAT_WIDTH, MAT_HEIGHT, arcade.csscolor.DARK_OLIVE_GREEN)
             pile.position = START_X + i * X_SPACING, TOP_Y
             self.pile_mat_list.append(pile)
+
+        # --- Create, shuffle, and deal the cards
 
         # Sprite list with all the cards, no matter what pile they are in.
         self.card_list = arcade.SpriteList()
@@ -126,6 +129,12 @@
                 card = Card(card_suit, card_value, CARD_SCALE)
                 card.position = START_X, BOTTOM_Y
                 self.card_list.append(card)
+
+        # Shuffle the cards
+        for pos1 in range(len(self.card_list)):
+            pos2 = random.randrange(len(self.card_list))
+            self.card_list[pos1], self.card_list[pos2] = self.card_list[pos2], self.card_list[pos1]
+
 
     def on_draw(self):
         """ Render the screen. """
@@ -190,7 +199,6 @@
             # Success, don't reset position of cards
             reset_position = False
 
-            # Release on top play pile? And only one card held?
         if reset_position:
             # Where-ever we were dropped, it wasn't valid. Reset the each card's position
             # to its original spot.