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,
35 class LocationCard(object):
37 A particular set of options available on a location.
40 def __init__(self, bitwise_operation, bitwise_operand, actions):
41 self.bitwise_operation = bitwise_operation
42 self.bitwise_operand = bitwise_operand
43 self.actions = actions
46 def generate_location():
47 raise NotImplementedError("TODO")
50 def generate_bitwise_operand():
52 Generate a set of two or three bits. At least one direction and one
53 condition bit will be included. There is a low probability of choosing
54 a third bit from the complete set.
57 bits.add(choice(DIRECTION_BITS.values()))
58 bits.add(choice(CONDITION_BITS.values()))
59 # One in three chance of adding a third bit, with a further one in four
60 # chance that it will match a bit already chosen.
61 if choice(range(3)) == 0:
62 bits.add(choice(BITS.values()))
63 return frozenset(bits)
66 def generate_location_actions():
67 raise NotImplementedError("TODO")
69 def apply_bitwise_operation(self, player):
71 'SET': player.bits.set_bits,
72 'CLEAR': player.bits.clear_bits,
73 'TOGGLE': player.bits.toggle_bits,
74 }[self.bitwise_operation]
75 operator(self.bitwise_operand)
78 class LocationAction(object):
80 An action that may be performed on a location.
83 REQUIRED_BITS = frozenset()
85 def __init__(self, **data):
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")