Files
Function/aufgaben/einstellung/pr_aufgaben/klötzchenwelt_07.py
T

34 lines
778 B
Python

from functools import reduce
def is_clear(state, block):
return all([v != block for v in state.values()])
def move(block, target):
def action(state):
if not is_clear(state, block):
raise ValueError(f"Auf Block {block} liegt etwas!")
if target != "_" and not is_clear(state, target):
raise ValueError(f"Block {target} ist nicht frei!")
new_state = state.copy()
new_state[block] = target
return new_state
return action
def chain(f, g):
return lambda state: g(f(state))
identity = lambda state: state
start = {"A": "B", "B": "_", "C": "_", "D": "C"}
goal = {"A": "_", "B": "C", "C": "_", "D": "B"}
actions = [
move("A", "_"),
move("D", "_"),
move("B", "C"),
move("D", "B"),
]