Commit graph

22 commits

Author SHA1 Message Date
5c48f47a0a
feat: add the algorithm to solve the maze 2024-02-15 22:34:08 +00:00
5be7f5041a
refactor: use MazePosition as an argument
- Use MazePosition as the argument for the _break_wall_r method
- Generate small mazes for tests to avoid RecursionError exceptions.
2024-02-15 16:36:18 +00:00
32696f311d
refactor: add MazeDirections and MazePositions
- Created a new enum type called MazeDirections to represent the
  directions you can make in the maze.
- Created a class called MazePosition to represent the position on the
  maze grid. It has the functionality to calculate and return adjacent
  positions.
- Used the above two additions to refactor the _break_walls_r method and
  make it a bit easier to read.
2024-02-15 14:58:51 +00:00
a8ef152847
fix: create a separate visited variable for solver
- Create a new visited variable for the Maze solver.
- Rename the existing visited variable to
  visited_by_maze_generator for the generator.
2024-02-15 03:45:01 +00:00
4d72fe8e43
fix: fixed issues with the maze generation
- Fixed the issue where during the reconfiguration of the walls of a
  cell, those that weren't being reconfigured were reset to True
  regardless of their previous configuration.
- During testing, don't run the _break_walls_r method because it will
  run into the RecursionError exception.
- Simplify the code for drawing cells and fix the redrawing wasn't
  applied properly.
2024-02-15 03:30:30 +00:00
a919c2698b
perf: reduce CPU usage whilst idle
When the Maze Solver was idle the wait_for_close() loop ran which
continuously redrew the window in an infinite while loop. This caused
the CPU usage to spike between 70%-80%. This commit removes that method
and uses the _root.mainloop() instead to keep the window visible on the
screen. With this the CPU usage has dropped to > 1% when idle.
2024-02-15 01:40:16 +00:00
27cdeaf7f4
tests: fix tests
Don't run self._break_walls_r() if the window is not set for now
for testing purposes.
2024-02-14 23:13:41 +00:00
d1c3ca6658
feat: add maze generation functionality
Main feature:

- Added functionality to randomly generate a maze before the solver
  solves it.

Fixes:

- Add a public method in the Cell class called wall_exists() that
  returns true if a given cell wall exists (false otherwise).

Refactors:

- Added an enum type called CellWallLabel for labelling the four cell
  walls.
- Added a draw() function in the CellWall class to reduce repeated code.
- Move the custom exceptions to errors.py

Tests:

- Add tests for the custom exceptions.

CI:

- Added a workflow for Forgejo Actions.
2024-02-14 22:50:46 +00:00
6d919a99d6
fix: add errors for invalid cell creation
- Raise CellInvalidError when attempting to specify the wrong corners of
  the cell when creating it. The x and y values should always represent
  the top left and bottom right corners of the cell.
- Raise CellTooSmallError when attempting to specify a cell which is too
  small to correctly draw its central point.
2024-02-13 18:54:58 +00:00
536711f808
feat: add entrance, exit to the maze.
- Add an entrance and exit to the maze. The entrance will always
  be on the top left and the exit will always be on the bottom
  right.
- Add a simple GitHub actions workflow to run the Python tests.
2024-02-13 15:52:28 +00:00
70175b3afd
test: add tests for the Maze class
Add some tests to test the Maze constructor.
2024-02-13 14:21:35 +00:00
2ebb555bac
fix: only draw the graphics if the window exists
Optionally pass in the reference of the Window to the Maze and
Cell classes, and only draw the graphics if the reference exists.

Use a single underscore instead of the double underscore for private
Class members.
2024-02-13 13:39:25 +00:00
30792f25b0
feat: add the Maze class
The Maze class stored a 2-dimensional grid of Cells. When the Maze is
initialised, the Cell's are created and drawn onto the canvas.
2024-02-13 12:18:47 +00:00
12b4e2367c
refactor: annotate method return type
Add missing annotations for methods that return None.
2024-02-13 10:59:47 +00:00
45a003270a
feat: add draw_move method to Cell
Add the draw_move method to the Cell class to draw a path between the
centre of two cells.
2024-02-13 10:48:26 +00:00
a19d9260d2
refactor: add a CellWall class
Add a CellWall class to simplify the code within the Cell class.
2024-02-13 01:15:19 +00:00
60e557c725
docs: update README.md 2024-02-13 00:19:56 +00:00
7d976f2350
feat: move Cell class to separate module. 2024-02-12 23:48:41 +00:00
14c6f659ff
feat: add the Cell class
Add the Cell class to represent a grid in the maze. Each 'Cell' can
be configured to specify which walls exists for it.
2024-02-12 23:32:03 +00:00
340eec773d
fix: position the window to the centre of screen 2024-02-12 21:30:27 +00:00
ccdffe00bf
fix: set missing attributes to the Canvas
Add missing attributes to the Canvas including it's size.
2024-02-12 20:04:55 +00:00
72dad848ec
feat: run a simple graphical window
Run a simple window and draw a few lines on it.
2024-02-12 19:53:45 +00:00