So, I am making a chess game, however I cannot correctly move part of the bishop.
This is my chessboard:
string board[8][8] = { {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "B" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"}, {"_" , "_", "_" , "_" ,"_", "_" , "_" , "_"} };
Here is the Draw function for drawing boards.
void Draw() { for( int i = 0; i < 8; i++ ) { for( int j = 0; j < 8; j++ ) std::cout << board[ i ][ j ] << ' '; std::cout << '\n'; } cout<<"\n"; }
The bishop's movement code is still.
if (board[x][y] == "B") { //Highlight the users chosen piece board[x][y] = "\033[0;31mB\033[0m"; //Now showing available moves the chosen bishop can move to for(int counter=1; counter <=7; counter++) { if(board[x+counter][y+counter] == "_") { //if there is an empty space, then place X to show peice can move there board[x+counter][y+counter] = "X"; } else { //if cannot move their ,then break break; } } }
Here is my problem. It shows X spaces that a piece can move to the user in some places on the board. however, when a piece is in certain places in the array, like the place it is in the code of the board. It overlaps and displays the Xs on the other side of the board, instead of stopping the drawing of Xs when they are not "_".