C Help chess program
For the next step of this program, insert into your next program the Chess.h found in
the following link: (You can ignore the Chess class in this file because we will
be focusing on the ChessPiece class)
Implement Chess.cpp to provide implementation for the ChessPiece class. Then
run the following program: (Note the expected output shows up in the comment of this program)
******************************************
#include <iostream>
#include <string>
using namespace std;
#include "Chess.h"
void testOtherPieces()
{
// This part is optional, but you could add some code here to test out
// the other ChessPiece class types (Rook, Knight, etc.)
// Write some code to create the other pieces (Rook, Knight, Queen, and King)
// and call the move routine. Test to make sure they worked by calling the isAt() routine.
}
int main()
{
ChessPiece arr[8] ; // This will use the default constructor
ChessPiece blackBishop(Bishop, Black, 0, 2);
blackBishop.move(4, 6);
if (blackBishop.isAt(4,6))
cout << blackBishop.getId() << " " << blackBishop.getFullName() << " 4:6" << endl;
if (!blackBishop.isCaptured())
cout << "black Bishop is not captured yet"<<endl;
Color color = blackBishop.getColor();
cout << "Color of black Bishop is " << color << endl;
ChessPiece whitePawn(Pawn, White, 6,7);
whitePawn.move(5,7);
whitePawn.captureMove(4,6);
blackBishop.setCaptured();
if (blackBishop.isCaptured())
cout << "black bishop is now captured" << endl;
/*
The output of your program for the above should be something like:
BB BlackBishop 4:6
black Bishop is not captured yet
Color of black Bishop is 1
black bishop is now captured
Press any key to continue . . .
*/
// Add your own code to test the move routine for Rook, Knight, Queen, and King
// This part is optional, but it can give you a mechanism to try out the moves for
// your other chess piece types (Rook, Knight, etc.)
testOtherPieces();
return 0;
}
Tutor Answer
