I realize that system("pause"); is bad coding. I found the error when I tried to remove the system commands from my code.
move is a virtual function in my piece class. My piece class probably should be an abstract class, but I needed to use piece addresses to reference subclass objects.
Code: Select all
void piece::move (char moves[][10], int board[]){}
The move function used should be refering to rook, knight, bishop, queen, king and pawn objects. These are subclasses of the piece class
When I used cout<<x; the program crashed when x==8, locats[8]->get_occupant->move(moves, board); would be accessing the pawn move function if it was working correctly.
Code: Select all
void pawn::move(char moves[][10], int board[])
{
int x;
have_moved=0;
for (int x=0; x<256&&moves[0][x]!='\0'; x++){}
if (player==1)
{
if (row==2&&board[columnrowtolocation(column, row+1)]==0&&board[columnrowtolocation(column, row+2)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]=dtoa(row+2);
moves[x++][4]='\0';
}
if (row+1<9&&board[columnrowtolocation(column, row+1)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]=dtoa(row+1);
moves[x++][4]='\0';
}
if (column-1>='a'&&row+1<8&&board[columnrowtolocation(column-1, row+1)]!=0&&board[columnrowtolocation(column-1, row+1)]!=player)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column-1;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
}
if (column+1<'i'&&row+1<8&&board[columnrowtolocation(column+1, row+1)]!=0&&board[columnrowtolocation(column+1, row+1)]!=player)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column+1;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
}
if (row==5&&column+1<'i'&&board[columnrowtolocation(column+1, row)]==2&&location->get_plus1()!=NULL&&location->get_plus1()->get_occupant()!=NULL&&location->get_plus1()->get_occupant()->get_type()=='p'&&board[columnrowtolocation(column+1, row+1)]==0&&location->get_plus1()->get_occupant()->get_have_moved())
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column+1;
moves[x++][5]=dtoa(row+1);
}
if (row==5&&column-1>='a'&&board[columnrowtolocation(column-1, row)]==2&&location->get_minus1()!=NULL&&location->get_minus1()->get_occupant()!=NULL&&location->get_minus1()->get_occupant()->get_type()=='p'&&board[columnrowtolocation(column-1, row+1)]==0&&location->get_minus1()->get_occupant()->get_have_moved())
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column-1;
moves[x++][5]=dtoa(row+1);
}
if (row+1==8&&column+1<'i'&&board[columnrowtolocation(column+1, row+1)]==2)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]='x';
moves[x][4]=column+1;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
}
if (row+1==8&&column-1>='a'&&board[columnrowtolocation(column-1, row+1)]==2)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]='x';
moves[x][4]=column-1;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row+1);
moves[x++][7]='\0';
}
if (row+1==8&&board[columnrowtolocation(column, row+1)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]=column;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]=column;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]=column;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]=column;
moves[x][5]=dtoa(row+1);
moves[x++][6]='\0';
}
}
else if (player==2)
{
if (row==7&&board[columnrowtolocation(column, row-1)]==0&&board[columnrowtolocation(column, row-2)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]=dtoa(row-2);
moves[x++][4]='\0';
}
if (row-1>1&&board[columnrowtolocation(column, row-1)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]=dtoa(row-1);
moves[x++][4]='\0';
}
if (row-1>1&&column-1>='a'&&row-1>0&&board[columnrowtolocation(column-1, row-1)]!=0&&board[columnrowtolocation(column-1, row-1)]!=player)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column-1;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
}
if (column+1<'i'&&row-1>1&&board[columnrowtolocation(column+1, row-1)]!=0&&board[columnrowtolocation(column+1, row-1)]!=player)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column+1;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
}
if (row==4&&column+1<'i'&&board[columnrowtolocation(column+1, row)]==1&&location->get_plus1()!=NULL&&location->get_plus1()->get_occupant()!=NULL&&location->get_plus1()->get_occupant()->get_type()=='p'&&board[columnrowtolocation(column+1, row-1)]==0&&location->get_plus1()->get_occupant()->get_have_moved())
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column+1;
moves[x++][5]=dtoa(row-1);
}
if (row==4&&column-1>='a'&&board[columnrowtolocation(column+1, row)]==1&&location->get_plus1()!=NULL&&location->get_plus1()->get_occupant()!=NULL&&location->get_plus1()->get_occupant()->get_type()=='p'&&board[columnrowtolocation(column+1, row-1)]==0&&location->get_plus1()->get_occupant()->get_have_moved())
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]=column;
moves[x][3]='x';
moves[x][4]=column+1;
moves[x++][5]=dtoa(row-1);
}
if (row-1==1&&board[columnrowtolocation(column, row-1)]==0)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]=column;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]=column;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]=column;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]=column;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
}
if (row-1==1&&column+1<'i'&&board[columnrowtolocation(column+1, row-1)]==1)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]='x';
moves[x][4]=column+1;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]='x';
moves[x][5]=column+1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
}
if (row-1==1&&column-1>='a'&&board[columnrowtolocation(column-1, row-1)]==1)
{
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='R';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='N';
moves[x][4]='x';
moves[x][4]=column-1;
moves[x][5]=dtoa(row-1);
moves[x++][6]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='B';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
moves[x][0]=column;
moves[x][1]=dtoa(row);
moves[x][2]='P';
moves[x][3]='Q';
moves[x][4]='x';
moves[x][5]=column-1;
moves[x][6]=dtoa(row-1);
moves[x++][7]='\0';
}
}
}
my other move functions that it could be referencing are
Code: Select all
void king::move(char moves[][10], int board[])
{
if (have_moved)
{
castlequeen=0;
castleking=0;
}
int y;
const int z=1;
for (int y=0; y<256&&moves[y][0]!=0; y++){}
if (column+z<'i'&&board[columnrowtolocation(column+z, row)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column+z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
}
if (column-z>='a'&&board[columnrowtolocation(column-z, row)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column-z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
}
if (row+z<9&&board[columnrowtolocation(column, row+z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
}
if (row-z>0&&board[columnrowtolocation(column, row-z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
}
if(column+z<'i'&&row+z<9&&board[columnrowtolocation(column+z, row+z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column+z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
}
if(column-z>='a'&&row-z>0&&board[columnrowtolocation(column-z, row-z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column-z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
}
if(row+z<9&&column-z>='a'&&board[columnrowtolocation(column-z, row+z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column-z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
}
if(row-z>0&&column+z<'i'&&board[columnrowtolocation(column+z, row-z)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='K';
if (board[columnrowtolocation(column+z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
}
if (castleking&&board[columnrowtolocation(column+1, row)]==0&&board[columnrowtolocation(column+2, row)]==0)
stringcopy(moves[y++], "O-O");
if (castlequeen&&board[columnrowtolocation(column-1, row)]==0&&board[columnrowtolocation(column-2, row)]==0&&board[columnrowtolocation(column-3, row)]==0)
stringcopy(moves[y++], "O-O-O");
}
//*********************************************************************************************************
void queen::move(char moves[][10], int board[])
{
int y;
for (int y=0; y<256&&moves[y][0]!=0; y++){}
for(int z=1;column+z<'i'&&row+z<9&&board[columnrowtolocation(column+z, row+z)]!=player; z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column+z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row+z)]!=0)
break;
}
for(int z=1; column-z>='a'&&row-z>0&&board[columnrowtolocation(column-z, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column-z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row-z)]!=0)
break;
}
for(int z=1; row+z<9&&column-z>='a'&&board[columnrowtolocation(column-z, row+z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column-z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row+z)]!=0)
break;
}
for(int z=1; row-z>0&&column+z<'i'&&board[columnrowtolocation(column+z, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column+z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row-z)]!=0)
break;
}
for(int z=1;column+z<'i'&&board[columnrowtolocation(column+z, row)]!=player; z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column+z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row)]!=0)
break;
}
for(int z=1; column-z>='a'&&board[columnrowtolocation(column-z, row)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column-z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row)]!=0)
break;
}
for(int z=1; row+z<9&&board[columnrowtolocation(column, row+z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column, row+z)]!=0)
break;
}
for(int z=1; row-z>0&&board[columnrowtolocation(column, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='Q';
if (board[columnrowtolocation(column, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column, row-z)]!=0)
break;
}
}
//******************************************************************************************************************
void knight::move(char moves[][10], int board[])
{
int y;
for (y=0; y<256&&moves[y][0]!='\0'; y++){}
if (row+1<9&&column+2<'i'&&board[columnrowtolocation(column+2, row+1)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column+2, row+1)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+2;
moves[y][x++]=dtoa(row+1);
moves[y++][x]='\0';
//cout << "\n"<<moves[y-1]<<"\n";
}
if (row+2<9&&column+1<'i'&&board[columnrowtolocation(column+1, row+2)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column+1, row+2)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+1;
moves[y][x++]=dtoa(row+2);
moves[y++][x]='\0';
//cout <<"\n"<< moves[y-1]<<"\n";
}
if (row-2>0&&column+1<'i'&&board[columnrowtolocation(column+1, row-2)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column+1, row-2)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+1;
moves[y][x++]=dtoa(row-2);
moves[y++][x]='\0';
}
if (row-1>0&&column+2<'i'&&board[columnrowtolocation(column+2, row-1)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column+2, row-1)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+2;
moves[y][x++]=dtoa(row-1);
moves[y++][x]='\0';
}
if (row+1<9&&column-2>='a'&&board[columnrowtolocation(column-2, row+1)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column-2, row+1)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-2;
moves[y][x++]=dtoa(row+1);
moves[y++][x]='\0';
}
if (row+2<9&&column-1>='a'&&board[columnrowtolocation(column-1, row+2)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column-1, row+2)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-1;
moves[y][x++]=dtoa(row+2);
moves[y++][x]='\0';
//cout <<"\n"<< moves[x-1]<<"\n";
}
if (row-2>0&&column-1>='a'&&board[columnrowtolocation(column-1, row-2)]!=player)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column-1, row-2)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-1;
moves[y][x++]=dtoa(row-2);
moves[y++][x]='\0';
}
if (row-1>0&&column-2>='a'&&board[columnrowtolocation(column-2, row-1)]!=player)
{
//system ("pause");
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='N';
if (board [columnrowtolocation(column-2, row-1)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-2;
moves[y][x++]=dtoa(row-1);
moves[y++][x]='\0';
}
}
//***************************************************************************************************************
void bishop::move(char moves[][10], int board[])
{
int y;
for (y=0; y<256&&moves[y][0]!=0; y++){}
for(int z=1;column+z<'i'&&row+z<9&&board[columnrowtolocation(column+z, row+z)]!=player; z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='B';
if (board[columnrowtolocation(column+z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row+z)]!=0)
break;
}
for(int z=1; column-z>='a'&&row-z>0&&board[columnrowtolocation(column-z, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='B';
if (board[columnrowtolocation(column-z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row-z)]!=0)
break;
}
for(int z=1; row+z<9&&column-z>='a'&&board[columnrowtolocation(column-z, row+z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='B';
if (board[columnrowtolocation(column-z, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row+z)]!=0)
break;
}
for(int z=1; row-z>0&&column+z<'i'&&board[columnrowtolocation(column+z, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='B';
if (board[columnrowtolocation(column+z, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row-z)]!=0)
break;
}
}
//****************************************************************************************************
void rook::move(char moves[][10], int board[])
{
int y;
for (y=0; y<256&&moves[y][0]!=0; y++){}
for(int z=1;column+z<'i'&&board[columnrowtolocation(column+z, row)]!=player; z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='R';
if (board[columnrowtolocation(column+z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column+z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
if (board[columnrowtolocation(column+z, row)]!=0)
break;
}
for(int z=1; column-z>='a'&&board[columnrowtolocation(column-z, row)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='R';
if (board[columnrowtolocation(column-z, row)]!=0)
moves[y][x++]='x';
moves[y][x++]=column-z;
moves[y][x++]=dtoa(row);
moves[y++][x]=0;
if (board[columnrowtolocation(column-z, row)]!=0)
break;
}
for(int z=1; row+z<9&&board[columnrowtolocation(column, row+z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='R';
if (board[columnrowtolocation(column, row+z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row+z);
moves[y++][x]=0;
if (board[columnrowtolocation(column, row+z)]!=0)
break;
}
for(int z=1; row-z>0&&board[columnrowtolocation(column, row-z)]!=player;z++)
{
int x=0;
moves[y][x++]=column;
moves[y][x++]=dtoa(row);
moves[y][x++]='R';
if (board[columnrowtolocation(column, row-z)]!=0)
moves[y][x++]='x';
moves[y][x++]=column;
moves[y][x++]=dtoa(row-z);
moves[y++][x]=0;
if (board[columnrowtolocation(column, row-z)]!=0)
break;
}
}
I guess I don't understand exactly what system commands do. I thought that system("pause"); or system("color 0"); should not affect any of the data in my program. Is there anything that system commands set to default to make it more robust? Is there a quick debugging tool for bounds checking because I think I have checked most places where that could occur, and I don't know how cout, printf, or system functions could affect the index I use for an array. If there isn't a quick way to do this, where should I start because checking the values of my indexes before every time I use an index in the char moves[][] array will make a lot of if statements, and mathematically I shouldn't be out of bounds, and the program works perfectly when a system command is written every time before the for loop, for(int x=0;x<64; x++) shown in the previous post, is run.