From cf6bcebf1f8df131bd47e8cfadb7f4b31a5e9383 Mon Sep 17 00:00:00 2001 From: Art-cyber520 Date: Thu, 29 Apr 2021 16:28:43 +0200 Subject: [PATCH] Action-list --- bin/Classess/Node.py | 42 +++++--------- bin/Classess/__pycache__/Node.cpython-38.pyc | Bin 2670 -> 2761 bytes .../__pycache__/Player.cpython-38.pyc | Bin 1911 -> 1911 bytes bin/main/main.py | 54 ++++++++++++------ 4 files changed, 51 insertions(+), 45 deletions(-) diff --git a/bin/Classess/Node.py b/bin/Classess/Node.py index 9a7d4ac..adba2af 100644 --- a/bin/Classess/Node.py +++ b/bin/Classess/Node.py @@ -1,3 +1,6 @@ +from bin.Classess.Player import FRAME_WIDTH, FRAME_HEIGHT + + class Node: def __init__(self): self.state = State() @@ -29,7 +32,7 @@ def successor(state): node_state_right.state.direction = "south" node_state_right.action = "Right" - if state.coord[0] + 53 < 533: + if state.coord[0] + 53 < FRAME_WIDTH: node_state_forward.state = State() node_state_forward.state.coord = [state.coord[0] + 53, state.coord[1]] node_state_forward.state.direction = state.direction @@ -83,7 +86,7 @@ def successor(state): node_state_right.state.direction = "west" node_state_right.action = "Right" - if state.coord[1] + 53 < 533: + if state.coord[1] + 53 < FRAME_HEIGHT: node_state_forward.state = State() node_state_forward.state.coord = [state.coord[0], state.coord[1] + 53] node_state_forward.state.direction = state.direction @@ -95,25 +98,23 @@ def successor(state): return [node_state_left, node_state_right] -def graphsearch(fringe, explored, start_state, end_state_coord): +def graph_search(fringe, explored, start_state, end_state_coord): node = Node() node.state = start_state node.parent = node.state - #node.action = "Right" fringe.append(node) - iter = 0 + iterator = 0 - bool = True - while bool: + end_loop = True + while end_loop: if len(fringe) == 0: - bool = False + end_loop = False #return False - elem = fringe[iter] + elem = fringe[iterator] if elem.state.coord == end_state_coord: - bool = False return fringe explored.append(elem) @@ -126,14 +127,6 @@ def graphsearch(fringe, explored, start_state, end_state_coord): if another_states[i].state.direction == fringe[j].state.direction: break else: - # states = [] - # for k in range(0, len(fringe)): - # new_state = fringe[k].state - # states.append(new_state) - # now_state = another_states[i].state - # if now_state in states: - # break - states = [] for k in range(0, len(fringe)): new_state = [fringe[k].state.coord, fringe[k].state.direction] @@ -142,13 +135,6 @@ def graphsearch(fringe, explored, start_state, end_state_coord): if now_state in states: break - # bool_break = False - # for k in range(0, n): - # if another_states[i].state.coord[0] == fringe[k].state.coord[0] and another_states[i].state.coord[1] == fringe[k].state.coord[1]: - # if another_states[i].state.direction == fringe[k].state.direction: - # bool_break = True - # if bool_break: - # break another_states[i].parent = elem.state fringe.append(another_states[i]) else: @@ -157,11 +143,11 @@ def graphsearch(fringe, explored, start_state, end_state_coord): 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]) - iter += 1 + iterator += 1 diff --git a/bin/Classess/__pycache__/Node.cpython-38.pyc b/bin/Classess/__pycache__/Node.cpython-38.pyc index 06dc08ffbb0c1335a6e845812172251afd6d628b..d1caddce48f6418ce3c933aa54510f5e6ea5d5e3 100644 GIT binary patch delta 1080 zcmZ`&&1=*^6rVSlNhZ77ZLQsEt!v#XmQ|=wkP7t^t=5C}YeiYa?Ya~CwN2VdstA!% zS_M56WsV|v^bhc)Coh5r5icI{AM_%4(2ECsldV<-19_SEe!urQFQ2>K74lcx+A;*6 z8?PTtJS#lO@0>b;nj{jMWDcq@N2?UbSt6;lR*AG$Xw^cENsbyvjY(TNtE9@MkS>00 znYlvB*>w}NOq1-H%O}r|)~=m9T^UPqEoE%<+}W|plZofhrU7mO*Ap{ z!}|0%>*S(`NP~CV=)k1V%d7`UPuXa1CZ;o14J40gjki!FJKIR)=eA|$l4owwIo2DftjOa4L+_o~4R2GWFYI=T| zDWTuQKYZ}>?))42C z4U>C(VV@+pWPChrx^hPC#B$3UO{cB8rhdCVKkxZc?M9{5e94%(s{50kD(C@s?}2JN zGHPK|kGxuIiI^WqFA>v`r|MCls=^SOK`^g#b>j@Km!NhIn&>7n}9Fp4zDB@lB73ou4E zLTB&Zor#GHe}IV#|G?e2GwFtvabaTg%&iYJvB`XMzVqsQXXd`|+38MACX+FOzkT1I zOy#oMsr_egQI^o>*X&_!iXO2BZQqu3uX>2NMfyi>j$6-5?mXFv6tB z5@}~hWJi@K?E)KuxGu93wu@1$(#LpK7~9V1Evp+-KCrRAct9&w2_z3_iFX>9lwN`d z8R31Mf?iW#N2h5DJ zwI=i}+k;j8#vaVC22Ow)D^PI)62v>!0##puEIrbn?aPqRube^tAmTetAGGurdla4- zZ$32M|8!_+%)Z^iIG5}kS>sEGCBfIk$5jS(Ok7hr+zM_-ZX{9|eWKiGcr~f|k#uAa z7&lkt+N`J2y67H)P_MhaaW>!dRLG|5^{Rg94y+f2-z+yhKZJ#%Tk}>*5k<59)BNYr zh4EQcZp`^!Sn`~a(} Bzf}ML diff --git a/bin/Classess/__pycache__/Player.cpython-38.pyc b/bin/Classess/__pycache__/Player.cpython-38.pyc index 1cbd2ac62fd34f7d62cdd08f056fe1f2db215f6b..98cddaa584dd6d5631aaae4a5e40cd600aa5d04a 100644 GIT binary patch delta 20 acmey)_nnVBl$V!_0SIo0b!_C$VFv&^5Ct>< delta 20 acmey)_nnVBl$V!_0SF3gS~ha$umb=&2n6l` diff --git a/bin/main/main.py b/bin/main/main.py index 1215635..85959cb 100644 --- a/bin/main/main.py +++ b/bin/main/main.py @@ -20,8 +20,10 @@ AMOUNT_OF_MINES = 10 # Creating objects player = Player() field = Field() + fringe = [] explored = [] +action_list = [] def Arrow(direction): @@ -162,28 +164,41 @@ def Action(event): # Modified by Artem to search in the status area +def create_action_list(states, index): + global fringe + global action_list + + if index == 0: + action_list.reverse() + return True + action_list.append(fringe[index].action) + state_parent = [fringe[index].parent.coord, fringe[index].parent.direction] + create_action_list(states, states.index(state_parent)) + + def MouseClickEvent(event): global fringe - for i in range(0, len(field.canvas_small_images)): - print(field.small_field_canvas.coords(field.canvas_small_images[i])) + global explored + global action_list start_position = field.small_field_canvas.coords(player.image_canvas_id) - end_state_coord = [] + end_position = [] + print("Pierwsza pozycja: {} {}".format(start_position[0], start_position[1])) for i in range(0, len(field.canvas_small_images)): img_coords = field.small_field_canvas.coords(field.canvas_small_images[i]) if (img_coords[0] <= event.x and event.x <= img_coords[0] + IMAGE_SIZE) and (img_coords[1] <= event.y and event.y <= img_coords[1] + IMAGE_SIZE): - end_state_coord = img_coords - if len(end_state_coord) == 2: - print("Koncowa pozycja: {} {}".format(end_state_coord[0], end_state_coord[1])) + end_position = img_coords + + if len(end_position) == 2: + print("Koncowa pozycja: {} {}".format(end_position[0], end_position[1])) node = nd.Node() if len(fringe) == 0: node.state.coord = start_position node.state.direction = "east" else: - # ZLE - NAPRAWIC states = [] for k in range(0, len(fringe)): new_state = fringe[k].state.coord @@ -196,20 +211,25 @@ def MouseClickEvent(event): fringe.clear() explored.clear() + action_list.clear() - fringe = nd.graphsearch(fringe, explored, node.state, end_state_coord) + fringe = nd.graph_search(fringe, explored, node.state, end_position) states = [] - for k in range(0, len(fringe)): - new_state = [fringe[k].state.coord, fringe[k].state.direction] - states.append(new_state) - for i in range(0, len(states)): - if states[i] in states[i + 1:]: - print("\nDooble element: {}\n".format(states[i])) - - print("\nLista fringe nie zawiera powtorzen!\n") for i in range(0, len(fringe)): - print('Node{} = State: {} {}, Parent: {} {}, Action: {}'.format(i + 1, fringe[i].state.coord, fringe[i].state.direction, fringe[i].parent.coord, fringe[i].parent.direction, fringe[i].action)) + new_state = [fringe[i].state.coord, fringe[i].state.direction] + states.append(new_state) + if end_position[0] == fringe[i].state.coord[0] and end_position[1] == fringe[i].state.coord[1]: + fringe = fringe[:i + 1] + break + + create_action_list(states, -1) + + # for i in range(0, len(fringe)): + # print('Node{} = State: {} {}, Parent: {} {}, Action: {}'.format(i + 1, fringe[i].state.coord, fringe[i].state.direction, fringe[i].parent.coord, fringe[i].parent.direction, fringe[i].action)) + + print(action_list) + def PutMines(mines_array):