def handle(state: Control, map_size=(0, 0)): state.Play_handle = True pygame.init() display = Display(title='Bloxorz Game', map_size=map_size) result = True print("Press Space Key to Exit!") while True: # os.system("clear") for event in pygame.event.get(): if state.Play_handle: if event.type == pygame.KEYDOWN and event.key == pygame.K_UP: result = state.move_up() elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: result = state.move_down() elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: result = state.move_right() elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: result = state.move_left() if display.quit(event): return state.draw_maps() state.draw_box() # state.print_maps() display.update() if state.check_goal(): print("WINNER!") return if result == False: print("LOSER!") return
def bfs_path(state: Control): stack = [ [state.start], ] while state.stack: current_state, current_maps = state.stack.pop(0) path = stack.pop(0) state.visted.append((current_state, current_maps)) for move in state.moves: state.set_state(current_state, current_maps) if move(): if state.check_goal(): result = path + [state.current] return result stack.append(path + [state.current]) return None