You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB
Python

import copy
import time
class RobotController(object):
def __init__(self, fire_ext_max_capacity = 5, collision_damage = 1, k_sof = 1, k_cas = 1, k_asset = 1, k_hp = 1, fall_damage = 10):
# STATE VARIABLES
self._fire_ext_max_capacity = fire_ext_max_capacity
self._fire_ext_capacity = self._fire_ext_max_capacity
self._start_hp = 100
self._hit_points = self._start_hp
self._collision_damage = collision_damage
self._charge_points = 100
self._fall_damage = fall_damage
self._collisions = []
self._exted_sofs = []
self._found_casualty = []
self._found_assets = []
self._falls = []
self._k_sof = k_sof
self._k_cas = k_cas
self._k_asset = k_asset
self._k_hp = k_hp
''' CONTROL '''
# speeds in [-1, 1] extra stuff will be cut
def send_speed_cmd(self, v, w):
v = min(max(-1, v), 1)
w = min(max(-1, w), 1)
return v, w
def send_fire_ext_burst_cmd(self):
if self._fire_ext_capacity > 0:
self._fire_ext_capacity -= 1
return True
return False
# poses in [-1, 1] extra stuff will be cut
def send_fire_ext_pose_cmd(self, horisontal_pose, vertical_pose):
horisontal_pose = min(max(-1, horisontal_pose), 1)
vertical_pose = min(max(-1, vertical_pose), 1)
return horisontal_pose, vertical_pose
def send_pick_asset_cmd(self):
raise NotImplemented("")
def get_score(self, time_stamp = None):
score = self._k_sof * len(self._exted_sofs) + self._k_cas * len(self._found_casualty) + self._k_asset * len(self._found_assets) + self._k_hp * self._hit_points
return score
def get_str_status(self):
status = f"{type(self).__name__}\n - Total score {self.get_score()}\n - Hit points: {self._hit_points}/{self._start_hp}\n - Extingushed sources of fire {len(self._exted_sofs)}\n - Fire extinguiher capacity {self._fire_ext_capacity}/{self._fire_ext_max_capacity}\n - Collisions {len(self._collisions)}\n - Falls {len(self._falls)}"
return status
def send_lights_cmd(self):
pass
def send_fall_reset_cmd(self):
pass
''' EVENTS '''
def _register_collision(self, time_stamp):
self._collisions.append(time_stamp)
self._hit_points = max(0, self._hit_points - self._collision_damage)
def _register_exted_sof(self, time_stamp, sof_params = {}):
self._exted_sofs.append((time_stamp,
copy.deepcopy(sof_params)))
def _register_found_casualty(self, time_stamp, casualty_params = {}):
self._found_casualty.append((time_stamp,
copy.deepcopy(casualty_params)))
def _register_found_assest(self, time_stamp, asset_params = {}):
self._found_assets.append((time_stamp,
copy.deepcopy(asset_params)))
def _register_fall(self, time_stamp):
self._falls.append(time_stamp)