def test_player_presence(self): circuit = Circuit() circuit._listOfPlayersOccupying[TestCircuit.player] = 10 self.assertTrue( circuit._check_if_player_is_an_occupant(TestCircuit.player)) self.assertFalse( circuit._check_if_player_is_an_occupant(TestCircuit.false_player))
def test_circuit_boundary(self): circuit = Circuit() circuit.set_maximum_number_of_players(2) circuit.player_moves(TestCircuit.player, 1) circuit.player_moves(TestCircuit.player, 95) self.assertEqual(circuit.player_moves(TestCircuit.player, 5), 96) self.assertEqual(circuit.player_moves(TestCircuit.player, 1), 97) self.assertEqual(circuit.player_moves(TestCircuit.player, 3), 100)
class Arena: def __init__(self): self.game_name = "Snakes" self.dice: Dice = None self.configs: CR = CR() self.configs.parse() self.history: GameHistory = None self.player_queue: CircularQueue = None self.player_count = 2 self.circuit = None self.player_set = [] def prepare_arena(self): """ Instantiate and initialize all tools :return: None """ self._set_dice(self.configs.get_dice_type(), self.configs.get_dice_count()) self.history = GameHistory() self._create_player_list() self._set_player_queue(self.player_set, self.player_count) self._set_circuit() self.circuit.set_entry_criterion(1) self._set_link_map(self.configs.get_link_list()) def _set_dice(self, dice_type, dice_count): if dice_type == "dice" and dice_count == 1: self.dice = Dice(Dice.CONFIG_SINGLE_DIE) elif dice_type == "dice" and dice_count == 2: self.dice = Dice(Dice.CONFIG_DOUBLE_DIE) elif dice_type == "shell" and dice_count == 1: self.dice = Dice(Dice.CONFIG_HALF_SET_SHELL) elif dice_type == "shell" and dice_count == 2: self.dice = Dice(Dice.CONFIG_FULL_SET_SHELL) else: raise IllegalStateException("Undefined dice behaviour configured") def _set_player_queue(self, player_list, max_player_count=2): self.player_queue = CircularQueue(max_player_count) for player in player_list: self.player_queue.push_new_player(player) def _set_circuit(self, max_player_count=2): self.circuit = Circuit() self.circuit.set_maximum_number_of_players(max_player_count) def _create_player_list(self, player_count=2): for n in range(0, player_count): self.player_set.append(Player()) def _set_link_map(self, link_map: list): link_map_dict = {} for x, y in link_map: link_map_dict[x] = y self.circuit.set_cell_link_map(link_map_dict) def get_last_roll(self): """ reads the roll value from the previous roll :return: last roll value """ if self.dice is None: raise IllegalStateException("dice is not et created") if self.dice.last_roll is None: raise IllegalStateException("dice not rolled yet") return self.dice.last_roll def get_dice_roll(self): """ rolls the dice and returns the value :return: """ if self.dice is None: raise IllegalStateException("dice is not et created") if self.dice.last_roll is None: raise IllegalStateException("dice not rolled yet") return self.dice.roll() def roll_event_triggered(self, count: int): """ triggers roll event receives the dice roll gets the current player from queue and assigns new position and pushes the player back to the queue creates a history event and pushes it into the history stack :return: None """ current_player: CircularQueue.QueueContainer = self.player_queue.get_next_player( ) old_position = current_player.player.position_in_circuit new_position = self.circuit.player_moves(current_player.player, count) current_player.player.position_in_circuit = new_position self.player_queue.complete_transaction() event = HistoryEvent(old_position, new_position, current_player) self.history.push_event_to_history(event) def get_player_set(self): """ called by HMI to get reference of all player objects :return: [players... ] """ if len(self.player_set) == 0: raise IllegalStateException("player set not yet prepared") return self.player_set
def _set_circuit(self, max_player_count=2): self.circuit = Circuit() self.circuit.set_maximum_number_of_players(max_player_count)
def test_branching(self): circuit = Circuit() circuit.set_cell_link_map({10: 25}) circuit.set_maximum_number_of_players(2) circuit.player_moves(TestCircuit.player, 1) self.assertEqual(circuit.player_moves(TestCircuit.player, 9), 25)
def test_update_existing_player(self): circuit = Circuit() circuit.set_maximum_number_of_players(2) circuit.player_moves(TestCircuit.player, 1) self.assertEqual(circuit.player_moves(TestCircuit.player, 10), 11)
def test_entryCondition(self): circuit = Circuit() circuit.set_maximum_number_of_players(2) self.assertEqual(circuit.player_moves(TestCircuit.player, 1), 1)
def test_max_count(self): circuit = Circuit() with self.assertRaises(Exception): circuit.player_moves(TestCircuit.player, 1)
def test_update_non_existing_player(self): circuit = Circuit() self.assertEqual(circuit.player_moves(TestCircuit.player, 10), -1)