#include <iostream>
#include <time.h>
#include <stdlib.h>
struct Feld {
int x;
int y;
};
void cm_springen(Feld a);
int feld1[9][9];
bool feld2[9][9];
int i, j;
Feld aktfeld;
void cm_springen(Feld a) {
int u1, u2;
int liste[9][9];
Feld gew;
int temp;
for(u1=1;u1<=8;++u1) {
for(u2=1;u2<=8;++u2) {
liste[u1][u2] = 0;
if((u1<=7) && (u2<=6) && feld2[u1+1][u2+2]) liste[u1][u2]++;
if((u1<=7) && (u2>=3) && feld2[u1+1][u2-2]) liste[u1][u2]++;
if((u1>=2) && (u2<=6) && feld2[u1-1][u2+2]) liste[u1][u2]++;
if((u1>=2) && (u2>=3) && feld2[u1-1][u2-2]) liste[u1][u2]++;
if((u1<=6) && (u2<=7) && feld2[u1+2][u2+1]) liste[u1][u2]++;
if((u1<=6) && (u2>=2) && feld2[u1+2][u2-1]) liste[u1][u2]++;
if((u1>=3) && (u2<=7) && feld2[u1-2][u2+1]) liste[u1][u2]++;
if((u1>=3) && (u2>=2) && feld2[u1-2][u2-1]) liste[u1][u2]++;
}
}
temp = 9;
if((a.x<=7) && (a.y<=6) && feld2[a.x+1][a.y+2] && liste[a.x+1][a.y+2]<temp){
gew.x = a.x +1; gew.y = a.y +2; temp = liste[gew.x][gew.y]; }
if((a.x<=7) && (a.y>=3) && feld2[a.x+1][a.y-2] && liste[a.x+1][a.y-2]<temp){
gew.x = a.x +1; gew.y = a.y -2; temp = liste[gew.x][gew.y]; }
if((a.x>=2) && (a.y<=6) && feld2[a.x-1][a.y+2] && liste[a.x-1][a.y+2]<temp){
gew.x = a.x -1; gew.y = a.y +2; temp = liste[gew.x][gew.y]; }
if((a.x>=2) && (a.y>=3) && feld2[a.x-1][a.y-2] && liste[a.x-1][a.y-2]<temp){
gew.x = a.x -1; gew.y = a.y -2; temp = liste[gew.x][gew.y]; }
if((a.x<=6) && (a.y<=7) && feld2[a.x+2][a.y+1] && liste[a.x+2][a.y+1]<temp){
gew.x = a.x +2; gew.y = a.y +1; temp = liste[gew.x][gew.y]; }
if((a.x<=6) && (a.y>=2) && feld2[a.x+2][a.y-1] && liste[a.x+2][a.y-1]<temp){
gew.x = a.x +2; gew.y = a.y -1; temp = liste[gew.x][gew.y]; }
if((a.x>=3) && (a.y<=7) && feld2[a.x-2][a.y+1] && liste[a.x-2][a.y+1]<temp){
gew.x = a.x -2; gew.y = a.y +1; temp = liste[gew.x][gew.y]; }
if((a.x>=3) && (a.y>=2) && feld2[a.x-2][a.y-1] && liste[a.x-2][a.y-1]<temp){
gew.x = a.x -2; gew.y = a.y -1; temp = liste[gew.x][gew.y]; }
aktfeld.x = gew.x;
aktfeld.y = gew.y;
}
int main() {
for(i=1;i<=8;++i) {
for(j=1;j<=8;++j) {
feld2[i][j] = true;
}
}
srand((unsigned)time(NULL));
aktfeld.x = rand()%8 +1;
aktfeld.y = rand()%8 +1;
feld1[aktfeld.x][aktfeld.y] = 1;
feld2[aktfeld.x][aktfeld.y]=false;
std::cout<<aktfeld.x << "/" << aktfeld.y << "\t";
for(int r=2;r<=64;++r) {
cm_springen(aktfeld);
std::cout<<aktfeld.x << "/" << aktfeld.y << "\t";
feld1[aktfeld.x][aktfeld.y] = r;
feld2[aktfeld.x][aktfeld.y] = false;
}
std::cout<<"\n\n\n";
for(i=1;i<=8;++i) {
for(j=1;j<=8;++j){
std::cout<<"\t" << feld1[i][j];
}
std::cout<<"\n";
}
return 0;
}
|