Added preliminary level 4. No lasers yet.

This commit is contained in:
Niels Serup
2012-08-11 02:22:29 +02:00
parent 5904d29aef
commit b61f54963d
8 changed files with 199 additions and 30 deletions

View File

@@ -19,8 +19,8 @@
#
# lasermirror.py
# --------------------
# date created : Tue Aug 7 2012
# copyright : (C) 2012 Niels G. W. Serup
# date created : Tue Aug 7 2016
# copyright : (C) 2016 Niels G. W. Serup
# maintained by : Niels G. W. Serup <ns@metanohi.name>
"""
@@ -33,6 +33,7 @@ import random
import itertools
from robotgame.logic.direction import *
import robotgame.logic.rollingstone as rstone
from robotgame.logic.rollingstone import Blocker
import robotgame.misc as misc
class Mirror(object):
@@ -46,12 +47,12 @@ class Target(object):
def generate_simple_playfield(nmirrors):
"""
Generate a completable 12x12 playfield where:
Generate a completable 16x16 playfield where:
* there are four laser sources, one in each corner
+ the one in the upper left corner (0, 0) starts in (0, -1) heading down
+ the one in the upper right corner (11, 0) starts in (12, 0), heading left
+ the one in the lower right corner (11, 11) starts in (11, 12), heading up
+ the one in the lower left corner (0, 11) starts in (-1, 11), heading right
+ the one in the upper right corner (15, 0) starts in (16, 0), heading left
+ the one in the lower right corner (15, 15) starts in (15, 16), heading up
+ the one in the lower left corner (0, 15) starts in (-1, 15), heading right
* there are four laser targets
* there are nmirrors mirrors
* there are nmirrors levers
@@ -59,14 +60,14 @@ def generate_simple_playfield(nmirrors):
Return playfield : {(x, y): Target | Mirror | rstone.Blocker | Lever}
"""
playfield = {(4, 4): Target,
(7, 4): Target,
(4, 7): Target,
(7, 7): Target,
(5, 5): rstone.Blocker,
(5, 6): rstone.Blocker,
(6, 5): rstone.Blocker,
(6, 6): rstone.Blocker,
playfield = {(6, 6): Target,
(9, 6): Target,
(6, 9): Target,
(9, 9): Target,
(7, 7): rstone.Blocker,
(7, 8): rstone.Blocker,
(8, 7): rstone.Blocker,
(8, 8): rstone.Blocker,
}
succs = lambda d: d
source_direc = Up
@@ -75,23 +76,21 @@ def generate_simple_playfield(nmirrors):
nm = nmirrors / missing
nmirrors -= nm
stone_playfield, _ = rstone.generate_simple_playfield(
5, 5, nm, 0, False, False)
7, 7, nm, 0, False, False)
for pos, direc in stone_playfield.items():
if direc is not None and pos >= (0, 0):
playfield[_adjust(source_direc, 12 - 1, 12 - 1, *pos)] = Mirror
playfield[_adjust(source_direc, 16 - 1, 16 - 1, *pos)] = Mirror
succs = (lambda s: lambda d: succ(s(d)))(succs)
source_direc = succ(source_direc)
occup = set(playfield.keys())
emptys = list(
set([(0, y) for y in filter(lambda y: (1, y) not in occup, range(12))]
+ [(11, y) for y in filter(lambda y: (10, y) not in occup, range(12))]
+ [(x, 0) for x in filter(lambda x: (x, 1) not in occup, range(12))]
+ [(x, 11) for x in filter(lambda x: (x, 10) not in occup, range(12))])
- occup)
if len(emptys) < nlevers:
raise Exception("Not enough space for all levers!")
for pos in misc.pick_random_elements(emptys, nlevers):
for _ in range(nlevers):
# This needs to be optimized...
occup = set(playfield.keys())
emptys = list(
set([(0, y) for y in filter(lambda y: (1, y) not in occup, range(16))]
+ [(15, y) for y in filter(lambda y: (10, y) not in occup, range(16))]
+ [(x, 0) for x in filter(lambda x: (x, 1) not in occup, range(16))]
+ [(x, 15) for x in filter(lambda x: (x, 10) not in occup, range(16))]) - occup)
pos = emptys[random.randrange(len(emptys))]
playfield[pos] = Lever
return playfield

View File

@@ -123,7 +123,7 @@ def generate_simple_playfield(width, height, nturns, nstones,
break
else:
allowed = set(range(0, height)) - set(not_allowed_y)
if missing == 3:
if missing <= 3:
allowed -= set((height - 1,))
if missing == nturns:
allowed -= set((0,))