// © Copyright 1995, Joseph Bergin. All rights reserved.#include "Chess.h"#include "error.h"// ***************************** ChessCell ******************************ChessCell::ChessCell():	_row(0),	_col(0),	_board(NULL),	_piece(NULL){}ChessPiece* ChessCell::pieceAt() const{	return _piece;}void ChessCell::location(unsigned int &row, unsigned int &col) const{	row = _row;	col = _col;}// ***************************** ChessBoard ******************************ChessBoard::ChessBoard(unsigned int size):	_size(size),	_board(size,size){	for(unsigned int i = 0; i<size; ++i)		for(unsigned int j = 0; j<size; ++j)		{	_board(i,j)._row = i+1;			_board(i,j)._col = j+1;			_board(i,j)._board = this;		}}ChessCell& ChessBoard::cellAt(unsigned int row, unsigned int col){	return _board(row-1, col-1);}ChessPiece* ChessBoard::pieceAt(unsigned int row, unsigned int col){	return (_board(row-1,col-1).pieceAt());}// ***************************** ChessPiece ******************************ChessPiece::ChessPiece(PieceKind kind):	_kind(kind),	_location(NULL){}ChessCell* ChessPiece::location() const{	return _location;}void ChessPiece::location(unsigned int &row, unsigned int &col) const{	if(!_location)	{	row = 0;		col = 0;		return;	}	_location->location(row,col);}Boolean ChessPiece:: moveTo(ChessCell & c){	if(_location != NULL) _location->_piece = NULL;	if(c._piece != NULL){ WARN("Piece already here");return false; }	c._piece = this;	_location = &c;	return true;}Boolean ChessPiece::legalMove(ChessCell &) const{	return false;}// ***************************** Queen  **********************************Queen::Queen():ChessPiece(QueenP){}Boolean Queen::legalMove(ChessCell & cell) const{	unsigned int row;	unsigned int col;	cell.location(row,col);	unsigned int r;	unsigned int c;	location(r,c);	if(r == row || c == col) return true;	if(r + c == row + col) return true;	if(r - c == row - col) return true;	return false;}
