From ce5107b6adc1dd98ac531d7617a7190c10c998ff Mon Sep 17 00:00:00 2001 From: lasse Date: Thu, 27 Mar 2025 11:19:58 +0100 Subject: [PATCH] route_planner_DSB --- .gitignore | 2 + .vscode/tasks.json | 28 +++++++ line-follower/Hello_world.c | 6 ++ line-follower/main.c | 144 ++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 .vscode/tasks.json create mode 100644 line-follower/Hello_world.c create mode 100644 line-follower/main.c diff --git a/.gitignore b/.gitignore index 8d37115..eabbc45 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ devenv.local.nix *.bak obj_dir output.vcd +*.exe +*.out work *.mti diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..865ba8b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc.exe build active file", + "command": "C:\\msys64\\ucrt64\\bin\\gcc.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/line-follower/Hello_world.c b/line-follower/Hello_world.c new file mode 100644 index 0000000..bee3151 --- /dev/null +++ b/line-follower/Hello_world.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello World!"); + return 0; +} \ No newline at end of file diff --git a/line-follower/main.c b/line-follower/main.c new file mode 100644 index 0000000..f9fd0fd --- /dev/null +++ b/line-follower/main.c @@ -0,0 +1,144 @@ +#include "leelib.c" +#include + +int main(){ + int maze[13][13] = {{-1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1}, + {-1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1}, + {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1}, + {-1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {-1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {-1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {-1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1}, + {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1}, + {-1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1}, + {-1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1}, + }; + + + int n_blocks; + printf("Enter number of blockades:\n"); + scanf ("%d", &n_blocks); + //TO DO: INITIALISE EDGES + for(int k = 0; k :\n", k + 1); + readEdge (ptr_block_i, ptr_block_j); + maze[block_i][block_j] = -1; + } + + int start_station_i, start_station_j; + int * ptr_start_station_i; + int * ptr_start_station_j; + ptr_start_station_i = &start_station_i; + ptr_start_station_j = &start_station_j; + + printf("Input start station number"); + readStation(ptr_start_station_i, ptr_start_station_j); + + int end_station_i, end_station_j; + int * ptr_end_station_i; + int * ptr_end_station_j; + ptr_end_station_i = &end_station_i; + ptr_end_station_j = &end_station_j; + + printf("Input end station number"); + readStation(ptr_end_station_i, ptr_end_station_j); + + + int v = 1; + maze[end_station_i][end_station_j] = v; + + //expand phase + for(v; v<20 ; v++) + { + for(int i=0; i < 13; i++ ) + { + for(int j = 0; j < 13; j++) + { + if(maze[i][j] == v) + { + // Check south + if (i + 1 < 13 && maze[i + 1][j] == 0) + { + maze[i+1][j] = v+1; + } + // Check north + if (i - 1 >= 0 && maze[i - 1][j] == 0) + { + maze[i-1][j] = v+1; + } + // Check east + if (j + 1 < 13 && maze[i][j+1] == 0) + { + maze[i][j+1] = v+1; + + } + // Check west + if (j - 1 >= 0 && maze[i][j-1] == 0) + { + maze[i][j-1] = v+1; + + } + } + } + } + } + + if(maze[start_station_i][start_station_j] == 0) + { + printf("No route could be found :( \n"); + printMatrix (maze); + return 0; + } + + + printf("\n Path:\n"); + int i = start_station_i; + int j = start_station_j; + for(int k=0; k <= 20; k++) + { + printCrossingName(i, j); + + if(i == end_station_i && j == end_station_j) + { + break; + } + // Check south + if (i + 1 < 13 && maze[i+1][j] > 0 && maze[i + 1][j] < maze[i][j]) + { + i++; + continue; + } + // Check north + if (i - 1 >= 0 && maze[i-1][j] > 0 && maze[i - 1][j] < maze[i][j]) + { + i--; + continue; + } + // Check east + if (j + 1 < 13 && maze[i][j+1] > 0 && maze[i][j+1] < maze[i][j]) + { + j++; + continue; + } + // Check west + if (j - 1 >= 0 && maze[i][j-1] && maze[i][j-1] < maze[i][j]) + { + j--; + continue; + } + } + + printf("\n Maze:\n"); + printMatrix (maze); + return 0; +}