From d8901fd63006716a8b142fdef2671a810e2ea5a3 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 2 Jun 2002 16:07:25 +0000 Subject: [PATCH] initial CVS commit --- Makefile | 3 +++ springer.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Makefile create mode 100644 springer.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a8cc5db --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +# $Id$ + +all: springer diff --git a/springer.c b/springer.c new file mode 100644 index 0000000..3a0e9fb --- /dev/null +++ b/springer.c @@ -0,0 +1,56 @@ +/* Lösung des Springerproblems + * $Id$ +*/ + +#define GROESSE 6 + +int schachbrett[GROESSE][GROESSE]; +long int zurueck; + +int springe(int x, int y, int s) { + schachbrett[x][y] = s; + + /* printf ("Zug %2d: %d %d\n",s,x,y); */ + + if (s==GROESSE*GROESSE) { + printf("yeah! %d Züge zurückgenommen!\n", zurueck); + zeigebrett(); + exit(0); + } + + if (gueltig(x-1,y+2)) springe(x-1,y+2,s+1); + if (gueltig(x+1,y+2)) springe(x+1,y+2,s+1); + if (gueltig(x+2,y+1)) springe(x+2,y+1,s+1); + if (gueltig(x+2,y-1)) springe(x+2,y-1,s+1); + if (gueltig(x+1,y-2)) springe(x+1,y-2,s+1); + if (gueltig(x-1,y-2)) springe(x-1,y-2,s+1); + if (gueltig(x-2,y-1)) springe(x-2,y-1,s+1); + if (gueltig(x-2,y+1)) springe(x-2,y+1,s+1); + +/* printf("oje: Nehme Zug zurück!\n"); + zeigebrett(); +*/ + zurueck++; + schachbrett[x][y] = 0; +} + +int gueltig(int x, int y) { + if ((x>=0) && (x=0) && (y