disallow wires with only one edge and discourage empty tiles
Browse files
gen.py
CHANGED
@@ -37,7 +37,17 @@ def isWireConnected(puzzle,x,y):
|
|
37 |
return True
|
38 |
|
39 |
def gettile():
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
def consistent(puzzle,x,y):
|
43 |
if not isWireConnected(puzzle,x,y):
|
@@ -102,6 +112,13 @@ def genpuzzle(w,h=None,seed=0):
|
|
102 |
puzzle[y][x] = gettile()
|
103 |
|
104 |
numsinks = (w*h//10) + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
for _ in range(numsinks):
|
106 |
x = random.randint(0,w-1)
|
107 |
y = random.randint(0,h-1)
|
|
|
37 |
return True
|
38 |
|
39 |
def gettile():
|
40 |
+
while True:
|
41 |
+
tile = (WIRE, [i for i in range(4) if random.random() < 0.4])
|
42 |
+
if len(tile[1]) == 1:
|
43 |
+
if random.random() < 0.2:
|
44 |
+
return (SOURCE, tile[1])
|
45 |
+
elif len(tile[1]) == 0:
|
46 |
+
if random.random() < 0.2:
|
47 |
+
return tile
|
48 |
+
else:
|
49 |
+
return tile
|
50 |
+
|
51 |
|
52 |
def consistent(puzzle,x,y):
|
53 |
if not isWireConnected(puzzle,x,y):
|
|
|
112 |
puzzle[y][x] = gettile()
|
113 |
|
114 |
numsinks = (w*h//10) + 1
|
115 |
+
# add linked sink to each source
|
116 |
+
for y in range(h):
|
117 |
+
for x in range(w):
|
118 |
+
if puzzle[y][x][0] == SOURCE:
|
119 |
+
x2,y2 = reachable(puzzle,x,y)
|
120 |
+
puzzle[y2][x2] = (SINK,puzzle[y2][x2][1])
|
121 |
+
|
122 |
for _ in range(numsinks):
|
123 |
x = random.randint(0,w-1)
|
124 |
y = random.randint(0,h-1)
|