예제 #1
0
def _a_star_search(initial: Board, depth, admissable=False):
    """
    Breath First Search algorithm. Also shows steps, new states and total states.
    """
    Car.boardWidth = initial.board_width
    Car.boardHeight = initial.board_height
    Board.a_star_depth = depth
    hash_table.states_checked_hash_table = {}
    queue = {}
    star_value = initial.a_star_count(admissable)
    queue[star_value] = [initial]
    print(initial)

    while True:
        best_boards = find_best_boards(queue)
        for best_board in best_boards:
            next_boards = best_board.possible_next_boards()
            for board in next_boards:
                value = board.a_star_count(admissable)
                if value not in queue:
                    queue[value] = [board]
                else:
                    queue[value].append(board)

        BenchMark.steps_made += 1
        print("")
        BenchMark.log_steps_made()
        BenchMark.log_time()
        BenchMark.log_states_count()
예제 #2
0
def breath_search(initial: Board, total_time: int):
    """
    Breath First Search algorithm. Also shows steps, new states and total states.
    """
    hash_table.states_checked_hash_table = {}
    BenchMark.start_the_time()
    Car.boardWidth = initial.board_width
    Car.boardHeight = initial.board_height
    # initial board (stage 0)
    path = []
    path.append([initial])

    hash_table.states_checked_hash_table[hash(initial)] = [initial]

    print("initial state: ")
    print(initial)

    while True:
        nextPath = []
        for board in path[-1]:
            try:
                nextPath.extend(board.possible_next_boards())
            except Win:
                BenchMark.states_count = countPath(path)
                BenchMark.log_steps_made()
                BenchMark.log_time()
                BenchMark.log_states_count()
                return
                # exit(0)


        path.append(nextPath)

        BenchMark.states_count = countPath(path)
        BenchMark.steps_made += 1
        print("")
        BenchMark.log_steps_made()
        BenchMark.log_time()
        BenchMark.log_states_count()


        if len(nextPath) == 0:
            print("States space is explored, no solution found...")
            print("Try freezing less cars.")
            return
        print(time.time() - BenchMark.start_time)
        if (time.time() - BenchMark.start_time) > total_time:
            print("This game is too hard for me! Aborting ....")
            return
예제 #3
0
def breath_search(initial: Board, total_time: int):
    """
    Breath First Search algorithm. Also shows steps, new states and total states.
    """
    hash_table.states_checked_hash_table = {}
    BenchMark.start_the_time()
    Car.boardWidth = initial.board_width
    Car.boardHeight = initial.board_height
    # initial board (stage 0)
    path = []
    path.append([initial])

    hash_table.states_checked_hash_table[hash(initial)] = [initial]

    print("initial state: ")
    print(initial)

    while True:
        nextPath = []
        for board in path[-1]:
            try:
                nextPath.extend(board.possible_next_boards())
            except Win:
                BenchMark.states_count = countPath(path)
                BenchMark.log_steps_made()
                BenchMark.log_time()
                BenchMark.log_states_count()
                return
                # exit(0)

        path.append(nextPath)

        BenchMark.states_count = countPath(path)
        BenchMark.steps_made += 1
        print("")
        BenchMark.log_steps_made()
        BenchMark.log_time()
        BenchMark.log_states_count()

        if len(nextPath) == 0:
            print("States space is explored, no solution found...")
            print("Try freezing less cars.")
            return
        print(time.time() - BenchMark.start_time)
        if (time.time() - BenchMark.start_time) > total_time:
            print("This game is too hard for me! Aborting ....")
            return