From 1d717acefac6bbea658b41bc2840d68448bf7cc2 Mon Sep 17 00:00:00 2001 From: Justyna Wojsz Date: Fri, 14 May 2021 14:52:55 +0200 Subject: [PATCH] a star --- container/__pycache__/a_star.cpython-37.pyc | Bin 0 -> 2678 bytes container/__pycache__/agent.cpython-37.pyc | Bin 0 -> 3285 bytes container/__pycache__/board.cpython-37.pyc | Bin 1571 -> 5136 bytes container/__pycache__/constans.cpython-37.pyc | Bin 339 -> 467 bytes container/__pycache__/mushroom.cpython-37.pyc | Bin 0 -> 1144 bytes container/__pycache__/node.cpython-37.pyc | Bin 0 -> 728 bytes container/__pycache__/piece.cpython-37.pyc | Bin 633 -> 741 bytes container/__pycache__/tree.cpython-37.pyc | Bin 0 -> 632 bytes container/a_star.py | 87 ++++++++++++++++++ container/board.py | 33 ++++++- container/node.py | 15 +++ main.py | 25 ++++- 12 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 container/__pycache__/a_star.cpython-37.pyc create mode 100644 container/__pycache__/agent.cpython-37.pyc create mode 100644 container/__pycache__/mushroom.cpython-37.pyc create mode 100644 container/__pycache__/node.cpython-37.pyc create mode 100644 container/__pycache__/tree.cpython-37.pyc create mode 100644 container/a_star.py create mode 100644 container/node.py diff --git a/container/__pycache__/a_star.cpython-37.pyc b/container/__pycache__/a_star.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a53134c7aa2d5cf5f4a2fc1e53d9cf0a10826f0 GIT binary patch literal 2678 zcmZuz&5s<#6|ax}nw}5OE+0E_2yrYDF^Cu>P!ti%vH~)v?8OG7(V}JCRl7T1-Q%iW zXB<^uvX;dKDF-AjC|X~TB5_1f{+2$1gfO`vam$I{tDgPHiXPRgSMR-gRrNmS&)sgy z@cnoB&yPOqGWHEEPCg0bCWg%c6jOZ87JS4x;bJZpawI)2=fNTzg&q&)(IOtj9uMcq zqBUv(k5v4KjZ&4U7Us4NRr)zsZPj@cj5?~TdZ2dICDq5=QyaJ0aPuk7WJ6wu_lmJm zK!WW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Pe7a)C c>AI-*mI*#CBJoLt9dOiTMXHYSmnEfAKdl3C9smFU delta 222 zcmcc2e3^;QiI*OJR*-PhpGVNMQ_S&}4rJGQ=-)4-*5!OZJJAb(2|v{2~yc$$5*dpfWu% zH}w{4xTi~q$1OGwS5J43kXtN4{^7y5*q!}-LVf*$Z*d0)hB^kh#s_;wxkj%2`=tcEcz7XrWNLf!#Ikr9<-#AIIz z>6}mq;L6?!842k@Am4g#4$Ph|icC{*e>InYu>*jDGmaN9%vS(O8xoR+O14cvqoDCt zV-1HjZv>#IoT+=-lcMq(c1*X3bhgMDp6oYVe>k_gORP-tEsX1fU)>NvroQYwAPjaS zfpop0#@n^2&N1J5BQEkPN^+&g+4)7xIIG2=%qR8cGGm#||AGW7R^(BpERT!Sa$Ou+ zw=5D<z)zyr zVfynpemH(_ls4m3$)p&+RA#>_%5e#0FA%3{zq)6V@&D-#%9-`TFv*iD43P=52|%bz zefV7J@*OJ34)X!)>kBFeixV+c3k8q%VYEbk1EnETAX74!=`FGj&32nW>4AW4SbYI9 zr);TRw06YCGlS;3m+OKq!o83ZZ)-iFEsZ@T0KTA7{Mxyjx1Z;v!fPZb<7_Vy(JnCO*cLHIrUNpg=#J8;(y5pU@)?X6LdXKss Np5T*cBd$`9{R5A*2qpjk literal 0 HcmV?d00001 diff --git a/container/__pycache__/node.cpython-37.pyc b/container/__pycache__/node.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b33928f7073e5bb74b8f23a0521d2d80393773f8 GIT binary patch literal 728 zcmZvZzmC)}5XQ%Uk_~&eLgE1sC26*xUD*g$r3cFy)m+$kOV98@&C z3XkBHikgm!ndI(-5EISMU!2(EZ~SbtSp&w`@yomK4B!X7+=M`JiW%-9UV#S94w#>L z4Vu4(Qgk?f8xqwiX1I?qP%{lR*DEcwJg{2mOy>uvrDnLYNV0O;R6p@o=vG7w8ad{3 z%y3>mZ@bt#n`Gxg zELTYeGrafY%+rB=M#u?N-4}>&;Hf9SA9p9s+hBZX2BUk|yf9%O-PnxYIY-=?eS8r5 zrgJv7y*0kEXlgrNrb4OS_E9M+6pj(V^4sTXL*}%qN?H^6B z;}hHQ{h|eGajhk4Nt!xK_cC`xRBv9ESz7m@w;{H+Gaj!O{&8M%e+Oq%=Hf@=XWI*o zXf{{MoGV2-P>X)S1&41L&M(?w`QoV` o{w{&~{1>Rwd`#Lg(ESu_UCc98$rc0uS(1t;OQol@?iVKf0Z+r1SpWb4 literal 0 HcmV?d00001 diff --git a/container/__pycache__/piece.cpython-37.pyc b/container/__pycache__/piece.cpython-37.pyc index dc89133bb314eed45880d40a35c451c509a810f5..bc840f0af22605ce26b0fc82e2cca199bcfe7296 100644 GIT binary patch literal 741 zcmYjPy>8S%5T5<9<6Lskgd&K7g2qiAAVMetB&beEh~{KzG2Xps9iMG>9UXUacXF@BZi4ngRT!&A|kcD|G)HL4#%uEa3xa zuEiZ_vFA&s*=NY*1IA%d5gv>qxkC3Z5Def+SaQuYzk{XFLQ7nwPB1$S$tPT zt>o{}{VN2`Mo=(f@;M-5$V6mV5cfg@HL(cbZ~}NB$Yqdixi&#mT@!@sHbL0+bF00Gpi#N^}jnTF%-Wz{2bbZmguImVEb2Gg3wy3&xC~a$8(Nn`0 z{WfGu+13t9C0NO42*6S{!)Ny-PIYlOP?4Hsv>v0!@jfCM**y%b=J#TRS`NvGW1YjE zMTR5q*^2+-7)z(f8H!LJA;;JmP>kW%K?%en3g9Fb&9flCHFgMTzr7|Qjt5t^e$}~k zNPJZ`#!Ejj_Q(Bo~Fromc}6{RG|9XKV%nW&t9Tlw%`A zE&=I5dX|Ka8~yBfsp~8rPwdcWJ$9>=y}G*|Dx(taLaXX~Lv0Q9e+ARS@Ud6!=Qmav zo7YNKIzLtRvD0nd8a+~v-HxsDQa4>uHOk~ItvP64Tr5P@RGkpi%Ek!5dj6SicrAmk z3nhL^uc7%cuvUQlZTfC2DhMLi$**JVn|GmObqf=-6Td0ldZVKLomr9{NU3M z46yvtv)Cwq&p9@aE7uKW-C17@lsJsIQH#D?WocAh+1e;8*F@>v_c-a-E8a=!wp`h$ z8dsVq!{DQ=+f^o`3by$g<%M4R8Oh&*KcMN?tLk;}IanWx#+up{A8a@qTwnCwImdWv z&xU8AF8-}%(XV5wb=}p2*4%-R5&%wcN@FwURxS4NWrpLsGR1eeaINE1>(-g`hWSkE zZ|7yRi}*(*G#2+4JmfuY5dVG<1SyW|OyviEN?Y{&x1PhE>)ExG-}#?ZOyBI1zvWg3 J7M)=#egpigkyZcz literal 0 HcmV?d00001 diff --git a/container/a_star.py b/container/a_star.py new file mode 100644 index 0000000..95f88c2 --- /dev/null +++ b/container/a_star.py @@ -0,0 +1,87 @@ +from container import board +from container.node import Node +from container.mushroom import Mushroom +from container.tree import Tree +from operator import attrgetter + + +def a_star(board, fringe, explored, istate, successor, get_cost, goaltest): + + agent_x = istate[0] + agent_y = istate[1] + agent_angle = istate[2] + fringe: List[Node] = [Node(agent_x, agent_y, agent_angle)] + + while fringe: + + if not fringe: + return False, False + + node = min(fringe, key=lambda x: x.cost) + fringe.remove(node) + + if (node.x, node.y) == goaltest: + actions = [] + while node.parent != None: + actions.append(node.action) + node = node.parent + actions.reverse() + return actions + + explored.append(node) + + for action, x, y, angle in successor(board, node.x, node.y, node.angle): + next_node = Node(x, y, angle) + next_node.parent = node + next_node.action = action + next_node.cost = get_cost(next_node, goaltest,board) + heuristic_function(node, goaltest) + + if next_node not in fringe and next_node not in explored: + fringe.append(next_node) + else: + for checked_node in fringe: + if(checked_node == next_node and (next_node.cost) < (checked_node.cost)): + fringe[fringe.index(checked_node)] = next_node + + + +def successor(board,x,y,angle): + + result = [] + + result.append(("rotate_left", x, y, (angle + 1) % 4)) + result.append(("rotate_right", x, y, (angle - 1) % 4)) + + if angle == 1: + if x > 0: + result.append(("move", x-1, y, angle)) + elif angle == 0: + if y > 0: + result.append(("move", x, y-1, angle)) + elif angle == 3: + if x < board.col - 1: + result.append(("move", x+1, y, angle)) + elif angle == 2: + if y < board.row - 1: + result.append(("move", x, y+1, angle)) + + return result + + +def get_cost(node, goal: Mushroom, board): + + if (node.parent.x, node.parent.y) == (node.x, node.y): + sum = 1 + elif(isinstance((board.board[node.x][node.y]),Tree)): + sum = 1000 + elif(isinstance((board.board[node.x][node.y]),Mushroom) and (board.board[node.x][node.y].poison) == True): + sum = 1000 + else: + sum = 2 + + return sum + node.parent.cost + + +def heuristic_function(node, goal): + return abs(node.x - goal[0]) + abs(node.y - goal[1]) + diff --git a/container/board.py b/container/board.py index 63993bb..a6bb551 100644 --- a/container/board.py +++ b/container/board.py @@ -5,6 +5,7 @@ from container.constans import * from container.tree import Tree from container.mushroom import Mushroom from container.agent import Agent +from container.a_star import a_star,successor, get_cost class Board: def __init__(self, x = 0, y = 0, width = WIDTH, height = HEIGHT, row = ROWS, col = COLUMNS): @@ -21,7 +22,7 @@ class Board: self.agent = Agent(self.free_spaces.pop(), self.square_size) - print(f"Board {col}x{row} with agent on ({self.agent.col},{self.agent.row})") + print(f"Board {col}x{row} with agent on ({self.agent.col},{self.agent.row}) {self.agent.angle}") self.surface = pygame.Surface((self.width, self.height)) @@ -41,6 +42,9 @@ class Board: self.grow_next = 0 + self.path = [] + self.actions = [] + def update_free_spaces(self): self.free_spaces = [] @@ -92,6 +96,15 @@ class Board: def update_agent(self): self.agent.update_animation() + + if self.actions and self.agent.moving == self.agent.rotating == 0: + action = self.actions.pop(0) + + if action == "move": self.agent.move() + elif action == "rotate_left": self.agent.rotate(1) + else: self.agent.rotate(-1) + + #zebranie grzyba if self.board[self.agent.col][self.agent.row] != False and self.board[self.agent.col][self.agent.row].name == "Mushroom" and self.board[self.agent.col][self.agent.row].grow == 100: self.agent.points += self.board[self.agent.col][self.agent.row].points @@ -122,8 +135,22 @@ class Board: x_y = self.free_spaces.pop() self.board[x_y[0]][x_y[1]] = Mushroom(x_y, random.randint(0, 2), True, 0) - - + def a_starxd(self): + print(self.agent.angle) + fringe = [] + explored = [] + self.actions = a_star(self, + fringe, + explored, + (self.agent.col,self.agent.row, self.agent.angle), + successor, + get_cost, + (bfs((self.agent.col,self.agent.row,self.agent.angle),successor,self)) + ) + + print(self.actions) + + return self.actions diff --git a/container/node.py b/container/node.py new file mode 100644 index 0000000..a2ed0a8 --- /dev/null +++ b/container/node.py @@ -0,0 +1,15 @@ + +class Node: + def __init__(self, x, y, angle = None, parent = None, action = 0, cost=0): + self.x = x + self.y = y + self.angle = angle + self.parent = parent + self.action = action + self.cost = cost + + def __eq__(self, other): + if isinstance(other, Node) and (self.x == other.x and self.y == other.y and self.angle == other.angle): + return True + else: + return False \ No newline at end of file diff --git a/main.py b/main.py index 1e66afd..882e5a0 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,9 @@ import pygame from container.constans import WIDTH, HEIGHT, ROWS, COLUMNS, GREEN from container.board import Board -FPS = 30 + +FPS = 18 + #creating game window WIN = pygame.display.set_mode((WIDTH,HEIGHT)) @@ -34,19 +36,36 @@ def main(): if key_input[pygame.K_LEFT]: board.agent.rotate(1) if key_input[pygame.K_UP]: board.agent.move() if key_input[pygame.K_RIGHT]: board.agent.rotate(-1) + + #drawing map and detective WIN.fill(GREEN) - board.update_agent() + board.update_agent() #update moves and collecting mushrooms board.grow_mushrooms() board.draw_squares(WIN) board.draw_pieces(WIN) board.draw_agent(WIN) board.draw_info(WIN) - + pygame.display.update() + + + if key_input[pygame.K_SPACE]: + board.a_starxd() + + if(board.agent.rotating==0 and board.agent.moving==0): + board.a_starxd() + + + pygame.quit() main() + + + + +