Advertisement
pleasedontcode

"Pathfinding Maze" rev_01

Nov 18th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Pathfinding Maze"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-18 19:49:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Should start at index 0,0 in the Maze array and go */
  21.     /* to the required coordinates */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <FatPartition.h>   //https://github.com/adafruit/SdFat
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  34.  
  35. // Define the maze dimensions
  36. const int n = 8, m = 8;
  37.  
  38. // Define the target coordinates (0-indexed)
  39. int ReachRow = 7; // Target row
  40. int ReachCol = 7; // Target column
  41.  
  42. // Define the maze structure
  43. int Maze[n][m] = {
  44.     {1, 1, 1, 1, 0, 1, 1, 1},
  45.     {0, 1, 0, 0, 0, 1, 0, 0},
  46.     {1, 1, 0, 1, 0, 1, 0, 1},
  47.     {0, 1, 1, 1, 1, 1, 1, 1},
  48.     {1, 0, 0, 1, 0, 1, 0, 0},
  49.     {1, 0, 1, 0, 0, 1, 0, 0},
  50.     {1, 1, 1, 1, 1, 1, 1, 1},
  51.     {0, 1, 0, 0, 0, 1, 0, 0}
  52. };
  53.  
  54. // Result maze to track the path
  55. char ResultMaze[n][m];
  56.  
  57. // Movement history to track the path taken
  58. int MovementHistory[3][m * n];
  59.  
  60. // Function to initialize the maze and variables
  61. void initializeMaze() {
  62.     for (int Rows = 0; Rows < n; Rows++) {
  63.         for (int Columns = 0; Columns < m; Columns++) {
  64.             ResultMaze[Rows][Columns] = 'X'; // Mark all cells as unvisited
  65.         }
  66.     }
  67.  
  68.     for (int Rows = 0; Rows < 3; Rows++) {
  69.         for (int Columns = 0; Columns < m * n; Columns++) {
  70.             MovementHistory[Rows][Columns] = -1; // Initialize movement history
  71.         }
  72.     }
  73.  
  74.     ReachRow--; // Adjust for 0-indexing
  75.     ReachCol--; // Adjust for 0-indexing
  76.     MovementHistory[0][0] = 0; // Row locator
  77.     MovementHistory[1][0] = 0; // Column locator
  78.     MovementHistory[2][0] = 0; // Last movement
  79. }
  80.  
  81. // Function to perform maze traversal
  82. void traverseMaze() {
  83.     int MovementValue = 0;
  84.     int CurrentRow = 0;
  85.     int CurrentColumn = 0;
  86.  
  87.     while (1) {
  88.         if (MovementValue < 0) {
  89.             break; // No path available
  90.         }
  91.  
  92.         if (CurrentRow == ReachRow && CurrentColumn == ReachCol) {
  93.             ResultMaze[CurrentRow][CurrentColumn] = '*'; // Mark the path
  94.             // Here you can add code to display the ResultMaze if needed
  95.             break;
  96.         }
  97.  
  98.         // Movement logic continues...
  99.         // (The rest of the movement logic can be included here)
  100.     }
  101. }
  102.  
  103. void setup(void) {
  104.     // Initialize the maze and variables
  105.     initializeMaze();
  106.     // Start traversing the maze
  107.     traverseMaze();
  108. }
  109.  
  110. void loop(void) {
  111.     // put your main code here, to run repeatedly:
  112. }
  113.  
  114. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement