Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lab 2 informed search task 2
- from searching_framework import *
- class Labirynth(Problem):
- def __init__(self, initial, goal):
- super().__init__(initial, goal)
- def goal_test(self, state):
- g = self.goal
- return state[0][0] == g[0] and state[0][1] == g[1]
- def successor(self, state):
- successors = dict()
- man_x = state[0][0]
- man_y = state[0][1]
- grid_size = state[1]
- obsticles = state[2]
- if man_y < grid_size - 1 and (man_x, man_y + 1) not in obsticles:
- successors['Gore'] = ((man_x, man_y + 1), grid_size, obsticles)
- if man_x > 0 and (man_x - 1, man_y) not in obsticles:
- successors['Levo'] = ((man_x - 1, man_y), grid_size, obsticles)
- if man_y > 0 and (man_x, man_y - 1) not in obsticles:
- successors['Dolu'] = ((man_x, man_y - 1), grid_size, obsticles)
- if man_x < grid_size - 2 and (man_x + 1, man_y) not in obsticles and (man_x + 2, man_y) not in obsticles:
- successors['Desno 2'] = ((man_x + 2, man_y), grid_size, obsticles)
- if man_x < grid_size - 3 and (man_x + 1, man_y) not in obsticles and (man_x + 2, man_y) not in obsticles and (
- man_x + 3, man_y) not in obsticles:
- successors['Desno 3'] = ((man_x + 3, man_y), grid_size, obsticles)
- return successors
- def actions(self, state):
- return self.successor(state).keys()
- def h(self, node):
- man_x = node.state[0][0]
- man_y = node.state[0][1]
- house_x = self.goal[0]
- house_y = self.goal[1]
- return abs(house_y - man_y)/4 + abs(house_x-man_x)/4
- def result(self, state, action):
- possible = self.successor(state)
- return possible[action]
- if __name__ == '__main__':
- n = int(input())
- number_of_blocks = int(input())
- obsticles = []
- i = 0
- while (number_of_blocks > i):
- temp = input().split(',')
- obsticles.append((int(temp[0]), int(temp[1])))
- i += 1
- man_coordinates = input().split(',')
- man_x = int(man_coordinates[0])
- man_y = int(man_coordinates[1])
- man = (man_x, man_y)
- house_coordinates = input().split(',')
- house_x = int(house_coordinates[0])
- house_y = int(house_coordinates[1])
- house = (house_x, house_y)
- labirynth = Labirynth((man, n, tuple(obsticles)), house)
- answer = astar_search(labirynth)
- if answer is None:
- print("NONE")
- else:
- print(answer.solution())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement