I need to make a chessboard to advertise the moves of the "elephant" I decided to make in the form of a maze, but he does not want to find a way. In the file: 1 is a barrier; 0 is the path.

Here are the conditions of the problem:

It is considered a chessboard of size nХn with obstacles. A minimum number of moves required to move a madman (elephant) is required for printing, observing the rules of the game of chess and avoiding obstacles from the initial position to the final position. It is believed that in the initial and final position of the elephant there are no obstacles.

Here is the code:

#include<iomanip> #include<iostream> #include<fstream> using namespace std; int n,m,L[10][10],sol[10][10],nrsol=0,is,js; int dx[]={-1,0,1,0},dy[]={0,1,0,-1}; void citire() { int i,j; //читает фаил с дорогой ifstream f("C:\\Users\\nickk\\Desktop\\New folder\\labirint.txt"); f>>n>>m>>is>>js; for(i=1;i<=n;i++) for(j=1;j<=m;j++) f>>L[i][j]; } void afisare() { int i,j; nrsol++; cout<<"Solutia nr "<<nrsol<<endl; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) cout<<setw(3)<<sol[i][j]; cout<<endl; } cout<<endl; } void traseu(int i, int j, int pas) { int inou,jnou,k; for(k=0;k<4;k++) { inou=i+dx[k]; jnou=j+dy[k]; if(inou>=1 && inou<=n && jnou>=1 && jnou<=m) if(L[inou][jnou]==0 && sol[inou][jnou]==0) { sol[inou][jnou]=pas; if(inou==1 || inou==n || jnou==1 || jnou==m) afisare(); traseu(inou,jnou,pas+1); sol[inou][jnou]=0; } } } int main() { citire(); sol[is][js]=1; traseu(is,js,2); cout<<nrsol; } 

Here is the screen file:

enter image description here

  • And what it means to advertise the moves of the "elephant". Predict? - Unick
  • As it should, yes something like this - Brasovean Nicolae

0