def test_yield_on_death_leaves_attacker_in_tokyo(main_player, other_players): player_a = other_players[0] player_a.location = Locations.OUTSIDE player_a.current_health = 1 main_player.location = Locations.TOKYO dice_resolution(MOCK_DICE_VALUES, main_player, other_players) assert main_player.location == Locations.TOKYO
def test_roll_energy_updates_player(): player = Player() other_players = [Player(), Player()] starting_energy = player.energy dice = [ DieValue.ENERGY, DieValue.ENERGY, DieValue.ENERGY, DieValue.ENERGY, DieValue.ENERGY, DieValue.ENERGY ] dice_resolver.dice_resolution(dice, player, other_players) assert player.energy == starting_energy + 6
def resolve_dice_handler(self, data): username, room, game, state = reconstruct_game(data) self.send_to_client( SERVER_RESPONSE, username, room, "{} locked in dice".format(state.players.current_player.username)) dice_resolution( state.dice_handler.dice_values, state.players.get_current_player(), state.players.get_all_alive_players_minus_current_player()) self.update_player_status(state, username, room, game) self.trigger_yield_popup_if_necessary(state, room)
def run_game(game_state, verbose=False): game_state.start_game() turn_counter = 1 start_player = game_state.players.current_player while game_state.is_game_active(): current_player = game_state.players.current_player if verbose: print(f"\n{current_player.username} Turn {turn_counter}") # Tell the game to do initial turn actions such as the required first roll game_state.start_turn_actions(current_player) # Print what current player rolled if verbose: print( f"{current_player.username} rolled {game_state.dice_handler.dice_values}" ) # Select what dice to re-roll as long as there are allowed re-rolls # (Press enter to select nothing) while game_state.dice_handler.re_rolls_left != 0: if verbose: print(f"{current_player.username} has \ {game_state.dice_handler.re_rolls_left} re-rolls left") # Get what user selected to re-roll if issubclass(type(current_player), Master_AI_Player): to_re_roll = current_player.choose_dice_to_re_roll( game_state.dice_handler.dice_values, verbose=verbose) else: to_re_roll = current_player.choose_dice_to_re_roll( game_state.dice_handler.dice_values) # log what was chosen if verbose: print(f"{current_player.username} rerolls {to_re_roll}") # tell game state to perform re-roll game_state.re_roll(to_re_roll) if verbose: print(f"{current_player.username} \ rolled {game_state.dice_handler.dice_values}") # Give a chance for real player to hit enter to continue, AI just returns current_player.acknowledge() # Game state acts on the resulting dice (heals, attacks, et) dice_resolution( game_state.dice_handler.dice_values, current_player, game_state.players.get_all_alive_players_minus_current_player()) # TODO: there is currently no opportunity to buy/use cards # Give everyone a chance to yield tokyo if they can for player in game_state.players.get_all_alive_players_minus_current_player( ): if player.allowed_to_yield and player.decide_to_yield(): game_state.yield_tokyo_to_current_player(player) # Checks if anyone has won and give chance for special card actions game_state.post_roll_actions(game_state.players.current_player) # Advance the game to the next active player (also resets some states) game_state.get_next_player_turn() # Increment turn counter if back at starting player if game_state.players.current_player == start_player: turn_counter += 1 return game_state.winner
def test_yield_on_death_moves_attacker_from_outside_to_tokyo(main_player, other_players): player_a = other_players[0] player_a.location = Locations.TOKYO player_a.current_health = 1 dice_resolution(MOCK_DICE_VALUES, main_player, other_players) assert main_player.location == Locations.TOKYO
def test_yield_on_death_causes_death(main_player, other_players): player_a = other_players[0] player_a.location = Locations.TOKYO player_a.current_health = 1 dice_resolution(MOCK_DICE_VALUES, main_player, other_players) assert not player_a.is_alive
def test_first_attack_roll_does_not_hurt_anyone(main_player, other_players): dice_resolution(MOCK_DICE_VALUES, main_player, other_players) assert all(others.current_health == DEFAULT_HEALTH for others in other_players)
def test_first_attack_roll_forces_move_to_tokyo(main_player, other_players): dice_resolution(MOCK_DICE_VALUES, main_player, other_players) assert main_player.location == Locations.TOKYO
def test_resolve_dice_and_heal(hurt_player): initial_health = hurt_player.current_health dice_resolution(MOCK_DICE_RESULTS, hurt_player) assert hurt_player.current_health == initial_health + MOCK_DICE_RESULTS.count( DieValue.HEAL)