As I have posted in previous posts in this section- I take time away from the course to attempt to put things together based on the things we learned so far.
I thought that it would be fun to put together a c-prompt version of a board game classic- chess.
My code as of right now only constructs the layout of our board and pieces; I’ll continue to add to this and edit as we go through the course.
The main point of this practice today was revisiting the For and if statements.
Also; I touched lightly in ‘multidimensional’ arrays and enumerators. The " int Chessboard[8][8]" declared an array of 8 rows by 8 columns.
My next version will likely be built and changed in the header file via classes.
But for now; to carry on with our lectures. Hope you guys like it!
int Chessboard[8][8];
void PrintBoard();
void InitializeBoard();
int main()
{
InitializeBoard();
PrintBoard();
std::string Hold;
std::getline(std::cin, Hold);
return 0;
}
void PrintBoard()
{
for (int print = 0; print <= 7; print++)
{
std::cout << "\n";
for (int print2 = 0; print2 <= 7; print2++)
{
if (Chessboard[print][print2] < 9)
{
std::cout << " ";
};
std::cout << " " << Chessboard[print][print2];
}
};
return;
}
void InitializeBoard()
{
//setting values to black pieces
enum Blackpiece
{
Empty = 0,
Bpawn,
Brook,
Bknight,
Bbishop,
Bqueen,
Bking,
};
// setting values to white pieces
enum Whitepiece
{
Wpawn = 11,
Wrook,
Wknight,
Wbishop,
Wqueen,
Wking,
};
//setting values to white pieces
//Initialize values for the chessboard
Chessboard[0][0] = Chessboard[0][7] = Wrook;
Chessboard[0][1] = Chessboard[0][6] = Wknight;
Chessboard[0][2] = Chessboard[0][5] = Wbishop;
Chessboard[0][3] = Wqueen;
Chessboard[0][4] = Wking;
Chessboard[1][0] = Chessboard[1][1] = Chessboard[1][2] = Chessboard[1][3] = Chessboard[1][4] = Chessboard[1][5] = Chessboard[1][6] = Chessboard[1][7] = Wpawn;
Chessboard[6][0] = Chessboard[6][1] = Chessboard[6][2] = Chessboard[6][3] = Chessboard[6][4] = Chessboard[6][5] = Chessboard[6][6] = Chessboard[6][7] = Bpawn;
Chessboard[7][0] = Chessboard[7][7] = Brook;
Chessboard[7][1] = Chessboard[7][6] = Bknight;
Chessboard[7][2] = Chessboard[7][5] = Bbishop;
Chessboard[7][3] = Bking;
Chessboard[7][4] = Bqueen;
}