From 4a2696bd8901712b7262bccf756ae4fba48011a0 Mon Sep 17 00:00:00 2001 From: Art-cyber520 Date: Tue, 27 Apr 2021 14:15:48 +0200 Subject: [PATCH] Graphsearch and successor - perhaps they work right, but we have to check it --- bin/Classess/Node.py | 71 +++++++++---------- bin/Classess/__pycache__/Node.cpython-38.pyc | Bin 2481 -> 2670 bytes bin/main/main.py | 20 ------ 3 files changed, 32 insertions(+), 59 deletions(-) diff --git a/bin/Classess/Node.py b/bin/Classess/Node.py index 2382c11..9a7d4ac 100644 --- a/bin/Classess/Node.py +++ b/bin/Classess/Node.py @@ -22,90 +22,77 @@ def successor(state): node_state_left.state = State() node_state_left.state.coord = state.coord node_state_left.state.direction = "north" - #node_state_left.parent = state node_state_left.action = "Left" node_state_right.state = State() node_state_right.state.coord = state.coord node_state_right.state.direction = "south" - #node_state_right.parent = state node_state_right.action = "Right" - node_state_forward.state = State() - node_state_forward.state.coord = [state.coord[0] + 53, state.coord[1]] - node_state_forward.state.direction = state.direction - #node_state_forward.parent = state - node_state_forward.action = "Up" - - #return [node_state_left, node_state_right, node_state_forward] + if state.coord[0] + 53 < 533: + node_state_forward.state = State() + node_state_forward.state.coord = [state.coord[0] + 53, state.coord[1]] + node_state_forward.state.direction = state.direction + node_state_forward.action = "Up" elif state.direction == "west": node_state_left.state = State() node_state_left.state.coord = state.coord node_state_left.state.direction = "south" - #node_state_left.parent = state node_state_left.action = "Left" node_state_right.state = State() node_state_right.state.coord = state.coord node_state_right.state.direction = "north" - #node_state_right.parent = state node_state_right.action = "Right" - node_state_forward.state = State() - node_state_forward.state.coord = [state.coord[0] - 53, state.coord[1]] - node_state_forward.state.direction = state.direction - #node_state_forward.parent = state - node_state_forward.action = "Up" - - #return [node_state_left, node_state_right, node_state_forward] + if state.coord[0] > 3: + node_state_forward.state = State() + node_state_forward.state.coord = [state.coord[0] - 53, state.coord[1]] + node_state_forward.state.direction = state.direction + node_state_forward.action = "Up" elif state.direction == "north": node_state_left.state = State() node_state_left.state.coord = state.coord node_state_left.state.direction = "west" - #node_state_left.parent = state node_state_left.action = "Left" node_state_right.state = State() node_state_right.state.coord = state.coord node_state_right.state.direction = "east" - #node_state_right.parent = state node_state_right.action = "Right" - node_state_forward.state = State() - node_state_forward.state.coord = [state.coord[0], state.coord[1] - 53] - node_state_forward.state.direction = state.direction - #node_state_forward.parent = state - node_state_forward.action = "Up" - - #return [node_state_left, node_state_right, node_state_forward] + if state.coord[1] > 3: + node_state_forward.state = State() + node_state_forward.state.coord = [state.coord[0], state.coord[1] - 53] + node_state_forward.state.direction = state.direction + node_state_forward.action = "Up" elif state.direction == "south": node_state_left.state = State() node_state_left.state.coord = state.coord node_state_left.state.direction = "east" - #node_state_left.parent = state node_state_left.action = "Left" node_state_right.state = State() node_state_right.state.coord = state.coord node_state_right.state.direction = "west" - #node_state_right.parent = state node_state_right.action = "Right" - node_state_forward.state = State() - node_state_forward.state.coord = [state.coord[0], state.coord[1] + 53] - node_state_forward.state.direction = state.direction - #node_state_forward.parent = state - node_state_forward.action = "Up" + if state.coord[1] + 53 < 533: + node_state_forward.state = State() + node_state_forward.state.coord = [state.coord[0], state.coord[1] + 53] + node_state_forward.state.direction = state.direction + node_state_forward.action = "Up" - #return [node_state_left, node_state_right, node_state_forward] - - return [node_state_left, node_state_right, node_state_forward] + if len(node_state_forward.state.coord) != 0: + return [node_state_left, node_state_right, node_state_forward] + else: + return [node_state_left, node_state_right] def graphsearch(fringe, explored, start_state, end_state_coord): @@ -126,7 +113,6 @@ def graphsearch(fringe, explored, start_state, end_state_coord): elem = fringe[iter] if elem.state.coord == end_state_coord: - print("Gotowe!") bool = False return fringe @@ -166,8 +152,15 @@ def graphsearch(fringe, explored, start_state, end_state_coord): another_states[i].parent = elem.state fringe.append(another_states[i]) else: - if another_states[i] in fringe: + states = [] + for k in range(0, len(fringe)): + new_state = [fringe[k].state.coord, fringe[k].state.direction] + states.append(new_state) + now_state = [another_states[i].state.coord, another_states[i].state.direction] + if now_state in states: break + # if another_states[i] in fringe: + # break if another_states[i].state.direction == fringe[j].state.direction: another_states[i].parent = elem.state fringe.append(another_states[i]) diff --git a/bin/Classess/__pycache__/Node.cpython-38.pyc b/bin/Classess/__pycache__/Node.cpython-38.pyc index dc862e5548ac9614ecb7c291c6769c09efab2fb6..06dc08ffbb0c1335a6e845812172251afd6d628b 100644 GIT binary patch delta 1059 zcma))&1(}u6u{@bnVtQ}rmab%NuzC{P>8mOAXGhhs2`__wiOSSR@oZdNNBf<7MaCE z4i*m@GX4ST!K?P_*`pv{^B35Q;8hR$W}9vZt>7;E_I=Fz&6{~|xAtg|@TgLI+;5_C zHs!`r@sNk21%YgE%1{avDqiP{%xHC7WC2@bwY>fP zx4`sbPI~bwJ$q3Qq&E*9B>#aIp$G52nQGHRb(eiR^ZS_hcyE4|4vYDn39(gCOn8jEJ=-8{!!InPX;nL6{(nn9XRY|gB(yaB%q!n|bFqDvLOa9W01s%kFL zM>e0Ans&Sss5)nbdw8$W%%VYrS%V~&v zf}FIRmVfXYrWq{U-_t^eRcuqokNhf*Nl%P-ZZu;>c*=&3VL znig~pt18&42GGAaKL2!ORg-#B=eiv4&6YjId=N8@;fX>MhaXsc>^YlT4Xu7{h&)z( zo1}jKdW8L`^A%OW<~_RmEV#FwZ11+Nsv7R=QrS5x-v*9h#5a4rRveAIr>$5`Tg30F zCvl=?%}n^7ZzHnvz