• Advertisement
Sign in to follow this  

c++ chess

This topic is 3458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am making a chess game in c++. i am going to use an array. the problem is that i sont no how i would add to it in orde to change his positoin. the code looks like this: ______________________________________________________________________________ #include <iostream> #include <conio.h> using namespace std; int main() { string a; char chessboard [8][8] = {}; chessboard[0][7] = 'R';// rook chessboard[7][0] = 'R';// rook chessboard[7][7] = 'R';// rook chessboard[0][0] = 'R';// rook for(int i = 0; i<9; i++){ for(int j = 0; j<9; j++){ cout << chessboard[i][j] << " "; } cout << endl; } cout << "what peice would you like to move and where (ex rook a 2)?" << endl; cin >> a; getch(); return 0; } _____________________________________________________________________ (thats not the whole list of pieces obviously!) im planning on using an if statement such as this: ____________________________________________________________________ if(a == rook a 2) _____________________________________________________________________ but the thing is that if the rook is at the starting postion(a 1) then how would i add to the array to change the rooks position? please help thanks, lookybooop

Share this post


Link to post
Share on other sites
Advertisement
The same way that you put it in to start with. Just remember to clear the old square too.

Share this post


Link to post
Share on other sites
Quote:
Original post by lookyboop

char chessboard [8][8] = {};

for(int i = 0; i<9; i++){
for(int j = 0; j<9; j++){
cout << chessboard[i][j] << " ";
}
cout << endl;
}


Is that the actual code? Cause you're accessing your array out of bounds, the loop condition should be <8, not <9.

Share this post


Link to post
Share on other sites
Quote:
Original post by DevFred
Quote:
Original post by lookyboop

char chessboard [8][8] = {};

for(int i = 0; i<9; i++){
for(int j = 0; j<9; j++){
cout << chessboard[i][j] << " ";
}
cout << endl;
}


Is that the actual code? Cause you're accessing your array out of bounds, the loop condition should be <8, not <9.


no i just wrote it quicly it probly does have bugs

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement