Can you complete this 'class" example

Hi all! I found in my book a "class" example, not complete, that I am unable to complete since I know almost nothing about chessboard. This example seems to me much more interesting than the example I find in the tutorials of this forum. Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
enum ChessPiece { EMPTY_SQUARE, WHITE_PAWN /* and others */ };
enum PlayerColor { PC_WHITE, PC_BLACK };

class ChessBoard
{
public:

	ChessPiece getPiece (int x, int y);
	PlayerColor getMove ();
	void makeMove (int from_x, int from_y, int to_x, int to_y);

private:
	ChessPiece _board[ 8 ][ 8 ];
	PlayerColor _whose_move;
};

// Method definitions are exactly the same!
ChessPiece ChessBoard::getPiece (int x, int y)
{
	return _board[ x ][ y ];
}

PlayerColor ChessBoard::getMove ()
{
	return _whose_move;
}

void  ChessBoard::makeMove (int from_x, int from_y, int to_x, int to_y)
{
	// normally, we'd want some code that validates the move first 
	_board[ to_x ][ to_y ] = _board[ from_x ][ from_y ];
	_board[ from_x ][ from_y ] = EMPTY_SQUARE;
}
at the very least, getPiece and getMove should be const, and makeMove should take something more specific than four arbitrary integers. Either a proper chess move description, or at least two board positions (so you don't have to check that they are not negative and not exceed 8).
You also need other state to determine next move validity, such as total number of moves taken, number of moves since the last repetition, whether the king had moved previously, etc - and, in fact, the full list of moves should be kept, and the ability to roll back for analysis... making a realistic setup for a chess engine can get fairly complicated even if it's just to serve two human players.
Thank you, Cubbi, for your reply. There must be hundreds of creators of chessboard programs, but none of them looks at this forum. Maybe, to-morrow, someone will appear !
Topic archived. No new replies allowed.