Interactions between lasers, targets and sources are prettier.

This commit is contained in:
Niels Serup
2012-08-13 21:42:46 +02:00
parent 7713fbaf98
commit c402c342b8
6 changed files with 151 additions and 62 deletions

View File

@@ -160,13 +160,16 @@ def generate_lasers(playfield):
sources = ((pos, obj.direction) for pos, obj
in filter(lambda posobj: isinstance(posobj[1], Source),
playfield.items()))
lasers = []
lasers, lasers_flat = [], set()
def add(start, end):
t = (min(start, end), max(start, end))
if not t in lasers:
lasers.append(t)
if not t in lasers_flat:
laser.append(t)
lasers_flat.add(t)
for start, direc in sources:
end = start
laser = []
lasers.append(laser)
while True:
cur = playfield.get(end)
if cur is Target:
@@ -176,7 +179,7 @@ def generate_lasers(playfield):
add(start, end)
break
if cur in (MirrorLeft, MirrorRight):
if (start, end) in ((start, end) for (start, end), direc in lasers):
if (start, end) in ((start, end) for (start, end), direc in lasers_flat):
break
add(start, end)
direc = _mirror_new_direc(cur, direc)