Added line follower boilerplate
This commit is contained in:
parent
668f279d13
commit
1bbf652d17
49
devenv.lock
49
devenv.lock
@ -31,10 +31,31 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"git-hooks": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"gitignore": "gitignore",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1742649964,
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"gitignore": {
|
"gitignore": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"pre-commit-hooks",
|
"git-hooks",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -66,32 +87,14 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pre-commit-hooks": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-compat": "flake-compat",
|
|
||||||
"gitignore": "gitignore",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1737465171,
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "cachix",
|
|
||||||
"repo": "pre-commit-hooks.nix",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"devenv": "devenv",
|
"devenv": "devenv",
|
||||||
|
"git-hooks": "git-hooks",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"pre-commit-hooks": "pre-commit-hooks"
|
"pre-commit-hooks": [
|
||||||
|
"git-hooks"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,14 @@
|
|||||||
env.GREET = "devenv";
|
env.GREET = "devenv";
|
||||||
|
|
||||||
# https://devenv.sh/packages/
|
# https://devenv.sh/packages/
|
||||||
packages = [ pkgs.verilator pkgs.gtkwave ];
|
packages = [
|
||||||
|
pkgs.verilator
|
||||||
|
pkgs.gtkwave
|
||||||
|
pkgs.clang-tools
|
||||||
|
pkgs.clang
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scripts.hello.exec = ''
|
scripts.hello.exec = ''
|
||||||
echo hello from $GREET
|
echo hello from $GREET
|
||||||
|
71
line-follower/leelib.c
Normal file
71
line-follower/leelib.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void readEdge (int *i, int *j)
|
||||||
|
/* Scans input to read a blocked edge.
|
||||||
|
Returns the indices i and j in m[13][13] of an edge.
|
||||||
|
Call this function with pointers to the variables
|
||||||
|
that should receive the values, e.g.
|
||||||
|
readEdge (&x, &y);
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
int cx, cy;
|
||||||
|
char d;
|
||||||
|
scanf ("%d %d %c", &cy, &cx, &d);
|
||||||
|
if (d == 's') {
|
||||||
|
*i = 2 + cy * 2 + 1;
|
||||||
|
*j = 2 + cx * 2;
|
||||||
|
}
|
||||||
|
else if (d == 'e') {
|
||||||
|
*i = 2 + cy * 2;
|
||||||
|
*j = 2 + cx * 2 + 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf (stderr, "error on direction: %c\n", d);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readStation (int *i, int *j)
|
||||||
|
/* Scans input to read a station.
|
||||||
|
Returns the indices i and j in m[13][13] of a station.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
scanf ("%d", &s);
|
||||||
|
switch (s) {
|
||||||
|
case 1: *i = 12, *j = 4; break;
|
||||||
|
case 2: *i = 12, *j = 6; break;
|
||||||
|
case 3: *i = 12, *j = 8; break;
|
||||||
|
case 4: *i = 8, *j = 12; break;
|
||||||
|
case 5: *i = 6, *j = 12; break;
|
||||||
|
case 6: *i = 4, *j = 12; break;
|
||||||
|
case 7: *i = 0, *j = 8; break;
|
||||||
|
case 8: *i = 0, *j = 6; break;
|
||||||
|
case 9: *i = 0, *j = 4; break;
|
||||||
|
case 10: *i = 4, *j = 0; break;
|
||||||
|
case 11: *i = 6, *j = 0; break;
|
||||||
|
case 12: *i = 8, *j = 0; break;
|
||||||
|
default: fprintf (stderr, "Illegal station\n"); exit (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printCrossingName (int i, int j)
|
||||||
|
/* Print the name of the crossing with indices i and j in m[13][13]/ */
|
||||||
|
{
|
||||||
|
if ((i-2)%2 == 0 && (j-2)%2 == 0)
|
||||||
|
printf ("c%d%d ", (i-2)/2, (j-2)/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printMatrix (int m[][13])
|
||||||
|
/* Print the elements of the matrix m[13][13]. */
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < 13; i++) {
|
||||||
|
for (j = 0; j < 13; j++) {
|
||||||
|
printf ("%2d ", m[i][j]);
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
}
|
19
line-follower/leelib.h
Normal file
19
line-follower/leelib.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
void readEdge (int *i, int *j);
|
||||||
|
/* Scans input to read a blocked edge.
|
||||||
|
Returns the indices i and j in m[13][13] of an edge.
|
||||||
|
Call this function with pointers to the variables
|
||||||
|
that should receive the values, e.g.
|
||||||
|
readEdge (&x, &y);
|
||||||
|
*/
|
||||||
|
|
||||||
|
void readStation (int *i, int *j);
|
||||||
|
/* Scans input to read a station.
|
||||||
|
Returns the indices i and j in m[13][13] of a station.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void printCrossingName (int i, int j);
|
||||||
|
/* Print the name of the crossing with indices i and j in m[13][13]/ */
|
||||||
|
|
||||||
|
void printMatrix (int m[][13]);
|
||||||
|
/* Print the elements of the matrix m[13][13]. */
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user