def generate_action_list(self): import state_space_search from towers import Towers3 as towers # solve for show (user can click through) subproc = subprocess.Popen(["python", "TowerofHanoi/state_space_search.py"], stdout=subprocess.PIPE) plan = "" while True: try: out = subproc.stdout.read(1) except: break if out == "": break else: plan += out # actually solve to get the plan of actions plan = state_space_search.solve(towers.INIT, towers.GOAL, towers.get_actions()) action_list = [] action_list.extend(ACTIONS_TURN_LEFT_TO_BEGIN) state = copy(towers.INIT) at = towers.Pole1 for (move, what, frm, to) in plan: frm_pole = towers.get_pole(state, frm) to_pole = towers.get_pole(state, to) print what, frm, to, at, frm_pole, to_pole if at != frm_pole: action_list += towers.MOVES[(at, frm_pole)] action_list += towers.CARRY_MOVES[(frm_pole, to_pole)] move(state, what, frm, to) at = to_pole action_list.extend(ACTIONS_CELEBERATE) return action_list
def get_action_queue(self): import state_space_search from towers import Towers3 as towers import subprocess # solve for show (user can click through) subproc = subprocess.Popen(['python', 'BlocksTower/state_space_search.py'], stdout=subprocess.PIPE) plan = '' while True: try: out = subproc.stdout.read(1) except: break if out == '': break else: plan += out # actually solve to get the plan of actions plan = state_space_search.solve(towers.INIT, towers.GOAL, towers.get_actions()) action_queue = ACTIONS_BEGIN state = copy(towers.INIT) at = towers.Pole1 for (move, what, frm, to) in plan: frm_pole = towers.get_pole(state, frm) to_pole = towers.get_pole(state, to) print what, frm, to, at, frm_pole, to_pole if at != frm_pole: action_queue += towers.MOVES[(at, frm_pole)] action_queue += towers.CARRY_MOVES[(frm_pole, to_pole)] move(state, what, frm, to) at = to_pole action_queue.extend(ACTIONS_CELEBERATE) return action_queue
def generate_action_list(self): import state_space_search from towers import Towers3 as towers # solve for show (user can click through) subproc = subprocess.Popen( ['python', 'TowerofHanoi/state_space_search.py'], stdout=subprocess.PIPE) plan = '' while True: try: out = subproc.stdout.read(1) except: break if out == '': break else: plan += out # actually solve to get the plan of actions plan = state_space_search.solve(towers.INIT, towers.GOAL, towers.get_actions()) action_list = [] action_list.extend(ACTIONS_TURN_LEFT_TO_BEGIN) state = copy(towers.INIT) at = towers.Pole1 for (move, what, frm, to) in plan: frm_pole = towers.get_pole(state, frm) to_pole = towers.get_pole(state, to) print what, frm, to, at, frm_pole, to_pole if at != frm_pole: action_list += towers.MOVES[(at, frm_pole)] action_list += towers.CARRY_MOVES[(frm_pole, to_pole)] move(state, what, frm, to) at = to_pole action_list.extend(ACTIONS_CELEBERATE) return action_list
def planner(viewer): solve(Towers3.INIT, Towers3.GOAL, Towers3.get_actions(), viewer=viewer)