整合子模块
This commit is contained in:
@@ -61,13 +61,16 @@ class Atom():
|
||||
"""
|
||||
# eval 环境设置
|
||||
def eval_with_env(s: str):
|
||||
nucleon = self.registry['nucleon']
|
||||
default = config_var.get()["puzzles"]
|
||||
metadata = nucleon.metadata
|
||||
try:
|
||||
nucleon = self.registry['nucleon']
|
||||
default = config_var.get()["puzzles"]
|
||||
metadata = nucleon.metadata
|
||||
except:
|
||||
ret = "尚未链接对象"
|
||||
try:
|
||||
ret = str(eval(s))
|
||||
except:
|
||||
ret = "此 eval 实例发生错误"
|
||||
except Exception as e:
|
||||
ret = f"此 eval 实例发生错误: {e}"
|
||||
return ret
|
||||
|
||||
def traverse(data, modifier):
|
||||
@@ -82,7 +85,10 @@ class Atom():
|
||||
elif isinstance(data, tuple):
|
||||
return tuple(traverse(item, modifier) for item in data)
|
||||
else:
|
||||
return modifier(data)
|
||||
if isinstance(data, str):
|
||||
if data.startswith("eval:"):
|
||||
return modifier(data[5:])
|
||||
return data
|
||||
|
||||
traverse(self.registry["nucleon"], eval_with_env)
|
||||
traverse(self.registry["orbital"], eval_with_env)
|
||||
|
||||
@@ -7,17 +7,23 @@ class Fission():
|
||||
"""裂变器: 单原子调度展开器"""
|
||||
def __init__(self, atom: pt.Atom, phase = PhaserState.RECOGNITION):
|
||||
self.atom = atom
|
||||
self.orbital = atom.registry["orbital"][phase.value]
|
||||
print(self.orbital)
|
||||
self.orbital_schedule = atom.registry["orbital"]["schedule"][phase.value] # type: ignore
|
||||
self.orbital_puzzles = atom.registry["orbital"]["puzzles"]
|
||||
#print(self.orbital_schedule)
|
||||
self.puzzles = list()
|
||||
for item, possibility in self.orbital: # type: ignore
|
||||
for item, possibility in self.orbital_schedule: # type: ignore
|
||||
if not isinstance(possibility, float):
|
||||
possibility = float(possibility)
|
||||
while possibility > 1:
|
||||
self.puzzles.append(puz.puzzles[item])
|
||||
self.puzzles.append({
|
||||
"puzzle": puz.puzzles[self.orbital_puzzles[item]["__origin__"]],
|
||||
"alia": item
|
||||
})
|
||||
possibility -= 1
|
||||
if random.random() <= possibility:
|
||||
self.puzzles.append(puz.puzzles[item])
|
||||
|
||||
self.puzzles.append({
|
||||
"puzzle": puz.puzzles[self.orbital_puzzles[item]["__origin__"]],
|
||||
"alia": item
|
||||
})
|
||||
def generate(self):
|
||||
yield from self.puzzles
|
||||
yield from self.puzzles
|
||||
|
||||
@@ -21,7 +21,8 @@ class Procession():
|
||||
try:
|
||||
self.current_atom = self.queue[self.cursor]
|
||||
return 1 # 成功
|
||||
except IndexError:
|
||||
except IndexError as e:
|
||||
print(f"{e}")
|
||||
return 0
|
||||
|
||||
def append(self, atom = None):
|
||||
|
||||
Reference in New Issue
Block a user