def vehicle_off_board(board: Board, vehicle: Vehicle, position, side='both'): if side == 'left' and position.x >= vehicle.position.x: return None vehicle_on_board = vehicle.get_positions(position).intersection( board.positions) == vehicle.get_positions(position) if not vehicle_on_board: print('CANNOT MOVE VEHICLE OFF BOARD') return True
def path_contains_obstacle(vehicle: Vehicle, vehicles: list, new_position: Position): print("{}:{}".format(vehicle.position, new_position)) positions_in_path = set() for p in Path(vehicle.position, new_position).get_vectors(): positions_in_path = positions_in_path.union(vehicle.get_positions(p)) positions_filled_by_other_cars = set() other_vehicles = [v for v in vehicles if v != vehicle] for other_vehicle in other_vehicles: positions_filled_by_other_cars = positions_filled_by_other_cars.union( other_vehicle.positions) if positions_filled_by_other_cars.intersection(positions_in_path): print('PATH IS NOT FREE') return True