Changed map generating

This commit is contained in:
Tomasz Torchalski 2023-05-04 18:21:09 +02:00
parent 674393a4d9
commit a9e8d1b83d
2 changed files with 35 additions and 28 deletions

4
bfs.py
View File

@ -1,10 +1,12 @@
from succ import succ as successors from succ import succ as successors
from queue import PriorityQueue
def bfs(istate, goalx, goaly, passedFields): def bfs(istate, goalx, goaly, passedFields):
fringe = [istate] fringe = [istate]
explored = [] explored = []
steps = [] steps = []
while(fringe): while fringe:
state = fringe.pop(0) state = fringe.pop(0)
if state.xpos == goalx and state.ypos == goaly: if state.xpos == goalx and state.ypos == goaly:
steps.insert(0, state) steps.insert(0, state)

43
main.py
View File

@ -28,46 +28,52 @@ class Agent:
self.rect = rect self.rect = rect
self.direction = direction self.direction = direction
def randomize_map(): # tworzenie mapy z losowymi polami def randomize_map(): # tworzenie mapy z losowymi polami
fields_list = [DIRT, GRASS, SAND, COBBLE]
field_array_1 = [] field_array_1 = []
field_array_2 = [] field_array_2 = []
field_priority = []
for i in range(16): for i in range(16):
temp_priority = []
for j in range(16): for j in range(16):
randomChoiceOfBlock = random.choice(fields_list) if i in (0, 1) and j in (0, 1):
priorityOfBlock = fields_list.index(randomChoiceOfBlock) field_array_2.append(GRASS)
field_array_2.append([randomChoiceOfBlock,priorityOfBlock]) temp_priority.append(1)
else:
prob = random.uniform(0, 100)
if 0 <= prob <= 10:
field_array_2.append(COBBLE)
temp_priority.append(3)
if 10 < prob <= 20:
field_array_2.append(SAND)
temp_priority.append(2)
else:
field_array_2.append(GRASS)
temp_priority.append(1)
field_array_1.append(field_array_2) field_array_1.append(field_array_2)
field_array_2 = [] field_array_2 = []
return field_array_1 field_priority.append(temp_priority)
return field_array_1, field_priority
def draw_window(agent, fields): def draw_window(agent, fields):
for i in range(16): for i in range(16):
for j in range(16): for j in range(16):
window.blit(fields[i][j][0], (i * 50, j * 50)) window.blit(fields[i][j], (i * 50, j * 50))
window.blit(AGENT, (agent.rect.x, agent.rect.y)) # wyswietlanie agenta window.blit(AGENT, (agent.rect.x, agent.rect.y)) # wyswietlanie agenta
pygame.display.update() pygame.display.update()
#def agent_movement(keys_pressed, agent): # sterowanie
# if keys_pressed[pygame.K_LEFT] and agent.x > 0:
# agent.x -= 50
# if keys_pressed[pygame.K_RIGHT] and agent.x < 750:
# agent.x += 50
# if keys_pressed[pygame.K_UP] and agent.y > 0:
# agent.y -= 50
# if keys_pressed[pygame.K_DOWN] and agent.y < 750:
# agent.y += 50
def main(): def main():
clock = pygame.time.Clock() clock = pygame.time.Clock()
run = True run = True
agent = GarbageTruck(0, 0, pygame.Rect(0, 0, 50, 50), 0) # tworzenie pola dla agenta agent = GarbageTruck(0, 0, pygame.Rect(0, 0, 50, 50), 0) # tworzenie pola dla agenta
fields = randomize_map() fields, priority_array = randomize_map()
print(priority_array)
print(priority_array[4][8])
while run: while run:
clock.tick(FPS) clock.tick(FPS)
for event in pygame.event.get(): # przechwycanie zamknięcia okna for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
run = False run = False
# keys_pressed = pygame.key.get_pressed() # keys_pressed = pygame.key.get_pressed()
@ -89,6 +95,5 @@ def main():
pygame.quit() pygame.quit()
if __name__ == "__main__": if __name__ == "__main__":
main() main()