Hi there, I\'m trying to write a code to describe movement of knight in a chess
ID: 3624142 • Letter: H
Question
Hi there,
I'm trying to write a code to describe movement of knight in a chess game using two dimensional arrays!!
I have done it without using the array!! plz help me to convert it using arrays !!I need this as soon as possible please!!
here is my code:
#include
using namespace std;
int start;
int i,j;// declare two variables
int knight [8][8]; // declare two dimentional array to represent the chess board.
int main()
{
cout<cout<<"This is the Chess board !! ";
cout<
for( i=0; i<8; i++)
{
for(j=0; j<8;j++)
{
cout<<" "<cin>>i>>j;
cout<cout<<"you can move to ";
if (((i+1>0)&&(i+1<8))&&((j+2>0)&&(j+2<8)))
{
cout<}
if (((i+1>0)&&(i+1<8))&&((j-2>0)&&(j-2<6)))
{
cout<}
if (((i-1>0)&&(i-1<7))&&((j-2>0)&&(j-2<6)))
{
cout<}
if (((i-1>0)&&(i-1<7))&&((j+2>0)&&(j+2<8)))
{
cout<}
if (((i-2>0)&&(i-2<6))&&((j-1>0)&&(j-1<7)))
{
cout<}
if (((i-2>0)&&(i-2<6))&&((j+1>0)&&(j+1<8)))
{
cout<}
if (((i+2>0)&&(i+2<8))&&((j-1>0)&&(j-1<7)))
{
cout<}
if (((i+2>0)&&(i+2<8))&&((j+1>0)&&(j+1<8)))
{
cout<}
return 0;
}
Explanation / Answer
Dear.... #include using namespace std; struct Chess { char name; char color; int row; int col; }; const Chess Rook = {'R'}; const Chess Knight = {'N'}; const Chess Bishop = {'B'}; const Chess King = {'K'}; const Chess Queen = {'Q'}; const Chess Pawn = {'p'}; const Chess Empty = {' '}; void drawBoard(Chess Chesss[][8]); int main (int argc, char * const argv[]) { Chess Chesss[8][8]; drawBoard(Chesss); return 0; } void drawBoard(Chess Chesss[][8]) { //array location new type name color Chesss[7][0] = new Rook ('R', 'b'); Chesss[7][1] = new Knight ('N', 'b'); Chesss[7][2] = new Bishop ('B', 'b'); Chesss[7][3] = new King ('K', 'b'); Chesss[7][4] = new Queen ('Q', 'b'); Chesss[7][5] = new Bishop ('B', 'b'); Chesss[7][6] = new Knight ('N', 'b'); Chesss[7][7] = new Rook ('R', 'b'); //set the blank Chesss and pawns for (int col = 0; colRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.