From 0268776045d0260bab01b5ecc5f5006245af0118 Mon Sep 17 00:00:00 2001 From: s473561 Date: Sat, 6 May 2023 12:57:48 +0200 Subject: [PATCH] updated bfs - works --- __pycache__/etykieta.cpython-311.pyc | Bin 1302 -> 1302 bytes __pycache__/main.cpython-311.pyc | Bin 4841 -> 3416 bytes __pycache__/packageList.cpython-311.pyc | Bin 0 -> 881 bytes __pycache__/paczka.cpython-311.pyc | Bin 2703 -> 2703 bytes __pycache__/regal.cpython-311.pyc | Bin 3257 -> 3257 bytes __pycache__/wozek.cpython-311.pyc | Bin 3448 -> 4018 bytes __pycache__/wyszukiwanie.cpython-311.pyc | Bin 2884 -> 6376 bytes main.py | 160 +++++++++--- wozek.py | 73 +++++- wyszukiwanie.py | 303 +++++++++++++++++++---- 10 files changed, 443 insertions(+), 93 deletions(-) create mode 100644 __pycache__/packageList.cpython-311.pyc diff --git a/__pycache__/etykieta.cpython-311.pyc b/__pycache__/etykieta.cpython-311.pyc index ddad8891b2c656548728b16cc764e440f69e5dc9..4a56169220a38ed740f34cf49bb86995b36f1fe8 100644 GIT binary patch delta 20 acmbQnHI0jVIWI340}yP!6ta<+W7*QKO_MwsMKY2p4T;T`5-F!oi?q`+BIC5I z$U;kNo`hHQQUuFrT*4>%5`NL2;6*+mh=McDYB&)P1BpJdk3uw3==J`V;R6s3TOCA^ zcLS|%DcF*_TiJ5}b3BB9vxtMBGt}ypPPL@&R`#CI8Sb(3S~s>O%UrLHGq+dS@%8G6 zBRzIbx464oWu#XJcFezv#8D+A^BXil>KOKH^yE&-)Eb=98VU0Q{Hd_*cY0GnCGp#8WyQs#@Fm2c1Cg|jz zWJcA56jzM7gsQ9?F(nEtK>lVr8P5z}OPY$N#+9U*+@9PbMl=1#a5a`n5>Sjxs#Q1; z$Q6738%wU2**-i3OOUApSmvR#RHCqh%+_^;UhlGZDAPkQ%_7q>1KNN-Y-{Y$Cb4#0 zvQ+QpmcahYC5zVEtXcZRY?v%lpmm&O7Eyuzir-xmD z|F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^A@iiZ@h8l+&=2<&akHi_09?ed|q(>qiRwn?|!2CL16Og%+0a%jW}0Zi{z z^3uKX>g<&@w6o+kU|MwTrFN}4!my)E*!rwxbGQ62bN?0(7iWt-7_-e;vS1r*5vv{gs-QSAdebQKBNnEr4C}3&MqFZ*temNHzQxh8*5$DP8#0MTB}hAW3bjS8G3U};w^pT0339k%jXhX zccBoV#-{rmc`k|L=Q3-r|E|P|^WN27U1mx2Ko&klk#=ZA8}jygG}O=zlV}G*J4|ys zHMCi77ec#Db9*$jS?&gercHCZHMCi78lfTUHo1b08k#nVZbE2>Y3^nXZI;`M&~DS* zEgIS^cPm2Ern#?Z=nLH2;NZJ@R9CmPcOr^xV1&>n-t@2xk5MA0k}I63QerB}snq?Y z=|zB0lsKPD113_m4cNSGE8YMyyTPl%KZ9;_SxVTC^ipF9p zwH(9KsN}M$mFHH%G1WS+H5AK-H&r_u6_T-V3R%RWNxxOKYKbk6?@E3YSJ&~XdDujR zizPNwjDRK~;C<-9<(m&9?}e5Gju%3cf!W#6WFoS$j@DHOEi5igPEUk>zzEzrCy0D# zAuVo1((y23q|uSpaL9N;IW?oD~VH+?#loyr8x zEYpOw`=qsVKXlyMFSqs=TCXXs*Umt<*T{mR#jj~8Gs7K;}&r>@5A&0P5L*xp$2O50u_JGD1e^fYH55dZ)H diff --git a/__pycache__/packageList.cpython-311.pyc b/__pycache__/packageList.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35e030c06d1bdfd55558a993cdf6fd89e37f16ef GIT binary patch literal 881 zcmah{&ubGw6n?Y2iEEn}&=zuvx#rT7pcD~=h!jE;ViCf^xa>?r+U#aKvk@A4$e{<7 zg5aedJw;0X85O~@C&7Op5>Gw(-fXg96@0Vvy&p64-uE8+v0PpQl*#vwc!&B2IV*9N z#-fhK8CdWb1e}0iQwv~*JCiO5s{;)?SOrM4rL(A^aRw5)OhDJ_LDv@S1iFr}5DUV_ zmri#K#ex8kGJ_JtVV{IlgPj1`c8 zrg=@^!Y!R%|K?V|xYhR?pWWJ5xAtlEEvU;NZx0<}PGef!LpX!~k7$bbX1FuS2BfHb z!%{_5sT~jF22(EDnkv;5{U&Kq$#D2mjyJE6&%)Q}_9nuT|J(AL^6ScJ<&{~ggeUDr zF?BhQ{7`b9u5lg?#b`iwiSxseKgdoD3AK(7R0ZK2%wxkrQKJT^Yke1ClCO*P@}xO; zSmE{@azM9A?p4TgQo1&_YSP}K+{DwAx^(Yn^d6`UjL{rSy}8X8n>$5@8UKc#6#Mm$ H1C#hSb6UC> literal 0 HcmV?d00001 diff --git a/__pycache__/paczka.cpython-311.pyc b/__pycache__/paczka.cpython-311.pyc index 43bec40fc68fd01dccf72a6e47e1d8089d3379d1..1424063e24a43cb5f746c9f6b00dbac80ab5a293 100644 GIT binary patch delta 20 acmeAd?HA=<&dbZi00f&ag>2+*;Q|0N{slq+ delta 20 ZcmeAd?HA=<&dbZi00b;OjvKjKxBx9O1Udi! diff --git a/__pycache__/regal.cpython-311.pyc b/__pycache__/regal.cpython-311.pyc index a1c73712858732ae8eba86a564c00286f58e3578..3a74b9aa802e057f3c02367ab473f6a4af35aedf 100644 GIT binary patch delta 20 acmdlfxl@vRIWI340}#|3hHd0t#{&R0_yqR= delta 20 acmdlfxl@vRIWI340}!zEIBw)##{&Q~R0P5R diff --git a/__pycache__/wozek.cpython-311.pyc b/__pycache__/wozek.cpython-311.pyc index 475bb021b2da8afbd21c9dcbc0f338fe343d7488..d6e10928c16443cbf448fd66de2456d060d93dce 100644 GIT binary patch delta 1741 zcmah}O>7%Q6rS0gUE8tOO;VFON%0R!0H+aEK&`}2gWOat3MNVj6mV4q$GdHv*iJg$ zkjAoWS8%XU1dcYM5hoX_5Y&rHDik>N$O*YogseT4V=4|t0f{4T*3Kp_k(inN_WjSB zH*fc!t{=S4?{9IfKa5|Y#BT3ypp+so(+QeKW zsze(;XgT_R2fxR_TY!i0yI(E;>UXPTUo~x-m5BBxenz`wX@A3%srG%#49;*ezXrN{ zraprv#XSodL7H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ZqvQe<#|Nv;ed~>k0CMxjx9pLD zT_9+u0U&yzF<*JU3eE?Pdya>FkIrXZPa6x~_E&vxE)_b?=9|u~3jGD4KX0DgG0uUp zC)dsQV(iV`wA^8^K>i4~9o5t)jYO>__ie-2N50s;b?umDC)|RO!!i>^Q}`CfFm^Lo zW?^&Bpb#r8`CxU=LTAn7IU_CF0`(|>pVg~UX)TkSjHE)bh@!SpjfZL=Van4N8l8xy zCe;N*_xz{X8Lu%8$1AV&Rt!WtHP{M33wStRd5R4OmYSE;Y`li+d?#-Vy1Hu)qD zd1&QdAhjNd5s6BN-vFNUI9*;l-&#VO;AZ&&TtZv0iX@#UW?c*)D534JVV9bO%#9Wp z=4plhx%@4hoQliIsB%iBe+uo1)&o#tF~&tC&KbKT1Tpy74&PDGg9ATz&=@ZM0<2^M Aj{pDw diff --git a/__pycache__/wyszukiwanie.cpython-311.pyc b/__pycache__/wyszukiwanie.cpython-311.pyc index 496134a0c4148bcb1302681962833f01823135ee..c58228edb1d91161068eed282160bcec14281815 100644 GIT binary patch literal 6376 zcmcH-OKcm*b$7YD{4GUECiSr-Tb6A(v>e%TpEmf2aBrWk695^bMTA}i64Z4~tcJ~Pd7gvJ4lf6M>{zAA+$6gyBHO%yw!IDz77 zqBsb}4HTh?;uJkIRG{TK4j!Nlc0x`q2N;99nM%YYgB_1Xl9B4nB%`a9oen5Gq$FyV z7O7cAq-Sj+Gs}uL7>zZADJ3etBgJAjR}+$gYk!U%g8|NPghFz7Sqg;=S17a`7gI4T z3!%{MR5(_p*n>a6`O~YxDTBK)F*SDm8)^q<{UIE=H20n=DeBz##P#cQv=aod%b)kCC^c)7 zSc#K(iJxb>Nh1W3y`kn1={Eo?@*?{=JL`m;gWN^W+jM1^q@_0$wP=+!Y7yrmNuxDpow4QXw%WTFxffuArnsYh2($*6=Qyd-i#3L1&v9lb_toJ^83D9+)Zvd{xr%qz z;g9a($(RZ@td6fBu{M4cPsXp}$(U6$FK5zmxoEt2*9xJpStJtswOZ%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Qx67P0eS~NULF8;MCqNPO@(+tl!0JD$`cP5=tG)a^bNo5R}SSRWP7+WMwo^!u{f|hfb}>YN3yxOx8xu)&l41fpf*noBo4kTAnQDR zk&m8?)((GK^PjEz&lYF4T%NmH-8EE>ZMa6Nu8{`cRl4%MvqVd@0gDaQyAD<8M%QSy zYxIAzw!A~-nW`sTywJ8uTA8mOo~-##*8L}oGfgLfwWo@OV&OYz_xy;h2X+`M50{63 zhE_R+*m}SVKYD)f+>6%uu{u9i<;S+VeZ?8`MCdr=Fw7Xho!j8ZWsuvmJF=?PK)88JRgR$%(9}Nx70G6BsC>Q_JX#MPEk+tWhpOJ;;>Blu!TbFW z`-@*}xqVII;U>0x{mbqL?(*b)??Z2i+v*-zI$wrVUrB9rPgJ`nek=U`?H}V$C!QYL zI1#Cyh&24eRnPDif8Z~EaDyK#kJtE6oex#{(6hkda;_E_uLs8AKcH*EM5XCQZ=ig! z+B*hsCA)s6`u;h1H;2b6r+>P!a^s%60S0&{Kurgww8^j({!;d%=Q#Fam(jye dxW4zJ=Q#Fam*F0yV5yBh@zee$*^f;7{{>gdP{IHJ diff --git a/main.py b/main.py index ba6e036..453aece 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,11 @@ import sys +import time import pygame import regal import paczka from wozek import Wozek -from wyszukiwanie import wyszukiwanie_bfs, Stan, SearchSpace +from wyszukiwanie import Stan, SearchSpace, Search, GridCellType +from typing import Tuple, Dict pygame.init() @@ -14,54 +16,35 @@ pygame.display.set_caption("Inteligentny wozek") icon = pygame.image.load('images/icon.png') pygame.display.set_icon(icon) +# def draw(self): +# screen.blit(self.image, (self.state.x, self.y)) def main(): - wozek = Wozek() - while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - sys.exit(0) - if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - sys.exit(0) - - grid = SearchSpace() - # create start and goal states - start_state = Stan(x=0, y=0, kierunek=0) # for example - goal_state = Stan(x=0, y=1, kierunek=0) # for example - # perform BFS search - path = wyszukiwanie_bfs(start_state, goal_state, grid) + wozek = Wozek(0,0) - # print the path, if found - if path: - for p in path: - print(p.x, p.y) - print("Path found:", path) - else: - print("No path found.") + # for event in pygame.event.get(): + # if event.type == pygame.QUIT: + # sys.exit(0) + # if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + # sys.exit(0) - for state in path: - pygame.time.delay(200) - wozek.x = state.x - wozek.y = state.y - for event in pygame.event.get(): - if event.type == pygame.QUIT: - sys.exit(0) - if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - sys.exit(0) + grid_points = SearchSpace() + goal_state = Stan(5, 2, 0) # for example + # perform BFS search + path = Search(grid_points).wyszukiwanie_bfs(wozek.state, goal_state) - # Drawing + if path: + for p in path: + wozek._move(p) screen.fill((51,51,51)) # removes object trail screen.blit(miejsce, (430, 400)) - - # idRegału, Długość regału podana w kratkach, Współrzędne od których ma być tworzony regał (wiersz,kolumna) - poziomo - # Współrzędne od (1,1) do (10,10) regal.Regal(1, 1, 2, 2) regal.Regal(2, 1, 2, 3) regal.Regal(3, 1, 3, 2) regal.Regal(4, 1, 3, 3) - + regal.Regal(5, 1, 8, 2) regal.Regal(6, 1, 8, 3) regal.Regal(7, 1, 9, 2) @@ -76,10 +59,111 @@ def main(): regal.Regal(14, 1, 8, 9) regal.Regal(15, 1, 9, 8) regal.Regal(16, 1, 9, 9) - wozek.draw() + pygame.display.flip() + time.sleep(1) - pygame.display.flip() # updating frames + # wozek._drive(path) + # print(path) + + # for action in path: + # x = wozek.state.x + # y = wozek.state.y + # direction = wozek.state.kierunek + + # print(x) + + # if action == "Left": + # wozek.state.kierunek = 3 if direction == 0 else direction - 1 + + # # always legal + # elif action == "Right": + + # # self._truck_direction(direction, action) + # wozek.state.kierunek = (direction + 1) % 4 + + # # check if its legal + # elif action == "Forward": + # t_x = x + 1 if direction == 1 else (x - 1 if direction == 3 else x) + # t_y = y - 1 if direction == 0 else (y + 1 if direction == 2 else y) + + # # if self.points_grid[t_y][t_x].is_available: + # wozek.state.x = t_x + # wozek.state.y = t_y + + + # screen.fill((51,51,51)) # removes object trail + # screen.blit(miejsce, (430, 400)) + + # regal.Regal(1, 1, 2, 2) + # regal.Regal(2, 1, 2, 3) + # regal.Regal(3, 1, 3, 2) + # regal.Regal(4, 1, 3, 3) + + # regal.Regal(5, 1, 8, 2) + # regal.Regal(6, 1, 8, 3) + # regal.Regal(7, 1, 9, 2) + # regal.Regal(8, 1, 9, 3) + + # regal.Regal(9, 1, 2, 8) + # regal.Regal(10, 1, 2, 9) + # regal.Regal(11, 1, 3, 8) + # regal.Regal(12, 1, 3, 9) + + # regal.Regal(13, 1, 8, 8) + # regal.Regal(14, 1, 8, 9) + # regal.Regal(15, 1, 9, 8) + # regal.Regal(16, 1, 9, 9) + # wozek.draw() + + # pygame.display.flip() + + # for p in path: + # print(p.x, p.y) + # print("Path found:", path) + # else: + # print("No path found.") + + # for state in path: + # pygame.time.delay(200) + # wozek.x = state.x + # wozek.y = state.y + # for event in pygame.event.get(): + # if event.type == pygame.QUIT: + # sys.exit(0) + # if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + # sys.exit(0) + + + # # Drawing + # screen.fill((51,51,51)) # removes object trail + # screen.blit(miejsce, (430, 400)) + + # # idRegału, Długość regału podana w kratkach, Współrzędne od których ma być tworzony regał (wiersz,kolumna) - poziomo + # # Współrzędne od (1,1) do (10,10) + # regal.Regal(1, 1, 2, 2) + # regal.Regal(2, 1, 2, 3) + # regal.Regal(3, 1, 3, 2) + # regal.Regal(4, 1, 3, 3) + + # regal.Regal(5, 1, 8, 2) + # regal.Regal(6, 1, 8, 3) + # regal.Regal(7, 1, 9, 2) + # regal.Regal(8, 1, 9, 3) + + # regal.Regal(9, 1, 2, 8) + # regal.Regal(10, 1, 2, 9) + # regal.Regal(11, 1, 3, 8) + # regal.Regal(12, 1, 3, 9) + + # regal.Regal(13, 1, 8, 8) + # regal.Regal(14, 1, 8, 9) + # regal.Regal(15, 1, 9, 8) + # regal.Regal(16, 1, 9, 9) + + # wozek.draw() + + # pygame.display.flip() # updating frames if __name__ == "__main__": diff --git a/wozek.py b/wozek.py index 880c081..7caaac4 100644 --- a/wozek.py +++ b/wozek.py @@ -1,24 +1,34 @@ +import time +from typing import Tuple import pygame +from wyszukiwanie import Stan, SearchSpace + +# from main import screen, miejsce + # screen nie działa class Wozek(): - def __init__(self): - self.x = 55 - self.y = 55 - self.x_change = 0 - self.y_change = 0 + def __init__(self, y, x): + # self.x = 55 + # self.y = 55 + # self.x_change = 0 + # self.y_change = 0 self.height = 64 self.width = 64 self.image = pygame.image.load("images/pusty_wozek.png") + # self.screen = pygame.display.set_mode((980, 980)) + # self.miejsce = pygame.image.load('images/miejsce_paczek.png') # Credit: Forklift icons created by Smashicons - Flaticon # https://www.flaticon.com/free-icons/forklift - self.__zainicjuj_stan_poczatkowy() + #self.__zainicjuj_stan_poczatkowy() + self.state = Stan(y, x, 0) def draw(self): from main import screen # screen.blit(self.image, (self.x, self.y)) - screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y)) + #screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y)) + screen.blit(self.image, (self.state.x*98, self.state.y*98)) # storage = ["none"] * 10 storage = [] @@ -47,10 +57,51 @@ class Wozek(): elif (len(storage) == 10): wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png") - def __zainicjuj_stan_poczatkowy(self): - from wyszukiwanie import Stan - # self.obecnyStan = Stan(55, 55, 3) - self.obecnyStan = Stan(0, 0, 3) + # def __zainicjuj_stan_poczatkowy(self): + # from wyszukiwanie import Stan + # # self.obecnyStan = Stan(55, 55, 3) + # self.obecnyStan = Stan(1, 1, 3) + # def _drive(self, actions): + + # # for action in actions.reverse(): + # for action in actions: + # self._move(action) + # pygame.event.pump() + # time.sleep(0.01) + # # self.screen.fill((51,51,51)) # removes object trail + # # self.screen.blit(self.miejsce, (430, 400)) + # self.draw() + + # pygame.display.flip() + + def _move(self, action): + x = self.state.x + y = self.state.y + direction = self.state.kierunek + + # always legal + if action == "Left": + + # self._truck_direction(direction, action) + self.state.kierunek = 3 if direction == 0 else direction - 1 + + # always legal + elif action == "Right": + # self._truck_direction(direction, action) + self.state.kierunek = (direction + 1) % 4 + + # check if its legal + elif action == "Forward": + t_x = x + 1 if direction == 1 else (x - 1 if direction == 3 else x) + t_y = y - 1 if direction == 0 else (y + 1 if direction == 2 else y) + + # if self.points_grid[t_y][t_x].is_available: + self.state.x = t_x + self.state.y = t_y + # else: + # print("[ MOVE LOG ] - You can't move in that direction!") + + # def ustaw_wozek_w_kierunku(self, kierunek): # TODO diff --git a/wyszukiwanie.py b/wyszukiwanie.py index bdd5101..a0676e2 100644 --- a/wyszukiwanie.py +++ b/wyszukiwanie.py @@ -1,67 +1,282 @@ +from enum import Enum + +from typing import Tuple, Dict + +class GridCellType(Enum): + NOTHING = 0 + REGAL = 1 + # dodać oznaczenie na miejsce dla paczek + class SearchSpace: - def __init__(self): - self.grid = [['1']*10 for _ in range(10)] # create a 10x10 grid of cells + grid: Dict[Tuple[int, int], GridCellType] = {} + + def __init__(self) -> None: + self._init_grid() + + def _init_grid(self) -> None: + for i in range (0,10): + for j in range(0,10): + self.grid[(i, j)] = GridCellType.NOTHING for r, c in [(2,2), (2,3), (3,2), (3,3), (8,2), (8,3), (9,2), (9,3), (2,8), (2,9), (3,8), (3,9), (8,8), (8,9), (9,8), (9,9)]: - self.grid[r][c] = 'X' # set the cells with a shelf to not passable + self.grid[(r,c)] = GridCellType.REGAL - def is_passable(self, x, y): - return 0 <= x < 10 and 0 <= y < 10 and self.grid[y][x] != 'X' - class Stan: def __init__(self, x, y, kierunek): self.x = x self.y = y self.kierunek = kierunek + class Wezel: - def __init__(self, stan): + def __init__(self, stan: Stan, action = None, parent = None): self.stan = stan + self.action = action + self.parent = parent -def poprzednik(wezel, search_space): - # gora -> prawo -> dol -> lewo | obrot w prawo - # gora -> lewo -> dol -> prawo | obrot w lewo - # 0 gora 1 prawo 2 dol 3 lewo - y = wezel.stan.x - x = wezel.stan.y - obrot_w_prawo = Stan(x, y, (wezel.stan.kierunek + 1) % 4) - obrot_w_lewo = Stan(x, y, (wezel.stan.kierunek - 1) % 4) +class Search: + def __init__(self, points_grid: SearchSpace): + self.points_grid = points_grid - if wezel.stan.kierunek == 0: - y -= 1 - elif wezel.stan.kierunek == 1: - x += 1 - elif wezel.stan.kierunek == 2: - y += 1 - elif wezel.stan.kierunek == 3: - x -= 1 + def wyszukiwanie_bfs(self, stan_poczatkowy: Stan, stan_docelowy: Stan): + pierwszy_wezel = Wezel(stan_poczatkowy) + fringe = [pierwszy_wezel] - wezly = [obrot_w_prawo, obrot_w_lewo] - ruch_w_przod = Stan(x, y, wezel.stan.kierunek) + odwiedzone = [] - # sprawdzenie czy nie wyjdzie poza plansze - if 0 <= x <= 916 and 0 <= y <= 916: - wezly.append(ruch_w_przod) + while fringe: + wezel = fringe.pop(0) - return wezly + if self.goal_test(state = wezel.stan, goal_state = stan_docelowy): + return self.get_actions(wezel) -def wyszukiwanie_bfs(stan_poczatkowy, stan_docelowy, search_space): - pierwszy_wezel = Wezel(stan_poczatkowy) - fringe = [pierwszy_wezel] + odwiedzone.append(wezel.stan) + + for action, stan in self.nastepnik(wezel): + if wezel not in fringe and stan not in odwiedzone: + x_node = Wezel(stan, action, wezel) + fringe.append(x_node) + return False - odwiedzone = set() + def goal_test(self, state: Stan, goal_state: Stan): + if state.x == goal_state.x and state.y == goal_state.y: + return True + else: + return False + + def nastepnik(self, wezel: Wezel): + # gora -> prawo -> dol -> lewo | obrot w prawo + # gora -> lewo -> dol -> prawo | obrot w lewo + # 0 gora 1 prawo 2 dol 3 lewo + state = wezel.stan + right_state = Stan( state.x, state.y,(state.kierunek + 1) % 4) - while fringe: - wezel = fringe.pop(0) + right_node = ["Right", right_state] - if stan_docelowy.x == wezel.stan.x and stan_docelowy.y == wezel.stan.y: - return odwiedzone + # 90 degree left state - cost of turn is 1 + left_state = Stan (state.x, state.y,3 if state.kierunek == 0 else state.kierunek - 1) - odwiedzone.add(wezel.stan) + # storing temporarily node as list + left_node = ["Left", left_state] - for stan in poprzednik(wezel, search_space): - if stan not in odwiedzone: - nowy_wezel = Wezel(stan) - fringe.append(nowy_wezel) - odwiedzone.add(stan) - return odwiedzone + # always two nodes are possible because we can turn in both sides + nodes = [right_node, left_node] + + y = state.x + x = state.y + # obrot_w_prawo = Stan(x, y, (wezel.stan.kierunek + 1) % 4) + # obrot_w_lewo = Stan(x, y, (wezel.stan.kierunek - 1) % 4) + + if wezel.stan.kierunek == 0: + y -= 1 + elif wezel.stan.kierunek == 1: + x += 1 + elif wezel.stan.kierunek == 2: + y += 1 + elif wezel.stan.kierunek == 3: + x -= 1 + + + place = None + + if 0 <= y < 98 and 0 <= x < 98: + place = self.points_grid.grid[(y,x)] + + if place is not None and place is GridCellType.NOTHING: + ruch_w_przod = Stan(y, x, wezel.stan.kierunek) + forward_node = ["Forward", ruch_w_przod] + nodes.append(forward_node) + + # sprawdzenie czy nie wyjdzie poza plansze + # if 0 <= x <= 916 and 0 <= y <= 916: + # wezly.append(ruch_w_przod) + + return nodes + + def get_actions(self, wezel: Wezel): + actions = [] + moves_forward = 0 + turns = 0 + parent = wezel + while True: + action = parent.action + parent = parent.parent + if action is None: + break + + if action == "Forward": + moves_forward = moves_forward + 1 + else: + turns = turns + 1 + + actions.append(action) + + actions.reverse() + + return actions + + + + + + + + + + +# class Kierunek(Enum): +# POLNOC = 0 +# POLUDNIE = 1 +# ZACHOD = 2 +# WSCHOD = 3 +# def kierunekNaLewo(self): +# if self == Kierunek.POLNOC: +# return Kierunek.ZACHOD +# elif self == Kierunek.POLUDNIE: +# return Kierunek.WSCHOD +# elif self == Kierunek.ZACHOD: +# return Kierunek.POLUDNIE +# elif self == Kierunek.WSCHOD: +# return Kierunek.POLNOC + +# def kierunekNaPrawo(self): +# if self == Kierunek.POLNOC: +# return Kierunek.WSCHOD +# elif self == Kierunek.POLUDNIE: +# return Kierunek.ZACHOD +# elif self == Kierunek.ZACHOD: +# return Kierunek.POLNOC +# elif self == Kierunek.WSCHOD: +# return Kierunek.POLUDNIE + +# class Akcja(Enum): +# OBROT_W_LEWO = 0 +# OBROT_W_PRAWO = 1 +# KROK_W_PRZOD = 2 + +# class Stan: +# def __init__(self, kierunek: Kierunek, x, y): +# self.x = x +# self.y = y +# self.kierunek = kierunek + +# def skopiuj(self): +# return Stan(self.x, self.y, self.kierunek) + +# class Nastepnik: +# def __init__(self, akcja: Akcja or None, stan: Stan, poprzednik): +# self.akcja = akcja +# self.stan = stan +# self._poprzednik = poprzednik + +# def getPoprzednik(self): +# return self._poprzednik + +# def setPoprzednik(self, x): +# raise Exception + +# poprzednik = property(getPoprzednik, setPoprzednik) + +# def skopiuj(self): +# return Nastepnik(self.akcja, self.stan.skopiuj(), self.poprzednik) + +# def goaltest(stan: Stan, cel: Stan): +# if stan.x != cel.x: +# return False +# elif stan.y != cel.y: +# return False +# else: +# return True + +# def stos_akcji(stan_koncowy: Nastepnik): +# stos = deque() +# while stan_koncowy.poprzednik is not None: +# stos.append(stan_koncowy.akcja) +# stan_koncowy = stan_koncowy.poprzednik +# return stos + +# def stan_w_liscie_nastepnikow(stan: Stan, lista_nastepnikow): +# for i in lista_nastepnikow: +# if i.stan.kierunek != stan.kierunek: +# continue +# elif i.stan.x != stan.x: +# continue +# elif i.stan.y != stan.y: +# continue +# else: +# return True +# return False + +# def nastepnik_kroku_w_przod(nastepnik: Nastepnik): +# akcja = Akcja.KROK_W_PRZOD +# stan = Stan(nastepnik.stan.kierunek, nastepnik.stan.x, nastepnik.stan.y) +# if stan.kierunek == Kierunek.POLNOC: +# stan.x -= 1 +# elif stan.kierunek == Kierunek.POLUDNIE: +# stan.x += 1 +# elif stan.kierunek == Kierunek.ZACHOD: +# stan.y -= 1 +# elif stan.kierunek == Kierunek.WSCHOD: +# stan.y += 1 +# return Nastepnik(akcja, stan, nastepnik) + +# def nastepnik_obrotu_w_lewo(nastepnik: Nastepnik): +# akcja = Akcja.OBROT_W_LEWO +# stan = Stan(nastepnik.stan.kierunek.kierunekNaLewo(), nastepnik.stan.x, nastepnik.stan.y) +# return Nastepnik(akcja, stan, nastepnik) +# #Nastepnik(Akcja.OBROT_W_LEWO, Stan(nastepnik.stan.kierunek.kierunekNaLewo(), nastepnik.stan.poleStartoweGorne), nastepnik) +# # + +# def nastepnik_obrotu_w_prawo(nastepnik: Nastepnik): +# akcja = Akcja.OBROT_W_PRAWO +# stan = Stan(nastepnik.stan.kierunek.kierunekNaPrawo(),nastepnik.stan.x, nastepnik.stan.y) +# return Nastepnik(akcja, stan, nastepnik) + +# def succ(nastepnik: Nastepnik): +# wynik = [] +# pom = nastepnik.skopiuj() +# #wynik.append(nastepnik_obrotu_w_lewo(pom)) +# wynik.append(nastepnik_obrotu_w_lewo(pom)) +# pom = nastepnik.skopiuj() +# wynik.append(nastepnik_obrotu_w_prawo(pom)) +# pom = nastepnik.skopiuj() + +# wynik.append(nastepnik_kroku_w_przod(pom)) +# return wynik + +# def graphsearch(istate: Stan, cel: Stan): +# fringe = deque() +# explored = [] +# fringe.append(Nastepnik(None, istate, None)) +# while fringe: +# # for i in fringe: +# # print("F",i.stan.kierunek,i.stan.poleStartoweGorne.wiersz,i.stan.poleStartoweGorne.kolumna,end=" ") +# # print() +# element: Nastepnik = fringe.popleft() +# if goaltest(element.stan, cel): +# return stos_akcji(element) +# explored.append(element) +# for nastepnik in succ(element): +# if not stan_w_liscie_nastepnikow(nastepnik, fringe) and not stan_w_liscie_nastepnikow(nastepnik, explored): +# fringe.append(nastepnik) +# return False \ No newline at end of file