Thread: chess program.

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    13

    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];
    
    };

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    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
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    13
    Thanks that chess page is pretty enlightening.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM