修复 5 个 bug + 3 项稳定性改进
Bug 修复: - server.py: shutdown/close 顺序修正,加 OSError 保护 - world.py: from dataclasses import Field → from world.commons.field import Field - walk.py: execute() 末尾补 return False - field.py: _resolve_side 根据 is_left_team 动态映射 our/their(修复右队区域判断反向) - math_ops.py: 三个硬编码球门坐标函数加 NotImplementedError 防误用 稳定性改进: - server.py: 连接重试加 time.sleep(1.0) 防 CPU 空转 - world_parser.py + math_ops.py: bare except → except Exception/AttributeError - world_parser.py: 球速计算加 EMA 滤波 (α=0.4) 降低视觉噪声
This commit is contained in:
@@ -5,7 +5,7 @@ import sys
|
||||
|
||||
try:
|
||||
GLOBAL_DIR = sys._MEIPASS # temporary folder with libs & data files
|
||||
except:
|
||||
except AttributeError:
|
||||
GLOBAL_DIR = "."
|
||||
|
||||
|
||||
@@ -286,22 +286,10 @@ class MathOps():
|
||||
@staticmethod
|
||||
def intersection_segment_opp_goal(a: np.ndarray, b: np.ndarray):
|
||||
''' Computes the intersection point of 2d segment 'ab' and the opponents' goal (front line) '''
|
||||
vec_x = b[0] - a[0]
|
||||
|
||||
# Collinear intersections are not accepted
|
||||
if vec_x == 0: return None
|
||||
|
||||
k = (15.01 - a[0]) / vec_x
|
||||
|
||||
# No collision
|
||||
if k < 0 or k > 1: return None
|
||||
|
||||
intersection_pt = a + (b - a) * k
|
||||
|
||||
if -1.01 <= intersection_pt[1] <= 1.01:
|
||||
return intersection_pt
|
||||
else:
|
||||
return None
|
||||
raise NotImplementedError(
|
||||
"intersection_segment_opp_goal uses hardcoded x=15 / y=±1.01. "
|
||||
"Refactor to accept field dimensions before use."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def intersection_circle_opp_goal(p: np.ndarray, r):
|
||||
@@ -309,34 +297,18 @@ class MathOps():
|
||||
Computes the intersection segment of circle (center p, radius r) and the opponents' goal (front line)
|
||||
Only the y coordinates are returned since the x coordinates are always equal to 15
|
||||
'''
|
||||
|
||||
x_dev = abs(15 - p[0])
|
||||
|
||||
if x_dev > r:
|
||||
return None # no intersection with x=15
|
||||
|
||||
y_dev = sqrt(r * r - x_dev * x_dev)
|
||||
|
||||
p1 = max(p[1] - y_dev, -1.01)
|
||||
p2 = min(p[1] + y_dev, 1.01)
|
||||
|
||||
if p1 == p2:
|
||||
return p1 # return the y coordinate of a single intersection point
|
||||
elif p2 < p1:
|
||||
return None # no intersection
|
||||
else:
|
||||
return p1, p2 # return the y coordinates of the intersection segment
|
||||
raise NotImplementedError(
|
||||
"intersection_circle_opp_goal uses hardcoded x=15 / y=±1.01. "
|
||||
"Refactor to accept field dimensions before use."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def distance_point_to_opp_goal(p: np.ndarray):
|
||||
''' Distance between point 'p' and the opponents' goal (front line) '''
|
||||
|
||||
if p[1] < -1.01:
|
||||
return np.linalg.norm(p - (15, -1.01))
|
||||
elif p[1] > 1.01:
|
||||
return np.linalg.norm(p - (15, 1.01))
|
||||
else:
|
||||
return abs(15 - p[0])
|
||||
raise NotImplementedError(
|
||||
"distance_point_to_opp_goal uses hardcoded x=15 / y=±1.01. "
|
||||
"Refactor to accept field dimensions before use."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def circle_line_segment_intersection(circle_center, circle_radius, pt1, pt2, full_line=True, tangent_tol=1e-9):
|
||||
|
||||
Reference in New Issue
Block a user