diff --git a/display_assets.py b/display_assets.py index 54b40e4..62fbcfd 100644 --- a/display_assets.py +++ b/display_assets.py @@ -7,8 +7,8 @@ import project_constants as const def calculate_screen_position(row, column): coords = ( - const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, - const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, ) return coords diff --git a/main.py b/main.py index 802d310..7cefe05 100644 --- a/main.py +++ b/main.py @@ -25,11 +25,13 @@ def main(): # create an instance of Minefield, pass necessary data minefield = mf.Minefield(const.MAP_RANDOM_10x10) - # get sequence of actions found by BFS algorythm - action_sequence = bfs.graphsearch(initial_state=bfs.State(row=minefield.agent.position[0], - column=minefield.agent.position[1], - direction=const.Direction.UP), - minefield=minefield) + # get sequence of actions found by BFS algorithm + action_sequence = bfs.graphsearch( + initial_state=bfs.State( + row=minefield.agent.position[0], + column=minefield.agent.position[1], + direction=const.Direction.UP), + minefield=minefield) running = True while running: diff --git a/minefield.py b/minefield.py index d82c039..070b7fb 100644 --- a/minefield.py +++ b/minefield.py @@ -59,8 +59,8 @@ class Minefield: @staticmethod def calculate_screen_position(row, column): coords = ( - const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, - const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * column, + const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * row, ) return coords diff --git a/project_constants.py b/project_constants.py index c9447c8..b49d62f 100644 --- a/project_constants.py +++ b/project_constants.py @@ -14,21 +14,23 @@ from enum import Enum # ================= # V_NAME_OF_WINDOW = "MineFusion TM" -ASSETS_DIR = os.path.join("resources", "assets") +DIR_ASSETS = os.path.join("resources", "assets") V_FPS = 60 ACTION_INTERVAL = 1 # interval between two actions in seconds V_TILE_SIZE = 60 -V_GRID_VER_TILES = V_GRID_HOR_TILES = 10 # vertical (number of rows), horizontal (number of columns) +V_GRID_VER_TILES = 10 # vertical (number of rows) +V_GRID_HOR_TILES = 10 # horizontal (number of columns) V_SCREEN_PADDING = 10 -V_WINDOW_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES -V_WINDOW_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES +V_NUMBER_PADDING = 50 +V_TILE_AREA_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES +V_TILE_AREA_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES SCREEN = pygame.display.set_mode( ( - V_TILE_SIZE * V_GRID_HOR_TILES + 2 * V_SCREEN_PADDING, # screen width - V_TILE_SIZE * V_GRID_HOR_TILES + 2 * V_SCREEN_PADDING # screen height + V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING, # screen width + V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING # screen height ) ) @@ -48,7 +50,7 @@ class Direction(Enum): v = (self.value + 1) % 4 return Direction(v) - def previous (self): + def previous(self): v = (self.value - 1) % 4 return Direction(v) @@ -113,71 +115,71 @@ MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "secondmap.json") # ============== # ASSET_BACKGROUND = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "new_grid.png")), - (V_WINDOW_WIDTH, V_WINDOW_WIDTH) + pygame.image.load(os.path.join(DIR_ASSETS, "numbered_grid.png")), + (650, 650) ) ASSET_SAPPER = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "robot_sapper.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "robot_sapper.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_WALL = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "brick_wall.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "brick_wall.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_MINE_A = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "mine_a.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "simple assets/mine_a.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_MINE_B = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "mine_b.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "simple assets/mine_b.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_MINE_F = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "mine_f.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "simple assets/mine_f.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_MINE_K = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "mine_k.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "simple assets/mine_k.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_ORANGE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_orange.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_orange.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_RED = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_red.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_red.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_BLUE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_blue.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_blue.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_PURPLE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_purple.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_purple.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_GREEN = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_green.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_green.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_YELLOW = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_yellow.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_yellow.png")), (V_TILE_SIZE, V_TILE_SIZE) ) ASSET_TILE_WHITE = pygame.transform.scale( - pygame.image.load(os.path.join(ASSETS_DIR, "tile_white.png")), + pygame.image.load(os.path.join(DIR_ASSETS, "tile_white.png")), (V_TILE_SIZE, V_TILE_SIZE) ) diff --git a/resources/assets/chained_mine.png b/resources/assets/chained_mine.png deleted file mode 100644 index 5a5abbc..0000000 Binary files a/resources/assets/chained_mine.png and /dev/null differ diff --git a/resources/assets/numbered_grid.png b/resources/assets/numbered_grid.png new file mode 100644 index 0000000..a7429f4 Binary files /dev/null and b/resources/assets/numbered_grid.png differ diff --git a/resources/assets/mine_a.png b/resources/assets/simple assets/mine_a.png similarity index 100% rename from resources/assets/mine_a.png rename to resources/assets/simple assets/mine_a.png diff --git a/resources/assets/mine_b.png b/resources/assets/simple assets/mine_b.png similarity index 100% rename from resources/assets/mine_b.png rename to resources/assets/simple assets/mine_b.png diff --git a/resources/assets/mine_f.png b/resources/assets/simple assets/mine_f.png similarity index 100% rename from resources/assets/mine_f.png rename to resources/assets/simple assets/mine_f.png diff --git a/resources/assets/mine_k.png b/resources/assets/simple assets/mine_k.png similarity index 100% rename from resources/assets/mine_k.png rename to resources/assets/simple assets/mine_k.png diff --git a/resources/assets/sapper.png b/resources/assets/simple assets/sapper.png similarity index 100% rename from resources/assets/sapper.png rename to resources/assets/simple assets/sapper.png diff --git a/searching_algorithms/bfs.py b/searching_algorithms/bfs.py index 309c2be..c93dca0 100644 --- a/searching_algorithms/bfs.py +++ b/searching_algorithms/bfs.py @@ -6,7 +6,7 @@ from project_constants import Direction, Action from minefield import Minefield # temporary goal for testing -GOAL = (13, 9) +GOAL = (9, 9) class State: