RE: [Dev-C++] reg-Knight's tour problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Santiago P. C. <San...@yd...> - 2002-03-07 14:09:41
|
Hi to *,
There's NO compiler defect (with this issue), so... Don't panic! ;o)
The variables 'i' & 'j' are class' members, defined on line:
> int row_loc,pos,i,j;
Just my 2 cents, regards
Santy
-----Original Message-----
From: Ioannis Vranos [mailto:no...@ya...]
Sent: Thursday, March 07, 2002 2:21 PM
To: Dev-C++
Subject: RE: [Dev-C++] reg-Knight's tour problem
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Mohammed Riyaz
> Sent: Thursday, March 07, 2002 2:00 PM
> To: dev...@li...
> Subject: [Dev-C++] reg-Knight's tour problem
>
>
> hey,
> I had a look at the code sent in. Am new to programming, my
> code sux when
> compared to that. :D .If any one of you cud fix this code
> ,help me out. -Riyaz
>
> #include <iostream.h>
> #include <stdlib.h>
Useless
> #include <process.h>
Pre-ANSI header file declaration
> class knight
> {
> int chess[8][8],location[65][10],denied[64];
> int row_loc,pos,i,j;
> public:
> knight();
> void assignment(void);
> int value(int);
> void refresh(void);
> int append(int ,int);
> };
> knight::knight(void)
> {
> row_loc=-1;
> i=j=0;
> for(int m=0;m<8;m++)
> for(int n=0;n<8;n++)
> chess[m][n]=0;
> for(int m=0;m<65;m++)
> for(int n=0;n<10;n++)
> location[m][n]=0;
> for(int m=0;m<64;m++)
> denied[m]=99;
> assignment();
> }
> void knight::assignment(void)
> {
> chess[i][j]=1;
Where are i, j defined? Strangely it compiles in MINGW32!!!! (compiler
defect).
> refresh();
> pos=value(j+(8*i));
> i=pos/8;
> j=pos%8;
> assignment();
// Recursion never ends!
> }
> int knight::value(int val)
> {
> row_loc++;
> int temp=1;
> int lock,ii,jj;
> location[row_loc][0]=val;
> ii=val/8;
> jj=val%8;
> if(jj==0)
> {
> if(ii>=1)
> {
> if(ii>=2)
> {lock=append(val-15,temp);if(lock==0) {temp++;}}
> lock=append(val-6,temp);if(lock==0) {temp++;}
> }
> if(ii<=6)
> {
> if(ii<=5)
> {lock=append(val+17,temp);if(lock==0) {temp++;}}
> lock=append(val+10,temp);if(lock==0) {temp++;}
> }
> }
> if(jj==7)
> {
> if(ii>=1)
> {
> if(ii>=2)
> {lock=append(val-17,temp);if(lock==0) {temp++;}}
> lock=append(val-10,temp);if(lock==0) {temp++;}
> }
> if(ii<=6)
> {
> if(ii<=5)
> {lock=append(val+15,temp);if(lock==0) {temp++;}}
> lock=append(val+6,temp);if(lock==0) {temp++;}
> }
> }
> if(jj==1)
> {
> if(ii>=1)
> {
> if(ii>=2)
> {
> lock=append(val-15,temp);if(lock==0) {temp++;}
> lock=append(val-17,temp);if(lock==0) {temp++;}
> }
> lock=append(val-6,temp);if(lock==0) {temp++;}
> }
> if(ii<=6)
> {
> if(ii<=5)
> {
> lock=append(val+17,temp);if(lock==0) {temp++;}
> lock=append(val+15,temp);if(lock==0) {temp++;}
> }
> lock=append(val+10,temp);if(lock==0) {temp++;}
> }
> }
> if(jj==6)
> {
> if(ii>=1)
> {
> if(ii>=2)
> {
> lock=append(val-15,temp);if(lock==0) {temp++;}
> lock=append(val-17,temp);if(lock==0) {temp++;}
> }
> lock=append(val-10,temp);if(lock==0) {temp++;}
> }
> if(ii<=6)
> {
> if(ii<=5)
> {
> lock=append(val+17,temp);if(lock==0) {temp++;}
> lock=append(val+15,temp);if(lock==0) {temp++;}
> }
> lock=append(val+6,temp);if(lock==0) {temp++;}
> }
> }
> if(jj>1 && jj<6)
> {
> if(ii>=1)
> {
> if(ii>=2)
> {
> lock=append(val-17,temp);if(lock==0) {temp++;}
> lock=append(val-15,temp);if(lock==0) {temp++;}
> }
> lock=append(val-10,temp);if(lock==0) {temp++;}
> lock=append(val-6,temp);if(lock==0) {temp++;}
> }
> if(ii<=6)
> {
> if(ii<=5)
> {
> lock=append(val+15,temp);if(lock==0) {temp++;}
> lock=append(val+17,temp);if(lock==0) {temp++;}
> }
> lock=append(val+6,temp);if(lock==0) {temp++;}
> lock=append(val+10,temp);if(lock==0) {temp++;}
> }
> }
> lock=append(-1,temp);
> code:
> if(location[row_loc][1]==-1)
> {
> ii=location[row_loc][0]/8;
> jj=location[row_loc][0]%8;
> chess[ii][jj]=0;
> row_loc--;
> if(row_loc<0) {cout<<"NO
> SOLUTION";system("pause");exit(0);}
> for(int m=1;m<9;m++)
> location[row_loc][m]=location[row_loc][m+1];
> goto code;
> }
> return location[row_loc][1];
> }
> void knight::refresh(void)
> {
> int l,tot;
> l=tot=0;
> for(int m=0;m<64;m++)
> denied[m]=99;
> for(int m=0;m<8;m++)
> {
> for(int n=0;n<8;n++)
> {
> if(chess[m][n]==1)
> {
> if(l==63)
> {
> cout<<"RESULT :"<<endl;
> for(int k=0;k<64;k++)
> cout<<denied[k]<<" ";
> system("pause");
> }
> tot=n+(8*m);
> denied[l]=tot;
> l++;
> }
> }
> }
> }
> int knight::append(int val1,int temp1)
> {
> int lock=0;
> for(int m=0;m<64;m++)
> if(denied[m]==val1)
> {lock=1;break;}
> if(!lock)
> location[row_loc][temp1]=val1;
> return lock;
> }
> void main()
> {knight k;}
int main()
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--------------------------------------------------------------------------------------
This message and any files transmitted with it are confidential and intended solely
for the use of the individual or entity to whom they are addressed. No confidentiality
or privilege is waived or lost by any wrong transmission.
If you have received this message in error, please immediately destroy it and kindly
notify the sender by reply email.
You must not, directly or indirectly, use, disclose, distribute, print, or copy any
part of this message if you are not the intended recipient. Opinions, conclusions and
other information in this message that do not relate to the official business of
People Communications S.A. shall be understood as neither given nor endorsed by it.
--------------------------------------------------------------------------------------
|