def __init__(self, initialState: State = State.GET_HEALTHY_HIVE): self.__pos = None self.__dir = None self.speedRight = 0 self.speedLeft = 0 self.speedRightOld = 0 self.speedLeftOld = 0 self.target = Point(0, 0) self.robotDirTargetHist = deque([180.0] * HIST_QUEUE_LENGTH) self.robotDistTargetHist = deque([math.inf] * HIST_QUEUE_LENGTH) self.targetDistance = 9999 self.targetAngle = 9999 self.state = initialState self.stateOld = initialState self.gameData = None self.stateChanged = False self.pidController = PidController() self.chassis = Chassis()
def create_random_circle(center, radius, quantity, noise): points = [] for i in range(int(quantity)): theta = random.random() * 2 * pi point = Point( cos(theta) * (radius + (random.random() - 0.5) * noise) + center.x, sin(theta) * (radius + (random.random() - 0.5) * noise) + center.y) points.append(point) return points
def circumcenter(point_a, point_b, point_c): """From three points, calculate the circumcenter""" ax = point_a.x ay = point_a.y bx = point_b.x by = point_b.y cx = point_c.x cy = point_c.y d = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) if d == 0: d = 0.1 ux = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / d uy = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / d return Point(ux, uy)
def create_random_point_cloud(number_of_circles, noise, min_val, max_val, points_per_circle): point_cloud = [] solutions = [] val_range = max_val - min_val for i in range(number_of_circles): random_center_x = random.random() * val_range random_center_y = random.random() * val_range random_center = Point(random_center_x, random_center_y) random_radius = random.random() * val_range random_points_per_circle = (random.random() + 0.5) * points_per_circle current_circle = create_random_circle(random_center, random_radius, random_points_per_circle, noise) point_cloud += current_circle solutions.append(Cluster(random_center, random_radius)) res = (point_cloud, solutions) return res
from Entities import Point, Cluster # Ejemplo 1 Point(Dos circunferencias separadas sin intersección) # "Solución" usada para generar los puntos: # Circunferencia de centro Point(9,5) y radio 2 # y Circunferencia de centro Point(2,2) y radio 1 # Lista de puntos: puntos0 = [Point (1,1.1), Point (-1.8,-1.1),Point (-1.5,1.3),Point (1.1,-1)] puntos1 = ([Point(9, 7), Point(7.7, 6.5), Point(7, 5), Point(11, 5), Point(9, 3), Point(10.3, 3.5), Point(7.3, 4), Point(10.3, 6.5), Point(3, 2), Point(2, 3), Point(1, 2), Point(2, 1), Point(1.2, 1.4), Point(1.2, 2.6), Point(2.7, 1.3), Point(2.8, 2.6)], [Cluster(Point(9,5), 2), Cluster(Point(2,2), 1)]) # Ejemplo 2 Point(Dos circunferencias concéntricas # y una tercera separada sin intersección) # "Solución" usada para generar los puntos: # Circunferencia de centro Point(9,5) y radio 2 # Circunferencia de centro Point(9,5) y radio 3 # y Circunferencia de centro Point(20,18) y radio 6 # Lista de puntos: puntos2 = ([Point(9, 8), Point(7, 7.3), Point(6, 5), Point(12, 5), Point(9, 2), Point(11, 2.7), Point(6.4, 3.5), Point(11, 7.2), Point(11, 5), Point(9, 7), Point(7, 5), Point(9, 3), Point(7.4, 3.8), Point(7.4, 6.2), Point(10.4, 3.6), Point(10.6, 6.2), Point(20, 12), Point(20, 24), Point(22, 23.7), Point(24, 22.5), Point(24.4, 22), Point(25.6, 20.1), Point(26, 18), Point(25.6, 16), Point(24.4, 14), Point(24, 13.5), Point(22.1, 12.4), Point(17.9, 12.4), Point(15.9, 13.6), Point(15.2, 14.5), Point(14.3, 16), Point(14, 18), Point(14.4, 20), Point(15.5, 22), Point(16.3, 22.8), Point(25.2, 15), Point(14.8, 15), Point(19, 12.1), Point(23.3, 13), Point(25.9, 19), Point(14.1, 19.2), Point(14.1, 17), Point(15.1, 21.4), Point(17.4, 23.4), Point(18.6, 23.8), Point(21, 23.9), Point(23, 23.2), Point(24.9, 21.4), Point(25.4, 20.6), Point(6.2, 6), Point(6.6, 6.8), Point(8, 7.8), Point(9.9, 7.8), Point(10.5, 7.6), Point(11.2, 7), Point(11.6, 6.6), Point(11.7, 6.3), Point(11.8, 6), Point(11.9, 5.7), Point(12, 4.6), Point(11.9, 4.2), Point(11.8, 3.8), Point(11.6, 3.5), Point(10.5, 2.4), Point(8.2, 2.1), Point(7.4, 2.5), Point(6.1, 4.2), Point(8, 6.7), Point(7.2, 6), Point(7.1, 5.6), Point(7, 4.6), Point(7.1, 4.3), Point(7.7, 3.5), Point(8, 3.3), Point(8.3, 3.1), Point(9.5, 3.1), Point(10.8, 4.2), Point(10.8, 5.9), Point(9.8, 6.8)], [Cluster(Point(9, 5), 2), Cluster(Point(9, 5), 3), Cluster(Point(20, 18), 6)]) puntos2_red = ([Point(10.4, 3.6), Point(10.6, 6.2), Point(20, 12), Point(20, 24), Point(22, 23.7), Point(24, 22.5), Point(24.4, 22), Point(25.6, 20.1), Point(26, 18), Point(25.6, 16), Point(24.4, 14), Point(24, 13.5), Point(22.1, 12.4), Point(17.9, 12.4), Point(15.9, 13.6),
enemyTeamTag = 'team1' else: print('Robot ne tekmuje.') sys.exit(0) print('Robot tekmuje in ima interno oznako "' + homeTeamTag + '"') # ------------------------------------------------------------------------------------------------------------------- # bottomLeft2 = gameState['fields']['baskets']['team1']['bottomRight'] topLeft2 = gameState['fields']['baskets']['team1']['topRight'] topRight2 = gameState['fields']['baskets']['team2']['topLeft'] bottomRight2 = gameState['fields']['baskets']['team2']['bottomLeft'] targetsList = [ Point(bottomLeft2['x'], bottomLeft2['y']), Point(topLeft2['x'], topLeft2['y']), Point(1000, 1500), Point(1100, 1700), Point(1200, 1900), Point(topRight2['x'], topRight2['y']), Point(bottomRight2['x'], bottomRight2['y']) ] print('Seznam ciljnih tock:') for tmpTarget in targetsList: print('\t' + str(tmpTarget)) # ------------------------------------------------------------------------------------------------------------------- # # GLOBAL VARIABLES
enemyTeamTag = 'team1' else: print('Robot ne tekmuje.') sys.exit(0) print('Robot tekmuje in ima interno oznako "' + homeTeamTag + '"') # ------------------------------------------------------------------------------------------------------------------- # bottomLeft2 = gameState['fields']['baskets']['team1']['bottomRight'] topLeft2 = gameState['fields']['baskets']['team1']['topRight'] topRight2 = gameState['fields']['baskets']['team2']['topLeft'] bottomRight2 = gameState['fields']['baskets']['team2']['bottomLeft'] targetList = [ Point(bottomLeft2['x'], bottomLeft2['y']), Point(bottomLeft2['x'], bottomLeft2['y'] + 100), Point(bottomLeft2['x'], bottomLeft2['y'] + 200), Point(bottomLeft2['x'], bottomLeft2['y'] + 300), Point(bottomLeft2['x'], bottomLeft2['y'] + 400), Point(topLeft2['x'], topLeft2['y']), Point(1300, 1500), Point(1400, 1500), Point(1600, 900), Point(1750, 1000), Point(1800, 1100), Point(2100, 1500), Point(2200, 1500), Point(topRight2['x'], topRight2['y']), Point(topRight2['x'], topRight2['y'] - 100), Point(topRight2['x'], topRight2['y'] - 200),