Commit graph

34 commits

Author SHA1 Message Date
c49707e404
ci: update Forgejo workflow
All checks were successful
test / test (pull_request) Successful in 3s
Run the python tests in a Python container using a custom local action
and a Dockerfile to build the testing environment.

Resolves the issue where setup-python doesn't seem to work with Forgejo
actions (at least for me anyway).
2024-08-16 06:46:40 +01:00
083a0a5ab1
fix: fixed mapping of search_algorithm
Map the correct search algorithm to its name.
2024-02-27 11:10:20 +00:00
9026ad7328
docs: update README.md with project documentation
- Update README.md with the project documentation.
- Add a gif of the demo.
- Add pictures for illustration.
2024-02-18 11:01:36 +00:00
f0e5f9b65b
chore: add .gitattributes with LFS settings 2024-02-18 09:36:26 +00:00
bf27ee6bb9
tests: add fixes for tests 2024-02-18 09:10:34 +00:00
1b0f044834
feat: add a side panel for user interaction
Some checks failed
test / test (pull_request) Failing after 6s
This commit adds a simple side panel to allow users to interact with the
application. The side panel allows the user to:

- Generate and regenerate mazes
- Choose between the searching algorithms
- Choose whether or not to add randomness to the algorithm
- Run and re-run the simulation
2024-02-18 08:53:36 +00:00
ed5f0033fa
fix(solver): call random.seed() from constructor 2024-02-17 04:01:56 +00:00
fa75e61acf
fix: add randomisation to original DFS algorithm
Update the DFS algorithm to allow the user to select if the solver
should randomly choose the directions when traversing through the maze.

The duplicate method has been removed.
2024-02-17 03:55:34 +00:00
b4d2e1161b
feat: add the BFS search algorithm to Solver
Add the BFS algorithm to the Solver class. This method can be executed
with or without random directions enabled.
2024-02-17 03:39:24 +00:00
611935050b
refactor: DFS not DST
The searching algorithm is called Depth-First Search not DST.
2024-02-17 02:35:01 +00:00
8466500092
feat: add the Randomised DST search algorithm
Implement a variation to the DST search algorithm to the Solver class.
In this variation, the solver randomly chooses the next direction when
it reaches a fork in its path.
2024-02-17 01:37:20 +00:00
a091f0a68d
refactor: add a dedicated class for the solver
Create a separate class to represent the solver of the maze.
Additional search algorithms will be implemented here.

Additional changes:

- Add public methods to mark cells as visited and to get results of
  the visits.
- Renamed MazeDirections to MazeDirection.
- Renamed _num_cell_rows to _height.
- Renamed _num_cells_per_row to _width.
- Created a dedicated method to configure a cell's walls in the Maze
  class.
- created a dedicated public method to draw a path between two cells in
  the Maze class.
2024-02-16 23:27:09 +00:00
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