]> git.treefish.org Git - shutbox.git/blobdiff - src/game.py
10 rods only
[shutbox.git] / src / game.py
index 04a32e2699a9ea1dcf2137244bdaa2f3c30261dd..203f56a9e31fb09ba9b4651418af1d8287ac7e28 100644 (file)
@@ -1,33 +1,46 @@
-#!/usr/bin/env python3
-
 import random
 
 class Game:
     def __init__(self):
 import random
 
 class Game:
     def __init__(self):
-        self._shutable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
+        self._shutable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
         self._diced = None
         self._options = []
         self._diced = None
         self._options = []
+        self._score = 0
 
     def dice(self):
         if not self._diced:
 
     def dice(self):
         if not self._diced:
-            self._diced = [random.randint(0, 6), random.randint(0, 6)]
-            for rods in [ self._dice,
-                          [ abs(self._dice[0] - self._dice[1]) ],
-                          [ self._dice[0] + self._dice[1] ] ]:
+            self._diced = [random.randint(1, 6), random.randint(1, 6)]
+            self._diced.sort()
+            for rods in [ self._diced,
+                          [ abs(self._diced[0] - self._diced[1]) ],
+                          [ self._diced[0] + self._diced[1] ] ]:
                 if self._can_be_shut(rods):
                     self._options.append(rods)
 
                 if self._can_be_shut(rods):
                     self._options.append(rods)
 
+    def get_diced(self):
+        return self._diced
+
+    def get_shutable(self):
+        return self._shutable
+
+    def get_options(self):
+        return self._options
+
     def shut(self, rods):
         if self._is_valid_option(rods):
             for rod in rods:
     def shut(self, rods):
         if self._is_valid_option(rods):
             for rod in rods:
+                self._score += rod
                 self._shutable.remove(rod)
             self._diced = None
             self._options = []
 
                 self._shutable.remove(rod)
             self._diced = None
             self._options = []
 
-    def is_game_over(self):
+    def is_over(self):
         return len(self._shutable) == 0 or \
             ( self._diced and len(self._options) == 0 )
 
         return len(self._shutable) == 0 or \
             ( self._diced and len(self._options) == 0 )
 
+    def get_score(self):
+        return self._score
+
     def _can_be_shut(self, rods):
         shutable = self._shutable.copy()
         for rod in rods:
     def _can_be_shut(self, rods):
         shutable = self._shutable.copy()
         for rod in rods:
@@ -35,6 +48,7 @@ class Game:
                 shutable.remove(rod)
             else:
                 return False
                 shutable.remove(rod)
             else:
                 return False
+        return True
 
     def _is_valid_option(self, rods):
         for option in self._options:
 
     def _is_valid_option(self, rods):
         for option in self._options: