/**
Name:The MOVMENT OF A HOURSE IN A CHESS
Copyright:wWw.CodeCorona.cOm
Author:arash_j13
May 29,2007
*/
#include <iostream>
#include <conio.h>
#include <cstdlib>
#define row 8
#define col 8
using namespace std;
//***************************FUNCTION PROTOTYPE*********************************
void print(int[row][col]);
void input(int&,int&);
void move (int[row][col],int,int);
bool motion(int&,int&,int);
//*****************************MAIN FUNCTION************************************
int main()
{
int x,y,table[row][col]={0};
input(x,y);
move(table,x,y);
cout<<"the final table to made with your movment is:\n\n";
print(table);
system("pause");
return EXIT_SUCCESS;
}
//******************************************************************************
void input(int&x,int&y)
{
char z=0;
do
{
system("cls");
cout<<z<<"please enter the row for start between(0 -7):";
cin>>x;
cout<<"\nplease enter the coloum for start (0-7):";
cin>>y;
z='\a';
}
while((x<0||x>col-1)||(y<0||y>row-1));
}
//******************************************************************************
void move(int t[row][col],int x,int y)
{
t[x][y]=1;
cout<<"the start point for this board is row "<<x<<" && coloum "<<y<<endl<<endl;
for(int k=0,number ; k < 8 ; )
{
char alert=0;
do
{
cout<<alert;
system("cls");
print(t);
getch();
cout<<"\nthe poosible movment in the board."
"\n\nnumber 1: 2 cell top && 1 cell left"
"\n\nnumber 2: 2 cell top && 1 cell right"
"\n\nnumber 3: 2 cell left && 1 cell down"
"\n\nnumber 4: 2 cell left && 1 cell top."
"\n\nnumber5: 2 cell right && 1 cell down"
"\n\nnumber 6: 2 cell right && 1 cell top"
"\n\nnumber 7: 2 cell down && 1 cell right"
"\n\number 8: 2 cell down && 1 cell left."
"\n \n\nplease choos one of this movment:";
cin>>number;
alert='\a';
}
while(number<1 || number>9);
if(!motion(x,y,number))
cout<<"\athis movment can not be done in chess.\n";
else
t[x][y]=++k;
}
}
//******************************************************************************
void print(int t[row][col])
{
cout<<" ";
for(int i=0;i<row;i++,cout<<endl<<endl<<" ")
for(int j=0;j<col;cout<<t[i][j++]<<" ");
}
//******************************************************************************
bool motion(int &x,int&y,int t)
{
int h[]={-2,-2,1,-1,1,-1,2,2};
int v[]={-1,1,-2,-2,2,2,1,-1};
int xt,yt;
xt=h[--t]+x;
yt=v[t]+y;
if(xt < 0 || xt > col-1 || yt < 0 || yt > row-1)
return false;
x=xt;
y=yt;
return true;
}