From 9e4c21f6009cb417e7d6ca8e2e6faf7acfea8bc7 Mon Sep 17 00:00:00 2001 From: Tomasz Adamczyk Date: Sat, 24 Apr 2021 20:43:09 +0200 Subject: [PATCH] A* --- .idea/workspace.xml | 42 +++++++++++--------- __pycache__/astar.cpython-37.pyc | Bin 5246 -> 5291 bytes __pycache__/definitions.cpython-37.pyc | Bin 3412 -> 3706 bytes __pycache__/map.cpython-37.pyc | Bin 5498 -> 5718 bytes astar.py | 21 +++++----- definitions.py | 16 +++++++- map.py | 52 ++++++++++++------------- py.py | 2 +- 8 files changed, 76 insertions(+), 57 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cdbaa44..b4ac252 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,6 +3,8 @@ + + @@ -119,6 +121,8 @@ + + @@ -130,42 +134,42 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + @@ -179,6 +183,6 @@ - + \ No newline at end of file diff --git a/__pycache__/astar.cpython-37.pyc b/__pycache__/astar.cpython-37.pyc index 62d6e65b0a66461bbb8f839e79e558309c982361..d47d5592c647fddd12c83daf8013669e02a845fb 100644 GIT binary patch delta 906 zcmXw1O-vI}5PtJ^yWMtoOS>%~El>go6an#|5=){2!a+n6P!bUYUBFm=Uwf$W^+NGt zJU}L1FflaT^km@X&4V618E#Fynvf6^6K^EOc}4eSzWv_Jyl>yk?4OSJDQCcOf{dQa zvzxO&ww*f2ZMP@mBh1r0eUo{5k>A&8=kpBO8AXn*zVwH^^8h|PgcS(j0MCPkANe9U z*rGjwDtx6qga{rJkK$eZIq3V}^osyB=r@+39+PG@zBHzw5x0n)7&oB_NBm3Bj0gUw z&`R+&XrtIHbl@-3gHF5`n1U|i)%YcF8+x!dn1^cI3U*~Qy1AchkSse);6Z`s`z7qM z67yI_6W1h{Y!`Bzd|HVWPnoV*iPtiZte|3)Ux0OEl1VyKBnIbl-l6atDR33|!0m9BygA!r2~L=yY0TXB(~P>NLM9%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G diff --git a/__pycache__/definitions.cpython-37.pyc b/__pycache__/definitions.cpython-37.pyc index 9145f88540b5fcea2d204c2f461b6c32b9ffd544..c2bfb11969819c6ff293ab65b23314dd55d73d8e 100644 GIT binary patch literal 3706 zcmaKt+j81Q7=VQg7&|z|2A^{9AxGPZ6N7VT(=-VN*`~pW5uzkJo>3KcZQ}r9BxN%8 zbsxmJ>?`yc`UJY|75BaBO}e{UEt0^6VPQXg`~SQDuEg%t)TDr4nd9Go6Bh;HZ_@Ez zas1;Q{#c)4f&c{=X$!#pj(`Xhfe6RI7>t4_jDZ-6!FWc1;|l_aqsZC#WdaFj6PJ@P z0VlqR-y+}|rpe1GbPb6}JQlx+l=!_#>Ro5vb?y=3_pVWInt9XQBgF3|sh472ihC(M z?-@MrSv>DFO7nSVLgT0C_&GLyj*lnApXWOD=9xFoJwp86H1!skx4=C@{9cNBi_BZ( z9wB~jhI&iPTjJgloCP;v`bY#f!7WU0W(3^c$_SzWZiD4elnjls!lJD3C@U}yRzvO_ zb=R1?#@#hI4({NJ-o=%@hrjRR%0563cx4}k;>^=H>nzSXk3)!mg$vZ%VBQAz2=RN1 z)Z1jno60U+D;2QW5 z-T|-RUGNj;ukn8VjMwu9y@B`G9sV|y<37#tj^%jAa}eU6%LD4=nV07tA%5>6^>&%J z%RNH;-a7RP%qwt@5WlxUy(069+#|&AZBkESp2R&u{N5w#?J;kUdxZGC$JE8KhfMHO+h~5)kZ!rNTD?NRG3-+s;wl4gBQvf_@)fyB z+N4n5-~O}u*Jn}aXK<%qCCxf%#&L5o^Ys+zcHkHUkXw}ia!V3GZao6%8C^mEJs(Cd zhS5ucHr_j;VL9>M`H9{^&g5=cF1*)jB_M&!t|Y07EUPswU#yo^tsvJ_kRH%|MQ%{& zgrQnGl$?cud6@rDI;}UW=t|~1E4Yqn53|XF5Xgo>E(~@+ zv{+J9FhN?kzEcNMY5zdg@`rN0qJm_jR8$XG&xyMiofxGcxtCWC%lS%CD=HtsjKAjw z8wd?a^$ED=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6$!O)T7RR*4uCl;Q)lN0U^;A5fNQ* zh+baC#cL`v`u;N0S(&B#N>nZOZ7W7Z%_gJ)TMEG$<5YNjo$ z)y#@nv%8)?Fe+xF8yQy`IEhSYkS-kqQd)1rsX9b4v-@X7QIRD{DQgR|bW2kfi=v(E zfW^Y?#o~>kR#pm%X!p$(WZBCdXhU9R{JMk+Np!az+{KXVZX3IGRV*m37wB&S-j<>J zhN-RBR;qT4vZoc(0Ig~~F{)`E=-;!sXEyiT+KvxP2eDkwVPIU8OL06mjq7;pK7#id zT<&`u>tScTh!-ns6XbAj#i;7qa&6uGDDyvr3vdMcIr|SIl%1q-l)^Cz$0?kkkfLxH zLqni!*m{intvc@y# p: fringe.insert(i, (x, p)) #zamiana state, który należy do fringe z priorytetem r na state z priorytetem p (niższym) + fringe.pop(i + 1) fringe = sorted(fringe, key=itemgetter(1)) #sortowanie fringe'a według priorytetu break i = i + 1 \ No newline at end of file diff --git a/definitions.py b/definitions.py index 2ee2ec4..41cbb97 100644 --- a/definitions.py +++ b/definitions.py @@ -2,6 +2,8 @@ import os import pygame BLOCK_SIZE = 60 +BEETROOTS_ADULT_COST = 4 +BEETROOTS_GROW_COST = 10 BEETROOTS_GROW_TIME = 5 BEETROOTS_MAXIMUM_STATE = BEETROOTS_GROW_TIME * 3 + 1 BEETROOTS_STAGE_0 = pygame.image.load(os.path.join('resources', 'beetroots_stage_0.png')) @@ -12,6 +14,8 @@ BEETROOTS_STAGE_2 = pygame.image.load(os.path.join('resources', 'beetroots_stage BEETROOTS_STAGE_2 = pygame.transform.scale(BEETROOTS_STAGE_2, (BLOCK_SIZE, BLOCK_SIZE)) BEETROOTS_STAGE_3 = pygame.image.load(os.path.join('resources', 'beetroots_stage_3.png')) BEETROOTS_STAGE_3 = pygame.transform.scale(BEETROOTS_STAGE_3, (BLOCK_SIZE, BLOCK_SIZE)) +CARROTS_ADULT_COST = 4 +CARROTS_GROW_COST = 10 CARROTS_GROW_TIME = 5 CARROTS_MAXIMUM_STATE = CARROTS_GROW_TIME * 3 + 1 CARROTS_STAGE_0 = pygame.image.load(os.path.join('resources', 'carrots_stage_0.png')) @@ -24,13 +28,18 @@ CARROTS_STAGE_3 = pygame.image.load(os.path.join('resources', 'carrots_stage_3.p CARROTS_STAGE_3 = pygame.transform.scale(CARROTS_STAGE_3, (BLOCK_SIZE, BLOCK_SIZE)) DIRT = pygame.image.load(os.path.join('resources', 'dirt.png')) DIRT = pygame.transform.scale(DIRT, (BLOCK_SIZE, BLOCK_SIZE)) +DIRT_COST = 2 HEIGHT_AMOUNT, WIDTH_AMOUNT = 10, 10 HEIGHT, WIDTH = BLOCK_SIZE * HEIGHT_AMOUNT, BLOCK_SIZE * WIDTH_AMOUNT FARMLAND_DRY = pygame.image.load(os.path.join('resources', 'farmland_dry.png')) FARMLAND_DRY = pygame.transform.scale(FARMLAND_DRY, (BLOCK_SIZE, BLOCK_SIZE)) +FARMLAND_DRY_COST = 3 FARMLAND_WET = pygame.image.load(os.path.join('resources', 'farmland_wet.png')) FARMLAND_WET = pygame.transform.scale(FARMLAND_WET, (BLOCK_SIZE, BLOCK_SIZE)) -FPS = 1 +FARMLAND_WET_COST = 1 +FPS = 10 +POTATOES_ADULT_COST = 4 +POTATOES_GROW_COST = 10 POTATOES_GROW_TIME = 5 POTATOES_MAXIMUM_STATE = POTATOES_GROW_TIME * 3 + 1 POTATOES_STAGE_0 = pygame.image.load(os.path.join('resources', 'potatoes_stage_0.png')) @@ -45,6 +54,7 @@ SPONGE = pygame.image.load(os.path.join('resources', 'sponge.png')) SPONGE = pygame.transform.scale(SPONGE, (BLOCK_SIZE, BLOCK_SIZE)) STATION = pygame.image.load(os.path.join('resources', 'rail_normal.png')) STATION = pygame.transform.scale(STATION, (BLOCK_SIZE, BLOCK_SIZE)) +STATION_COST = 5 TRACTOR_DIRECTION_EAST_TEXTURE = pygame.image.load(os.path.join('resources', 'minecart_command_block_east.png')) TRACTOR_DIRECTION_EAST_TEXTURE = pygame.transform.scale(TRACTOR_DIRECTION_EAST_TEXTURE, (BLOCK_SIZE, BLOCK_SIZE)) TRACTOR_DIRECTION_NORTH_TEXTURE = pygame.image.load(os.path.join('resources', 'minecart_command_block_north.png')) @@ -58,10 +68,12 @@ TRACTOR_DIRECTION_NORTH = 1 TRACTOR_DIRECTION_SOUTH = 3 TRACTOR_DIRECTION_WEST = 4 TRACTOR_FERTILIZER = 2 -TRACTOR_FUEL = 200 +TRACTOR_FUEL = 99999999999999 TRACTOR_AMOUNT_OF_SEEDS_EACH_TYPE = 20 TRACTOR_MAXIMUM_COLLECTED_PLANTS = 80 TRACTOR_WATER_LEVEL = 40 +WHEAT_ADULT_COST = 4 +WHEAT_GROW_COST = 10 WHEAT_GROW_TIME = 5 WHEAT_MAXIMUM_STATE = WHEAT_GROW_TIME * 7 + 1 WHEAT_STAGE_0 = pygame.image.load(os.path.join('resources', 'wheat_stage_0.png')) diff --git a/map.py b/map.py index ccbf047..422643d 100644 --- a/map.py +++ b/map.py @@ -23,32 +23,6 @@ class Map: temp_field = field.Field(temp_plant, temp_rect, temp_soil) temp_map_field.append(temp_field) self.fields.append(temp_map_field) - def get_field_cost(self, x, y): #zwraca koszt danego pola - field = self.fields[x][y] - if field.get_plant().get_name() == "station" and field.get_plant().get_state() == -1: - return 5 - elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.BEETROOTS_GROW_TIME: - return 10 - elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE: - return 4 - elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.CARROTS_GROW_TIME: - return 10 - elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE: - return 4 - elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.POTATOES_GROW_TIME: - return 10 - elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE: - return 4 - elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 7 * definitions.WHEAT_GROW_TIME: - return 10 - elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE: - return 4 - elif field.get_soil().get_state() is False: - return 2 - elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False: - return 3 - elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True: - return 1 def fill_map(self): #wypełnia mapę teksturami na podstawie logicznego stanu pól for i in range(definitions.WIDTH_AMOUNT): for j in range(definitions.HEIGHT_AMOUNT): @@ -107,6 +81,32 @@ class Map: elif block != definitions.DIRT or block != definitions.FARMLAND_DRY or block != definitions.FARMLAND_WET: definitions.WINDOW.blit(definitions.FARMLAND_WET, (rect.x, rect.y)) definitions.WINDOW.blit(block, (rect.x, rect.y)) + def get_field_cost(self, x, y): #zwraca koszt danego pola + field = self.fields[x][y] + if field.get_plant().get_name() == "station" and field.get_plant().get_state() == -1: + return definitions.STATION_COST + elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.BEETROOTS_GROW_TIME: + return definitions.BEETROOTS_GROW_COST + elif field.get_plant().get_name() == "beetroot" and field.get_plant().get_state() == definitions.BEETROOTS_MAXIMUM_STATE: + return definitions.BEETROOTS_ADULT_COST + elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.CARROTS_GROW_TIME: + return definitions.CARROTS_GROW_COST + elif field.get_plant().get_name() == "carrot" and field.get_plant().get_state() == definitions.CARROTS_MAXIMUM_STATE: + return definitions.CARROTS_ADULT_COST + elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 3 * definitions.POTATOES_GROW_TIME: + return definitions.POTATOES_GROW_COST + elif field.get_plant().get_name() == "potato" and field.get_plant().get_state() == definitions.POTATOES_MAXIMUM_STATE: + return definitions.POTATOES_ADULT_COST + elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() > 0 and field.get_plant().get_state() <= 7 * definitions.WHEAT_GROW_TIME: + return definitions.WHEAT_GROW_COST + elif field.get_plant().get_name() == "wheat" and field.get_plant().get_state() == definitions.WHEAT_MAXIMUM_STATE: + return definitions.WHEAT_ADULT_COST + elif field.get_soil().get_state() is False: + return definitions.DIRT_COST + elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is False: + return definitions.FARMLAND_DRY_COST + elif field.get_soil().get_state() is True and field.get_soil().get_water_level() is True: + return definitions.FARMLAND_WET_COST def draw_window(self, tractor1, tractor1_rect): #rysuje mapę self.fill_map() if tractor1.get_direction() == definitions.TRACTOR_DIRECTION_EAST: diff --git a/py.py b/py.py index 5cc80e7..7a17ea3 100644 --- a/py.py +++ b/py.py @@ -29,7 +29,7 @@ def main(): if not move_list and plant.Plant.if_any_mature_plant(map1) is True: #jeżeli są jakieś ruchy do wykonania w move_list oraz istnieje jakaś dojrzała roślina istate = graph.Istate(tractor1.get_direction(), tractor1.get_x() / definitions.BLOCK_SIZE, tractor1.get_y() / definitions.BLOCK_SIZE) #stan początkowy traktora (jego orientacja oraz jego aktualne współrzędne) #move_list = (graph.graphsearch([], [], istate, graph.succ, plant.Plant.get_closest_mature_plant(map1, tractor1))) #lista z ruchami, które należy po kolei wykonać, graph - move_list = (astar.graphsearch([], [], istate, graph.succ, plant.Plant.get_closest_mature_plant(map1, tractor1), astar.f, map1)) #lista z ruchami, które należy po kolei wykonać, astar + move_list = (astar.graphsearch([], [], istate, graph.succ, plant.Plant.get_closest_mature_plant(map1, istate), astar.f, map1)) #lista z ruchami, które należy po kolei wykonać, astar elif move_list: #jeżeli move_list nie jest pusta tractor1.handle_movement(move_list.pop(0), tractor1_rect) #wykonaj kolejny ruch oraz zdejmij ten ruch z początku listy else: