- def correct_arm(arm):
- if arm < 0:
- arm += CIRCLE
- return arm
-
- def in_shadow_cone(new_cone):
- for old_cone in self.shadow_cones:
- if old_cone[0] >= new_cone[0] and \
- new_cone[1] >= old_cone[1]:
- #print('DEBUG shadowed by:', old_cone)
- return True
- return False
-
- def merge_cone(new_cone):
- for old_cone in self.shadow_cones:
- if new_cone[0] > old_cone[0] and \
- new_cone[1] <= old_cone[0]:
- #print('DEBUG merging to', old_cone)
- old_cone[0] = new_cone[0]
- #print('DEBUG merged cone:', old_cone)
- return True
- if new_cone[1] < old_cone[1] and \
- new_cone[0] >= old_cone[1]:
- #print('DEBUG merging to', old_cone)
- old_cone[1] = new_cone[1]
- #print('DEBUG merged cone:', old_cone)
- return True
- return False
-
- def eval_cone(cone):
- new_cone = [left_arm, right_arm]
- #print('DEBUG CONE', cone, '(', step_size, distance_to_center, number_steps, ')')
- if in_shadow_cone(cone):
- return
- self[yx] = '.'
- if self.source_map[yx] != '.':
- #print('DEBUG throws shadow', cone)
- unmerged = True
- while merge_cone(cone):
- unmerged = False
- if unmerged:
- self.shadow_cones += [cone]
-
- #print('DEBUG', yx)
- step_size = (CIRCLE/4)/distance_to_center
- number_steps = dir_i * distance_to_center + dir_progress
- left_arm = correct_arm(-(step_size/2) - step_size*number_steps)
- right_arm = correct_arm(left_arm - step_size)
- if right_arm > left_arm:
- eval_cone([left_arm, 0])
- eval_cone([CIRCLE, right_arm])
- else:
- eval_cone([left_arm, right_arm])
-
- def circle_out(self, yx, f):
-
- def move(pos, direction):
- """Move position pos into direction. Return whether still in map."""
- mover = getattr(self, 'move_' + direction)
- pos[:] = mover(pos)
- if pos[0] < 0 or pos[1] < 0 or \
- pos[0] >= self.size[0] or pos[1] >= self.size[1]:
- return False
- return True
-
- directions = (('DOWN', 'LEFT'), ('LEFT', 'UP'),
- ('UP', 'RIGHT'), ('RIGHT', 'DOWN'))
- circle_in_map = True
- distance = 1
- yx = yx[:]
- #print('DEBUG CIRCLE_OUT', yx)
- while circle_in_map:
- circle_in_map = False
- move(yx, 'RIGHT')
- for dir_i in range(len(directions)):
- for dir_progress in range(distance):
- direction = directions[dir_i]
- move(yx, direction[0])
- if move(yx, direction[1]):
- f(yx, distance, dir_i, dir_progress)
- circle_in_map = True
- distance += 1