route_planner_DSB
This commit is contained in:
parent
1bbf652d17
commit
ce5107b6ad
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,6 +8,8 @@ devenv.local.nix
|
||||
*.bak
|
||||
obj_dir
|
||||
output.vcd
|
||||
*.exe
|
||||
*.out
|
||||
|
||||
work
|
||||
*.mti
|
||||
|
28
.vscode/tasks.json
vendored
Normal file
28
.vscode/tasks.json
vendored
Normal file
@ -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"
|
||||
}
|
6
line-follower/Hello_world.c
Normal file
6
line-follower/Hello_world.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello World!");
|
||||
return 0;
|
||||
}
|
144
line-follower/main.c
Normal file
144
line-follower/main.c
Normal file
@ -0,0 +1,144 @@
|
||||
#include "leelib.c"
|
||||
#include <stdio.h>
|
||||
|
||||
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_blocks ; k++)
|
||||
{
|
||||
int block_i, block_j;
|
||||
int * ptr_block_i;
|
||||
int * ptr_block_j;
|
||||
ptr_block_i = &block_i;
|
||||
ptr_block_j = &block_j;
|
||||
|
||||
printf("Enter block postion %d as <x> <y> <direction ('s'or 'e')>:\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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user