Move player defaults into constants.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 17:31:14 +0000 (19:31 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 17:31:14 +0000 (19:31 +0200)
naja/constants.py
naja/gameboard.py
naja/gamestate.py

index d7e023a557700404c32bd63fa156bd6e75afac69..99dd99c97928caa730eec83829d5825c9c56051d 100644 (file)
@@ -36,6 +36,14 @@ BITS = AttrDict({
 DIRECTION_BITS = AttrDict((k, v) for k, v in BITS.items() if v < 4)
 CONDITION_BITS = AttrDict((k, v) for k, v in BITS.items() if v >= 4)
 
+# Player defaults
+PLAYER_DEFAULTS = AttrDict({
+    'INITIAL_BITS': BITS.NORTH | BITS.SOUTH | BITS.EAST | BITS.WEST,
+    'INITIAL_POS': (2, 2),
+    'MAX_HEALTH': 4,
+    'WINS_REQUIRED': 4,
+})
+
 # Game size constants
 TILE_SIZE = (96, 96)
 BOARD_SIZE = (5 * TILE_SIZE[0], 5 * TILE_SIZE[1])
index 5ec61507c7e31a5b10b7c28780b427414e97c462..5728d5d0f28535abfeadcbb5ab3f98c3a24b74b7 100644 (file)
@@ -1,6 +1,7 @@
 from random import choice
 
-from naja.constants import BITS, DIRECTION_BITS, CONDITION_BITS
+from naja.constants import(
+    BITS, DIRECTION_BITS, CONDITION_BITS, PLAYER_DEFAULTS)
 from naja.player import Player
 from naja import actions
 
@@ -20,8 +21,11 @@ class GameBoard(object):
         self.board_locations = board_locations
 
     @classmethod
-    def new_game(cls, initial_bits, initial_pos, max_health, wins_required,
-                 locations_definition):
+    def new_game(cls, locations_definition,
+                 initial_bits=PLAYER_DEFAULTS.INITIAL_BITS,
+                 initial_pos=PLAYER_DEFAULTS.INITIAL_POS,
+                 max_health=PLAYER_DEFAULTS.MAX_HEALTH,
+                 wins_required=PLAYER_DEFAULTS.WINS_REQUIRED):
         state = {
             'max_health': max_health,
             'health': max_health,
index dabf34a9c23311c6302d06242dc2688dce5d50b8..4e892f883ef4cf7ab456a871cda2a13f37c5ca7b 100644 (file)
@@ -2,7 +2,6 @@
 The current game state.
 """
 
-from naja.constants import BITS
 from naja.gameboard import GameBoard
 
 
@@ -11,19 +10,8 @@ class GameState(object):
     Naja game state.
     """
 
-    INITIAL_BITS = (
-        BITS.NORTH | BITS.SOUTH |
-        BITS.EAST | BITS.WEST
-    )
-    MAX_HEALTH = 4
-    WINS_REQUIRED = 4
-
     def __init__(self):
         self.gameboard = GameBoard.new_game(
-            initial_bits=self.INITIAL_BITS,
-            initial_pos=(2, 2),
-            max_health=self.MAX_HEALTH,
-            wins_required=self.WINS_REQUIRED,
             locations_definition=[])  # TODO: we will need some of these :)
 
     @property