summary refs log tree commit diff
path: root/minic
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-11-08 14:28:05 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-11-08 14:28:05 -0500
commit058515be5e1e136d40ae9899002e4ecdaee67e6b (patch)
treedbf30e746a4cdf2d3bad7502758fd07581c7a1de /minic
parentfbf74646e1c2bd1a7b9def14b9d3e7f304a69e35 (diff)
downloadroux-058515be5e1e136d40ae9899002e4ecdaee67e6b.tar.gz
add new test in minic
Diffstat (limited to 'minic')
-rw-r--r--minic/test/knight.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/minic/test/knight.c b/minic/test/knight.c
new file mode 100644
index 0000000..273e651
--- /dev/null
+++ b/minic/test/knight.c
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+void *calloc();
+
+int N;
+int **b;
+
+board()
+{
+	int x;
+	int y;
+
+	for (y=0; y<8; y++) {
+		for (x=0; x<8; x++)
+			printf(" %02d", b[x][y]);
+		printf("\n");
+	}
+	printf("\n");
+	return 0;
+}
+
+chk(int x, int y)
+{
+	if (x < 0 || x > 7 || y < 0 || y > 7)
+		return 0;
+	return b[x][y] == 0;
+}
+
+go(int k, int x, int y)
+{
+	int i;
+	int j;
+
+	b[x][y] = k;
+	if (k == 64) {
+		if (x != 2 && y != 0 && abs(x-2) + abs(y) == 3) {
+			board();
+			N++;
+			if (N == 10)
+				exit(0);
+		}
+	} else
+		for (i=-2; i<=2; i++)
+			for (j=-2; j<=2; j++) 
+				if (abs(i) + abs(j) == 3 && chk(x+i, y+j)) 
+					go(k+1, x+i, y+j);
+	b[x][y] = 0;
+	return 0;
+}
+
+main()
+{
+	int i;
+
+	b = calloc(8, sizeof (int *));
+	for (i=0; i<8; i++)
+		b[i] = calloc(8, sizeof (int));
+	go(1, 2, 0);
+}