~aleteoryx/9c

ref: 73f196770a756c4286371668ddd4c31ab8c92d92 9c/maze.c -rw-r--r-- 682 bytes
73f19677 — glenda readme a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <u.h>
#include <libc.h>
#include <stdio.h>

// FIXME: assumes vga font
int
getcols(void)
{
	int x1, y1, x2, y2;
	FILE* fp;

	fp = fopen("/dev/wctl", "r");

	fscanf(fp, "%d %d %d %d", &x1, &y1, &x2, &y2);

	fclose(fp);

	return (x2 - x1) / 8 / 2 * 2 - 4;
}

void
main(void)
{
	while(1)
	{
		int cols = getcols();
		char* outbuf1 = calloc(cols + 1, 1);
		char* outbuf2 = calloc(cols + 1, 1);
		for (int i = 0; i < (cols / 2); i ++)
		{
			if (rand() % 2)
			{
				strcat(outbuf1, " /");
				strcat(outbuf2, "/ ");
			}
			else
			{
				strcat(outbuf1, "\\ ");
				strcat(outbuf2, " \\");
			}
		}
		print("%s\n%s\n", outbuf1, outbuf2);
		free(outbuf1);
		free(outbuf2);
	}
}