-
chess program.
i'm building a basic chess program. i set up a class to define each chess piece.
this class contains all the information needed to set up a chess piece and define its location on the board.
the location is stored in the class.
what would be fantastic is if anybody could tell me how to select each piece knowing only its location on the chessgrid.
thanks ;)
heres the class definition.
Code:
class piece
{
public:
//Constructors
piece(char side, char type, int y, int x);
//Purpose: to set a piece and declare its initial location and type.
//Parameters: init piece type (caps for white), init piece location
//Detectors
void piece::allowed_moves(char board[8][8]);
//Purpose: based on the location of a piece, the present state of the board and
// the piece type, this calculates the allowable moves for that piece.
//Parameters: type of piece, present location, present board state, alowed moves.
void request_move( int y, int x);
//Purpose: allow the user to select a move from a couple of those already defined.
//Perameters: x, y coordinates.
char piece_typer();
//Purpose: return the piece type info
//Returns: piece_type.
int side_return();
//Purpose: return the piece side as an integer
//Returns: -1 for black 1 for white.
//Mutators
void place(char board[8][8]);
//Purpose: place a piece on the chess board.
//Parameters: chessboard array.
void move(int y, int x, char board[8][8]);
//Purpose: given a piece location set a new defined location based on allowed moves.
//Parameters: piece location.
void kill(char board[8][8]);
//Purpose: delete the piece.
private:
void move_check (int g, int h, int a, int b, char c[8][8]);
char piece_type, piece_side;
int location;
int sider;
int allowed[8][8];
};
-
Not sure what you mean by "select each piece" but at any rate it is going to depend on how you define the board. One board representation is bitboards, another is called 0x88--you should be able to find that by googling. And more than selecting every piece, you'll need to be able to generate all legal moves from a particular position on the board. You should get some idea of how to do this by researching bitboards. Here is a link to some other chess topics to get you started:
http://www.seanet.com/~brucemo/topics/topics.htm
-
Thanks that chess page is pretty enlightening.