agents and control ""(( , ),( , )linea (( , ),( , )lineb dadb - ax - eaeb - ay - denom db*ea-eb*da if denom== line segments are parallel return false cb (da*( - )-ea*( - ))/denom position along line if cb return false ca (db*( - )-eb*( - ))/denom position along line return <=ca<= test casesassert line_segments_intersect((( , ),( , )),(( , ),( , ))assert not line_segments_intersect((( , ),( , )),(( , ),( , ))assert line_segments_intersect((( , ),( , )),(( , ),( , ))middle layer the middle layer acts like both controller (for the environment layerand an environment for the upper layer it has to tell the environment how to steer thus it calls env do(*it also is told the position to go to and the timeout thus it also has to implement do(*agentmiddle py -middle layer from agents import environment import math class rob_middle_layer(environment)def __init__(self,env)self env=env self percepts env initial_percepts(self straight_angle angle that is close enough to straight ahead self close_threshold distance that is close enough to arrived self close_threshold_squared self close_threshold** just compute it once def initial_percepts(self)return { def do(selfaction)"""action is {'go_to':target_pos,'timeout':timeouttarget_pos is ( ,ypair timeout is the number of steps to try returns {'arrived':truewhen arrived is true or {'arrived':falseif it reached the timeout version june