diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc index 851941e..7c1838f 100644 Binary files a/__pycache__/agent.cpython-38.pyc and b/__pycache__/agent.cpython-38.pyc differ diff --git a/__pycache__/common.cpython-38.pyc b/__pycache__/common.cpython-38.pyc index 64eca0d..9acdfc7 100644 Binary files a/__pycache__/common.cpython-38.pyc and b/__pycache__/common.cpython-38.pyc differ diff --git a/__pycache__/field.cpython-38.pyc b/__pycache__/field.cpython-38.pyc index 6acf55c..a95ddf4 100644 Binary files a/__pycache__/field.cpython-38.pyc and b/__pycache__/field.cpython-38.pyc differ diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc index ca9dbf7..45c8227 100644 Binary files a/__pycache__/settings.cpython-38.pyc and b/__pycache__/settings.cpython-38.pyc differ diff --git a/bfs.py b/bfs.py new file mode 100644 index 0000000..bd42ea7 --- /dev/null +++ b/bfs.py @@ -0,0 +1,51 @@ +import settings +import math + + +def generate_neighbours_list(): + width = settings.Field.horizontal_count() + height = settings.Field.vertical_count() + keys = [width for width in range(height * width)] + neighbours_list = {key: [] for key in keys} + for i in range(height): + for j in range(width): + point = i * width + j + # point_row = math.floor(point/width) + # point_column = point % width + point_left = i * width + j - 1 + point_left_column = point_left - width * i + point_right = i * width + j + 1 + point_right_column = point_right % width + point_up = (i - 1) * width + j + point_up_row = math.floor(point_up / width) + point_down = (i + 1) * width + j + point_down_row = math.floor(point_down / width) + if point_left_column >= 0: + neighbours_list[point].append(point_left) + if point_right_column > 0: + neighbours_list[point].append(point_right) + if point_up_row >= 0: + neighbours_list[point].append(point_up) + if point_down_row < height: + neighbours_list[point].append(point_down) + return neighbours_list + + +def generate_fields_lists(fields): + width = settings.Field.horizontal_count() + height = settings.Field.vertical_count() + fields_to_visit = [] + for i in range(height): + for j in range(width): + point = i * width + j + if fields[j][i] == 'dirt': + fields_to_visit.append(point) + return fields_to_visit + + +def generate_all(fields): + neighbours_list = generate_neighbours_list() + fields_to_visit = generate_fields_lists(fields) + print(neighbours_list) + print(fields_to_visit) + diff --git a/main.py b/main.py index d13a5cd..a7834e9 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import pygame import random - +import bfs import field import settings import common @@ -21,21 +21,25 @@ def randomize_map(): fields_array = [] for i in possibleFields: fields_array.append(possibleFields[i].tile.object) - field_array_big = [] field_array_small = [] + field_array_big_2 = [] + field_array_small_2 = [] for i in range(settings.Field.horizontal_count()): for j in range(settings.Field.vertical_count()): - field_array_small.append(random.choice(fields_array)) + k = random.choice(list(possibleFields.keys())) + field_array_small.append(possibleFields[k].tile.object) + field_array_small_2.append(k) field_array_big.append(field_array_small) + field_array_big_2.append(field_array_small_2) field_array_small = [] - return field_array_big + field_array_small_2 = [] + return field_array_big, field_array_big_2 def read_img(agent, fields): window = common.get('window') current_field = fields[agent.x()][agent.y()] - if current_field == possibleFields['grass'].tile.object: window.blit(possibleFields['grass'].block.object, (0, 0)) elif current_field == possibleFields['dirt'].tile.object: @@ -80,7 +84,8 @@ def main(): pygame.display.set_caption(settings.Pygame.display_name()) - fields = randomize_map() + fields, fields_2 = randomize_map() + bfs.generate_all(fields_2) while common.get('game_running'): pygame.time.Clock().tick(settings.Pygame.fps())