def enemy_was_hit_last_turn(self, enemy_ship): last_turn_attack_order = ServiceOrder.get_attack_order( self.last_turn_own_orders) last_turn_attack_position = ServiceOrder.extract_position_from_attack_order( last_turn_attack_order) enemy_ship.enemy_was_in_range( range_detection=1, detection_position=last_turn_attack_position)
def read_opponent_order(self, opponent_order): if opponent_order == "NA": return list_opponent_order = opponent_order.split("|") move_order = ServiceOrder.get_move_order(list_opponent_order) if move_order: self.delta_position = self.delta_position.add_direction( ServiceOrder.get_direction_from_order(move_order)) self.enemy_board.update_enemy_start_position(self.delta_position) self.enemy_board.update_enemy_current_position(self.delta_position) self.update_number_of_possible_positions()
def analyse_opponent_attack_order(enemy_ship, attack_order): attack_position = ServiceOrder.extract_position_from_attack_order( attack_order) enemy_ship.enemy_board.enemy_is_in_range( range_detection=4, attack_position=attack_position) enemy_ship.enemy_board.update_enemy_potential_start_position( enemy_ship.delta_position)
def analyse_enemy_damage(self, enemy_ship): if self.enemy_was_damaged: enemy_has_surface = bool( ServiceOrder.get_surface_order( self.current_turn_opponent_orders)) enemy_has_torpedo = bool( ServiceOrder.get_attack_order( self.current_turn_opponent_orders)) enemy_has_trigger = bool( ServiceOrder.get_trigger_order( self.current_turn_opponent_orders)) own_ship_has_shooted = bool( ServiceOrder.get_attack_order(self.last_turn_own_orders)) if own_ship_has_shooted: if not (enemy_has_surface or enemy_has_torpedo or enemy_has_trigger): self.enemy_was_hit_last_turn(enemy_ship) return # Case first turn elif self.last_turn_own_orders is None: return # Case damage taken but not because of our own torpedo (Surface or enemy torpedo) elif not ServiceOrder.get_attack_order(self.last_turn_own_orders): return # Case I shot a torpedo but did not hit else: attack_order = ServiceOrder.get_attack_order( self.last_turn_own_orders) position_torpedo = ServiceOrder.get_position_from_attack_order( attack_order) enemy_ship.enemy_board.update_board_torpedo_did_not_hit_in_position( position_torpedo, enemy_ship.delta_position)
def read_opponent_order(self, enemy_ship): if self.current_turn_opponent_orders == "NA": return list_orders = ServiceOrder.split_orders( self.current_turn_opponent_orders) for order in list_orders: silence_order = ServiceOrder.get_silence_order(order) if bool(silence_order): self.analyse_opponent_silence_order(enemy_ship) move_order = ServiceOrder.get_move_order(order) if bool(move_order): self.analyse_opponent_move_order(enemy_ship, move_order) surface_order = ServiceOrder.get_surface_order(order) if bool(surface_order): self.analyse_opponent_surface_order(enemy_ship, surface_order) attack_order = ServiceOrder.get_attack_order(order) if bool(attack_order): self.analyse_opponent_attack_order(enemy_ship, attack_order)
from louis.GameClass import Position from louis.Service import ServiceUtils, ServiceMovement, ServiceOrder, ServiceTorpedo # Init global_data, board, ennemy_ship, my_ship = ServiceUtils.init() # game loop while True: # read turn data and update own ship accordingly turn_data = ServiceUtils.read_turn_data() my_ship.update_turn_data(turn_data) # Read and analyse opponent order ennemy_ship.read_opponent_order(turn_data["opponent_orders"]) move_order = ServiceMovement.chose_movement_and_move(my_ship, board) attack_order = ServiceTorpedo.chose_torpedo(my_ship, ennemy_ship) message_order = ServiceOrder.create_number_of_possible_position_order( ennemy_ship) if not move_order: move_order = ServiceMovement.surface(board) orders = ServiceOrder.concatenate_order( [move_order, attack_order, message_order]) ServiceOrder.display_order(orders)
def move_my_ship(ship, direction, board): board.get_cell(position=ship.position).has_been_visited() ship.move(direction) move_order = ServiceOrder.create_move_order(direction) return move_order
def analyse_opponent_move_order(enemy_ship, move_order): enemy_ship.delta_position = enemy_ship.delta_position.add_direction( ServiceOrder.get_direction_from_order(move_order)) enemy_ship.update_potential_position_from_geography()
# game loop while True: # read turn data and analysis turn_data = ServiceUtils.read_turn_data() context_data.update_turn_data(turn_data, enemy_ship, board) my_ship.update_with_turn_data(context_data) enemy_ship.update_with_turn_data(context_data) # Read and analyse opponent order context_data.read_opponent_order(enemy_ship) should_surface = ServiceMovement.should_surface(my_ship, board) if not should_surface: direction_order = ServiceMovement.chose_direction(my_ship, board) locomotion_order = ServiceMovement.chose_locomotion(context_data) move_order = ServiceOrder.concatenate_direction_and_locomotion( direction_order, locomotion_order) recharge_order = ServiceRecharge.chose_recharge(context_data) move_and_recharge_order = ServiceOrder.concatenate_move_and_recharge_order( move_order=move_order, recharge_order=recharge_order) else: move_and_recharge_order = ServiceMovement.surface(board) attack_order = ServiceTorpedo.chose_torpedo(my_ship, enemy_ship) message_order = ServiceOrder.create_number_of_possible_position_order( enemy_ship) orders = ServiceOrder.concatenate_order( [attack_order, move_and_recharge_order, message_order]) ServiceOrder.display_order(orders) context_data.update_end_of_turn_data(orders, enemy_ship)