commit d8901fd63006716a8b142fdef2671a810e2ea5a3 Author: neingeist Date: Sun Jun 2 16:07:25 2002 +0000 initial CVS commit 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