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>

51
app.py
View File

@ -1,9 +1,9 @@
import pygame import pygame
import prefs 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
@ -29,7 +29,7 @@ def initBoard():
y1 = 6 y1 = 6
for i in range(x1, x1+4): for i in range(x1, x1+4):
for j in range(y1, y1+2): for j in range(y1, y1+2):
cells[i][j].prepareTexture("sprites/wall.png") cells[i][j].prepareTexture("sprites/wall.png")
cells[i][j].blocking_movement = True cells[i][j].blocking_movement = True
cells[6][4].interactableItem = BeerKeg(cells[6][4], "Beer Keg") cells[6][4].interactableItem = BeerKeg(cells[6][4], "Beer Keg")
@ -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)
@ -110,9 +80,9 @@ def watekDlaSciezkiAgenta():
if element =="left": if element =="left":
agent.rotate_left() agent.rotate_left()
if element =="right": if element =="right":
agent.rotate_right() agent.rotate_right()
if element =="forward": if element =="forward":
agent.move_direction() agent.move_direction()
time.sleep(1) time.sleep(1)
@ -125,7 +95,7 @@ while running:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
running = False running = False
# takie głupie kontrolki do usunięcia potem, tylko do preznetacji # takie głupie kontrolki do usunięcia potem, tylko do preznetacji
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
@ -139,7 +109,7 @@ while running:
agent.move_right() agent.move_right()
if not any([keys[K_w], keys[K_s], keys[K_a], keys[K_d]]): if not any([keys[K_w], keys[K_s], keys[K_a], keys[K_d]]):
agent.moved = False agent.moved = False
if keys[K_q]: if keys[K_q]:
agent.rotate_left() agent.rotate_left()
if keys[K_e]: if keys[K_e]:
@ -147,7 +117,10 @@ 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()