bfs na przycisk b

This commit is contained in:
Uni 2024-05-08 19:19:52 +02:00
parent 91a4e02c18
commit 34f3bb77f5
7 changed files with 47 additions and 39 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

8
.idea/Projekt_Si.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Projekt_Si.iml" filepath="$PROJECT_DIR$/.idea/Projekt_Si.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

37
app.py
View File

@ -3,7 +3,7 @@ import prefs
from classes.beerKeg import BeerKeg from classes.beerKeg import BeerKeg
from classes.coffeMachine import CoffeMachine from classes.coffeMachine import CoffeMachine
from classes.table import Table from classes.table import Table
from pygame.locals import K_w, K_s, K_a, K_d, K_q, K_e, K_r from pygame.locals import K_w, K_s, K_a, K_d, K_q, K_e, K_r, K_b
from classes.cell import Cell from classes.cell import Cell
from classes.agent import Agent from classes.agent import Agent
from collections import deque from collections import deque
@ -64,38 +64,8 @@ def draw_grid(window, cells, agent):
initBoard() initBoard()
agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells) agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells)
#Wpisujemy miejsce w ktorym znajduje sie agent i miejsce docelowe do funkcji znajdujacej najkrotsza sciezke
# start_cell = cells[5][5]
# target_cell = cells[5][5]
# shortest_path = agent.bfs(start_cell, target_cell, cells)
# if shortest_path:
# print("Sciezka: ", [(cell.X, cell.Y) for cell in shortest_path])
# else:
# print("Brak sciezki")
# path = agent.convert_to_coordinates(shortest_path)
#osobny watek dla sciezki agenta zeby co *iles czasu* poruszal sie tam gdzie mowi path
# def watekDlaSciezkiAgenta():
# while True:
# agent.sciezkaAgenta(agent,path)
# time.sleep(1)
# watek = threading.Thread(target=watekDlaSciezkiAgenta)
# watek.daemon = True
# watek.start()
#target_x, target_y = 9,6
#target_x, target_y = 5,2
#target_x, target_y = 7,2
#target_x, target_y = 8,2
#target_x, target_y = 4,8
#target_x, target_y = 0,9
target_x, target_y = 9,11 target_x, target_y = 9,11
#target_x, target_y = 4,11
#target_x, target_y = 6,3
#target_x, target_y = 11,11
#WYWOLUJEMY FUNKCJE SZUKAJACA LISTY AKCJI #WYWOLUJEMY FUNKCJE SZUKAJACA LISTY AKCJI
path = agent.bfs2(target_x, target_y) path = agent.bfs2(target_x, target_y)
@ -148,6 +118,9 @@ while running:
if keys[K_r]: if keys[K_r]:
agent.move_direction() agent.move_direction()
if keys[K_b]:
path = agent.bfs2(target_x, target_y)
if pygame.key.get_pressed()[pygame.K_e]: if pygame.key.get_pressed()[pygame.K_e]:
if agent.current_cell.interactableItem and pygame.time.get_ticks() - agent.last_interact_time > 500: if agent.current_cell.interactableItem and pygame.time.get_ticks() - agent.last_interact_time > 500:
agent.last_interact_time = pygame.time.get_ticks() agent.last_interact_time = pygame.time.get_ticks()