Changed map generating
This commit is contained in:
parent
674393a4d9
commit
a9e8d1b83d
4
bfs.py
4
bfs.py
@ -1,10 +1,12 @@
|
||||
from succ import succ as successors
|
||||
from queue import PriorityQueue
|
||||
|
||||
|
||||
def bfs(istate, goalx, goaly, passedFields):
|
||||
fringe = [istate]
|
||||
explored = []
|
||||
steps = []
|
||||
while(fringe):
|
||||
while fringe:
|
||||
state = fringe.pop(0)
|
||||
if state.xpos == goalx and state.ypos == goaly:
|
||||
steps.insert(0, state)
|
||||
|
43
main.py
43
main.py
@ -28,46 +28,52 @@ class Agent:
|
||||
self.rect = rect
|
||||
self.direction = direction
|
||||
|
||||
|
||||
def randomize_map(): # tworzenie mapy z losowymi polami
|
||||
fields_list = [DIRT, GRASS, SAND, COBBLE]
|
||||
field_array_1 = []
|
||||
field_array_2 = []
|
||||
field_priority = []
|
||||
for i in range(16):
|
||||
temp_priority = []
|
||||
for j in range(16):
|
||||
randomChoiceOfBlock = random.choice(fields_list)
|
||||
priorityOfBlock = fields_list.index(randomChoiceOfBlock)
|
||||
field_array_2.append([randomChoiceOfBlock,priorityOfBlock])
|
||||
if i in (0, 1) and j in (0, 1):
|
||||
field_array_2.append(GRASS)
|
||||
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_2 = []
|
||||
return field_array_1
|
||||
field_priority.append(temp_priority)
|
||||
return field_array_1, field_priority
|
||||
|
||||
|
||||
def draw_window(agent, fields):
|
||||
for i 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
|
||||
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():
|
||||
clock = pygame.time.Clock()
|
||||
run = True
|
||||
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:
|
||||
clock.tick(FPS)
|
||||
for event in pygame.event.get(): # przechwycanie zamknięcia okna
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
# keys_pressed = pygame.key.get_pressed()
|
||||
@ -89,6 +95,5 @@ def main():
|
||||
pygame.quit()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user