what am I suppose to do?

I am confused about what to do in the main function as well as the update_board function. Any help would greatly be appreciated.




#include <iostream> // I/O streams cout & cin
#include <cstdlib> // Common routines (e.g., system)

using namespace std; // Import standard namespace

const int SIZE = 8; // 8x8 chessboard
const char EMPTY = '_'; // character for empty cell

// display_game(board): Displays chess BOARD as 8x8 character grid
//
void display_game (char board[SIZE][SIZE])
{
cout << "Current board:" << endl;
for (int row = 0; row < SIZE; row++) {
for (int col = 0; col < SIZE; col++) {
int black_score = 0;
int white_score = 0;
int scores[256] = {};
scores['p'] = 1;
scores['P'] = 1;
//.... <--- what am I suppose to do here? scores['q'] = 9;
scores['Q'] = 9;


}
cout << endl;
}
cout << endl;
}

// valid_mode(board, from_row, from_col, to_row, to_col): make sure the move from (from_row, from_col) to (to_row, to_col) makes sense for BOARD
//
bool valid_move (char board[SIZE][SIZE], int from_row, int from_col, int to_row, int to_col)
{
bool valid = false;

while (! valid) {
int from_row = rand() % SIZE;
int from_col = rand() % SIZE;
int to_row = rand() % SIZE;
int to_col = rand() % SIZE;
valid = validate_move(board, from_row, from_col, to_row, to_col);
}
return (valid);
}

// update_board(board, from_row, from_col, to_row, to_col): update BOARD to reflect move from (from_row, from_col) to (to_row, to_col) makes sense for BOARD
//
void update_board (char board[SIZE][SIZE], int from_row, int from_col, int to_row, int to_col)
{
// TODO...



}

// moderate_game(board): reads each move and updates the board accordingly
//
void moderate_game (char board[SIZE][SIZE])
{
// Read while more good input
while (cin.good()) {
char move_type;

// Read the move type letter (C or M)
cout << "Enter next move: ";
cin >> move_type;

// Process the move type
if (cin.eof()) {
// do nothing
}
else if (move_type == 'C') {
string rest;
getline(cin, rest);
cerr << "Ignoring comment (" << rest << ")" << endl;
}
else if (move_type != 'M') {
cout << "Error: Invalid move type (" << move_type << ")" << endl;
}
else {
// Read and validate the starting and ending coordinates
int from_row, from_col, to_row, to_col;
cin >> from_row >> from_col >> to_row >> to_col;

if (! valid_move(board, from_row, from_col, to_row, to_col)) {
cerr << "Invalid move" << endl;
}
else {
update_board(board, from_row, from_col, to_row, to_col);
display_game(board);
}
}
}
}

// main: Entry point for program
//
int main ()
{
char board[SIZE][SIZE] = // Check board with black on top (uppercase)
{
{'R', 'H', 'B', 'Q', 'K', 'B', 'H', 'R'},
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
{'_', '_', '_', '_', '_', '_', '_', '_'},
{'_', '_', '_', '_', '_', '_', '_', '_'},
{'_', '_', '_', '_', '_', '_', '_', '_'},
{'_', '_', '_', '_', '_', '_', '_', '_'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'r', 'h', 'b', 'q', 'k', 'b', 'h', 'r'},

};

display_game(board);
moderate_game(board);

// Exit with successful execution status
#if defined(WIN32)
system("PAUSE"); // For Dev++ under Windows
#endif
return (0);
}
the function display board should look like this

1
2
3
4
5
6
7
8
for(int nRow = 0; nRow < SIZE; nRow++)
{
     for(int nCol =0; nCol < SIZE; nCol++)
     {
            cout << board[nRow][nCol];
     }
     cout << endl;
}


I don't know what else you are trying to do with it. Try to keep you functions simple very direct in task. I don't what the calculations you are doing in it are. They look like they need to be put in a initialization function not a display function.

Last edited on
Topic archived. No new replies allowed.