Computer Chess Club Archives


Search

Terms

Messages

Subject: followup about the move structure

Author: Mathieu Pagé

Date: 17:01:31 02/21/04


Hi,

As it had been sugested I changed my move structure to a simple integer
containing all the data related to a move and I found it a little bit slower
than my other implementation that consisted of some int and some char (10 bytes
total).

Is it normal ?
(My code follow the message. Marked with a line of '*' is where I manipulate the
data with some bit operations.)

Mathieu P.

<code language="C++">
// définitions des valeurs pour les types de coups
#define NORMAL                0
#define CAPTURE               1
#define PRISE_EN_PASSANT      2
#define GRAND_ROQUE           3
#define PETIT_ROQUE           4
#define PROMOTION_REINE       5
#define PROMOTION_CAVALIER    6
#define PROMOTION_FOU         7
#define PROMOTION_TOUR        8

// Définitions de valeurs pour les constantes des pièces
#define PION_BLANC            0
#define TOUR_BLANC            1
#define CAVALIER_BLANC        2
#define FOU_BLANC             3
#define ROI_BLANC             4
#define REINE_BLANC           5
#define PION_NOIR             6
#define TOUR_NOIR             7
#define CAVALIER_NOIR         8
#define FOU_NOIR              9
#define ROI_NOIR              10
#define REINE_NOIR            11
#define VIDE                  12

// définition des masques pour décortiquer data
#define CCOUP_MASK_FROM             0x0000003f
#define CCOUP_MASK_TO               0x00000fc0
#define CCOUP_MASK_PIECE_JOUEE      0x0000f000
#define CCOUP_MASK_PIECE_PRISE      0x000f0000
#define CCOUP_MASK_TYPE_COUP        0x00700000

class CCoup
{
   friend std::ostream& operator<<(std::ostream& out, const CCoup& coup);
   friend bool operator!=(const CCoup& gauche, const CCoup& droite);

private:
   // Toute les données sont placé dans un seul int. Voici la dispositions des
bits
   // 0 à 5 : from [0,63]
   // 6 à 11 : to [0,63]
   // 12 à 15 : Piece joué [0,12]
   // 16 à 19 : Piece prise [0,12]
   // 20 à 22 : Type de coup [0,8]

	int data;

public:
/**************************************************************/
	int GetType() const {return (data & CCOUP_MASK_TYPE_COUP) >> 20;};
	int GetPiece() const {return (data & CCOUP_MASK_PIECE_JOUEE) >> 12;};
	int GetPiecePrise() const {return (data & CCOUP_MASK_PIECE_PRISE) >> 16;};
	int GetOrigine() const {return data & CCOUP_MASK_FROM;};
	int GetDestination() const {return (data & CCOUP_MASK_TO) >> 6;};

/*****************************************************************/
	void SetType(int newCoup){data = data & ~CCOUP_MASK_TYPE_COUP | (newCoup <<
20);};
	void SetPiece(int newPiece){data = data & ~CCOUP_MASK_PIECE_JOUEE | (newPiece
<< 12);};
	void SetPiecePrise(int newPiecePrise){data = data & ~CCOUP_MASK_PIECE_PRISE |
(newPiecePrise << 16);};
	void SetOrigine(int newFrom){data = data & ~CCOUP_MASK_FROM | (newFrom &
CCOUP_MASK_FROM);};
	void SetDestination(int newTo){data = data & ~CCOUP_MASK_TO | (newTo << 6);};

	std::string GetLongAlgebraic() const;
};
</code>



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.