-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyberpuzze.py
70 lines (54 loc) · 1.84 KB
/
cyberpuzze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from utils.graph_utils import Dungeon
from utils.color_utils import (
color_red,
)
class Cyber(Dungeon):
def _dungeonstart(self):
"""Generat the initial layout of the dungeon"""
sv = self._g.vs[0]
gv = self._g.vs[1]
self._insert_room_btw(sv, gv, "ENTRANCE")
return
def _rv_processor(self, rv):
func = {
"ENTRANCE": self._generate_ENTRANCE,
}.get(rv["type"], None)
if func is None:
return None
return func(rv)
def _process(self):
"""Main graph processor
Tries to substitute every red vertex with the correspondent sequence.
Finishes after 200 iterations or if the graph has 1 000 vertices
"""
missing_gram = set()
while True:
self._niter += 1
# get all the red vertices
# self.plot_dungeon(debug=True)
red_vertices = self._g.vs.select(color_eq=color_red, reviewed_eq=False)
if not red_vertices:
break
rv = red_vertices[0]
rv["reviewed"] = True
status = self._rv_processor(rv)
if status is None:
missing_gram.add(rv["type"])
if self._g.vcount() > self._maxnode or self._niter > self._maxiter:
break
if missing_gram:
self.logger.error(f"Missing grammar for {missing_gram}")
return
def _generate_ENTRANCE(self, rv):
"""Entrance
Arguments
rv int: Reference vertex
"""
voi = self._g.neighbors(rv, "in")[0]
vdi = self._g.neighbors(rv, "out")[0]
roll = (self.d100 % 6)+1
self.logger.debug(f"ROLL: {roll}")
for _ in range(roll):
fn = ln = self._insert_room_btw(voi, vdi, "E")
self._remove_room(rv, fn, ln)
return