1 /*  DreamChess
2 **
3 **  DreamChess is the legal property of its developers, whose names are too
4 **  numerous to list here. Please refer to the AUTHORS.txt file distributed
5 **  with this source distribution.
6 **
7 **  This program is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License as published by
9 **  the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  This program is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU General Public License for more details.
16 **
17 **  You should have received a copy of the GNU General Public License
18 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef DREAMER_MOVE_H
22 #define DREAMER_MOVE_H
23 
24 #include "board.h"
25 #include "dreamer.h"
26 
27 #define NORMAL_MOVE 0
28 #define CAPTURE_MOVE 1
29 #define CAPTURE_MOVE_EN_PASSANT 2
30 #define CASTLING_MOVE_KINGSIDE 4
31 #define CASTLING_MOVE_QUEENSIDE 8
32 #define RESIGN_MOVE 16
33 #define STALEMATE_MOVE 32
34 #define PROMOTION_MOVE_KNIGHT 64
35 #define PROMOTION_MOVE_BISHOP 128
36 #define PROMOTION_MOVE_ROOK 256
37 #define PROMOTION_MOVE_QUEEN 512
38 #define NO_MOVE 4096
39 
40 #define MOVE_NO_PROMOTION_MASK 63
41 #define MOVE_PROMOTION_MASK 960
42 
43 /* New move type */
44 
45 #define MOVE_TYPE_MASK 0x3ff
46 #define MOVE_TYPE_SHIFT 0
47 #define MOVE_SOURCE_MASK 0xfc00
48 #define MOVE_SOURCE_SHIFT 10
49 #define MOVE_DEST_MASK 0x3f0000
50 #define MOVE_DEST_SHIFT 16
51 #define MOVE_CAPTURED_MASK 0x3c00000
52 #define MOVE_CAPTURED_SHIFT 22
53 #define MOVE_PIECE_MASK 0x3c000000
54 #define MOVE_PIECE_SHIFT 26
55 
56 #define MOVE_GET(M, P) (((M)&MOVE_##P##_MASK) >> MOVE_##P##_SHIFT)
57 #define MOVE_SET(M, P, V) ((M) = ((M) & ~MOVE_##P##_MASK) | ((V) << MOVE_##P##_SHIFT))
58 #define MOVE(PIECE, SOURCE, DEST, TYPE, CAPTURED)                                                                      \
59 	(((PIECE) << MOVE_PIECE_SHIFT) | ((SOURCE) << MOVE_SOURCE_SHIFT) | ((DEST) << MOVE_DEST_SHIFT) |                   \
60 	 ((TYPE) << MOVE_TYPE_SHIFT) | ((CAPTURED) << MOVE_CAPTURED_SHIFT))
61 
62 #define MOVE_IS_REGULAR(M) (((M) != NO_MOVE) && ((M) != RESIGN_MOVE) && ((M) != STALEMATE_MOVE))
63 
64 extern move_t moves[(MAX_DEPTH + 1) * 256];
65 extern int moves_start[MAX_DEPTH + 2];
66 extern int moves_cur[MAX_DEPTH + 1];
67 
68 void move_init(void);
69 
70 void move_exit(void);
71 
72 int compute_legal_moves(board_t *board, int ply);
73 
74 move_t move_next(board_t *board, int ply);
75 
76 #endif
77