예제 #1
0
__author__ = 'Andreas'
import astar
import checkers_problem

f = open('checkers.txt', 'r')
world = []
for line in f:
    line = line.strip().split(',')
    world.append(line)

print(world)

g_file = open('checkers_goal.txt', 'r')
goal = []
for line in g_file:
    line = line.strip().split(',')
    goal.append(line)

print(goal)
prob = checkers_problem.Problem(goal_state=goal, initial_state=world)
solution = astar.cost_search(prob)
print(solution)
예제 #2
0
queue = prique.Frontier()
heuristic = True

if ALGORITHM_TYPE == "d":
    # -- Dijkstra -- Priority queue and no heuristic
    queue = prique.Frontier()
    heuristic = False
elif ALGORITHM_TYPE == "b":
    # -- BFS -- FIFO queue and no heuristic
    queue = prique.BfsQueue()
    heuristic = False

# Create problem file:
prob = pathfind_problem.Problem((goal_x, goal_y), (start_x, start_y), world, heuristic)
# Call search algorithm
solution, frontier, visited = astar.cost_search(prob, queue)

# Create image
board_gen = board_image_gen.Board_img_gen(len(world[0]), len(world), 50)
# Draw world
board_gen.draw_world(world)
# Draw visited nodes
board_gen.draw_open_closed(visited, "x")
# Draw open nodes
board_gen.draw_open_closed([node.state for node in frontier.h], "o")

# Reconstruct the path taken to goal, by going backwards from parent to parent
parent = solution.parent
path = []

while parent.parent: