1 from random import choice
3 from naja.constants import BITS, DIRECTION_BITS, CONDITION_BITS
6 class GameBoard(object):
8 A representation of the game board.
11 def __init__(self, player, health, wins, locations=None, state=None):
13 self.max_health = health
14 self.wins_required = wins
17 locations = self.generate_locations()
18 self.locations = locations
21 state = self.generate_state()
22 self.update_state(state)
25 def generate_locations(cls):
26 raise NotImplementedError("TODO")
28 def generate_state(self):
30 'health': self.max_health,
34 def update_state(self, state):
35 self.health = state['health']
36 self.wins = state['wins']
38 def lose_health(self):
40 # TODO: Check win/lose
43 class LocationCard(object):
45 A particular set of options available on a location.
48 def __init__(self, bitwise_operand, actions):
49 self.bitwise_operand = bitwise_operand
50 self.actions = actions
53 def generate_location():
54 raise NotImplementedError("TODO")
57 def generate_bitwise_operand():
59 Generate a set of two or three bits. At least one direction and one
60 condition bit will be included. There is a low probability of choosing
61 a third bit from the complete set.
64 bits.add(choice(DIRECTION_BITS.values()))
65 bits.add(choice(CONDITION_BITS.values()))
66 # One in three chance of adding a third bit, with a further one in four
67 # chance that it will match a bit already chosen.
68 if choice(range(3)) == 0:
69 bits.add(choice(BITS.values()))
70 return frozenset(bits)
73 def generate_location_actions():
74 raise NotImplementedError("TODO")
77 class LocationAction(object):
79 An action that may be performed on a location.
84 def __init__(self, required_bits, **data):
85 self.required_bits = required_bits
88 def check_available(self, player):
89 return player.bits.check_bits(self.required_bits)
91 def perform_action(self, player, board):
92 raise NotImplementedError("TODO")
94 def check_and_clear_MSB(self, player):
95 if player.bits.check_bit(BITS.MSB):
96 player.bits.clear_bit(BITS.MSB)