Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dvizenje_na_covece_desno(x, y, precki):
- if x < 10 and [x+1, y] not in precki:
- x += 1
- return x
- def dvizenje_na_covece_levo(x, y, precki):
- if x > 0 and [x-1, y] not in precki:
- x -= 1
- return x
- def dvizenje_na_covece_pravo(x, y, precki):
- if y < 10 and [x, y+1] not in precki:
- y += 1
- return y
- def dvizenje_na_covece_nazad(x, y, precki):
- if y > 0 and [x, y-1] not in precki:
- y -= 1
- return y
- class Covece(Problem):
- def __init__(self, precki, initial, goal=None):
- super().__init__(initial, goal)
- self.precki = precki
- def successor(self, state):
- successors = dict()
- covece_x = state[0]
- covece_y = state[1]
- tocki_pozicija = state[2]
- y_new = dvizenje_na_covece_pravo(covece_x, covece_y, self.precki)
- if y_new != covece_y:
- successors['ProdolzhiPravo'] = (covece_x, y_new,
- tuple([t for t in tocki_pozicija if t[0] != y_new or t[1] != covece_x]))
- y_new = dvizenje_na_covece_nazad(covece_x, covece_y, self.precki)
- if y_new != covece_y:
- successors['ProdolzhiNazad'] = (covece_x, y_new,
- tuple([t for t in tocki_pozicija if t[0] != y_new or t[1] != covece_x]))
- x_new = dvizenje_na_covece_levo(covece_x, covece_y, self.precki)
- if x_new != covece_x:
- successors['SvrtiLevo'] = (x_new, covece_y,
- tuple([t for t in tocki_pozicija if t[0] != x_new or t[1] != covece_y]))
- x_new = dvizenje_na_covece_desno(covece_x, covece_y, self.precki)
- if x_new != covece_x:
- successors['SvrtiDesno'] = (x_new, covece_y,
- tuple([t for t in tocki_pozicija if t[0] != x_new or t[1] != covece_y]))
- return successors
- def actions(self, state):
- return self.successor(state).keys()
- def result(self, state, action):
- return self.successor(state)[action]
- def goal_test(self, state):
- #prazna torka od tocki
- return len(state[-1]) == 0
- if __name__ == '__main__':
- #sekogas fiksna precki lista
- precki_lista = [[9, 7], [8, 8], [9, 8], [8, 7], [6, 9], [4, 5], [6, 1],
- [8, 4], [0, 6], [4, 6], [5, 1], [9, 4], [0, 8], [4, 7],
- [4, 1], [1, 2], [0, 9], [3, 6], [8, 1], [1, 3], [1, 9],
- [5, 6], [6, 2], [1, 4], [2, 9], [3, 9]]
- covece_x = int(input())
- covece_y = int(input())
- nasokaNaIgracot = str(input())
- brojNaTocki = int(input())
- pomosnaLista =[]
- for x in range(brojNaTocki):
- string = input().split(",")
- pomosnaLista1 = []
- pomosnaLista1.append(int(string[0]))
- pomosnaLista1.append(int(string[1]))
- pomosnaLista.append((tuple(pomosnaLista1)))
- tocki_torka = tuple(pomosnaLista)
- covece = Covece(precki_lista, (covece_x, covece_y, tocki_torka))
- print(breadth_first_graph_search(covece).solution())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement