[Reprint] Chinese chess software-engine Implementation (ii) the chess representation

Source: Internet
Author: User

The current more advanced idea of the chessboard is the "bit chessboard". The "bit chessboard" is very handy for chess because the chess board has 64 squares, which can be represented by a 64-bit variable in the information of a chessboard. The basic idea is to use the value of the bit is 1 or the maximum to indicate the existence of chess pieces in the corresponding position of the chessboard, the advantage is that the bit operation can be used to speed up the situation evaluation and the speed of the move generation. When used in Chinese chess, it needs to be pieced together to represent the 90 squares of the Chinese chess board.

Considering my current level of energy is indeed limited. At present, instead of focusing on high-quality algorithmic research, which should be the primary goal of implementing this procedure, lazy uses a traditional simpler "checkerboard array"-that is, a 9*10 array to store information on the board, and each element of the array stores what is on the board at its corresponding position. This method of presentation is simple and easy. The initial situation of the chessboard by this method is as follows:

BYTE cchessboard[9][10] = {  R,  0,  0,  p,  0,  0,  p,  0,  0,  R,  H,  0,  C,  0,  0,  0,  0,  C,  0,  H,  E,  0,  0,  P,  0,  0,  p,  0,  0,  E,  A,  0,  0,  0,  0,  0,  0,  0,  0,  A,  K,  0,  0,  p,  0,  0,  p,  0,  0,  K,  A,  0,  0,  0,  0,  0,  0,  0,  0,  A,  E,  0,  0,  p,  0,  0,  p,  0,  0,  E,  H,  0,  C,  0,  0,  0,  0,  C,  0,  H,  R,  0,  0,  p,  0,  0,  p,  0,  0,  R};

where "0" means no pieces, "R" means the Red car, "R" for black cars and so on (see the following code), that is, we gave the board as shown in the number, and agreed that the red square pieces are always under the board.

The following is the code for CChessDef.h. This header file defines the basic data structure related to chess, including the representation of checkers, the basic structure types of chess and so on. I also used two ways to name a piece of chess, in order to be known in some cases and in other cases can be easily and quickly expressed.

CChessDef.h//////////////////////Basic type definition//////////////////////////////////////////typedef char BYTE;  typedef struct _point{BYTE x; BYTE y;}            Point;     The structure of the points on the chessboard typedef struct _cchessmove{point Ptfrom;         Beginning point Ptto;         Target point int nscore;        The historical score of the Go method} Cchessmove;    Walk the structure//////////////////////chess square definition////////////////////////////////////////////const int HUMAN = 1;    Man const int computer = 0;    Computer const int RED = 1;    Red Square const int BLACK = 0; Black square//////////////////////chess piece definition////////////////////////////////////////////////Red square piece definition Red const BYTE K = 1    ;    Handsome const BYTE A = 2;    Shi Const BYTE E = 3;    Phase Const BYTE H = 4;    Horse Const BYTE R = 5;    Vehicle const BYTE C = 6;    Cannon Const BYTE P = 7;    Soldier//Black piece definition Black const BYTE k = 8;    will be const BYTE A = 9;    Shi Const BYTE e = 10;    Like a const BYTE h = 11; Horse Const BYTE R = 12;    Vehicle const BYTE C = 13;    Cannon Const BYTE p = 14;     Stroke//Red Square pieces define # define Red_k k#define red_s a#define red_x e#define red_m h#define red_j r#define red_p C#define red_b P//Black pieces define # define Black_k k#define black_s a#define black_x e#define black_m h#def  Ine Black_j r#define black_p c#define black_b P//Determine which party the piece is const int sideofman[15] ={0, red, red, red, red, Red, red, red, black, black, black, black, black, black, black,};//This array will be used as a "function".       similar to int sideofman (BYTE);  Chess Game Definition////////////////////////////////////////////////chessboard on the chess board distribution byte cchessboard[9][10] = {R, 0,   0, p, 0, 0, p, 0, 0, R, H, 0, C, 0, 0, 0, 0, C, 0, H, E, 0, 0, p, 0, 0, p, 0, 0, E, A, 0, 0,  0, 0, 0, 0, 0, 0, a, K, 0, 0, p, 0, 0, p, 0, 0, K, a, 0, 0, 0, 0, 0, 0, 0, 0, a, E, 0, 0, P, 0, 0, p, 0, 0, E, H, 0, C, 0, 0, 0, 0, C, 0, H, R, 0, 0,  P, 0, 0, p, 0, 0, R}; End of CChessDef.h

[reprint] Chinese chess software-engine Implementation (ii) the chess representation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.