Files
brchess/src/piece.h
Bruno Raoult d5906b1fb9 start bitboard init (see commit details)
- bitboard.c: make attacks for knight/king
- square macros (BB, BBfile, BBrank) renamed sq_make, sq_file,
  sq_rank, moved to board.h (and become temporarily inline funcs)
- different macros/defs moved to "correct place" (bitboard/board/piece):
  board.[ch]: everything related to board/square
  bitboard.[ch]: everything related to bitboards
  piece.[ch]: everything related to pieces
2024-02-11 20:47:09 +01:00

126 lines
3.7 KiB
C

/* piece.h - piece definitions.
*
* Copyright (C) 2021-2024 Bruno Raoult ("br")
* Licensed under the GNU General Public License v3.0 or later.
* Some rights reserved. See COPYING.
*
* You should have received a copy of the GNU General Public License along with this
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
*
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
*
*/
#ifndef PIECE_H
#define PIECE_H
#include <string.h>
#include "chessdefs.h"
/* piece_t bits structure
* piece is on bits 1-3, color on bit 4:
* .... CPPP
* C: 0 for white, 1: black
* PPP: pawn (1), knight, bishop, rook, queen, king (6)
*/
typedef enum {
WHITE, BLACK,
COLOR_MAX
} color_t;
typedef enum {
ALL_PIECES = 0, /* 'all pieces' bitboard */
PAWN = 1, KNIGHT, BISHOP, ROOK, QUEEN, KING,
PIECE_TYPE_MAX = 7 /* bit 4 */
} piece_type_t;
typedef enum {
EMPTY = 0,
NO_PIECE = 0,
W_PAWN = PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
B_PAWN = PAWN | 8, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING,
PIECE_MAX
} piece_t;
/* default values for opening, midgame, endgame
*/
#define E_VAL_OPN 0 /* empty */
#define P_VAL_OPN 100
#define N_VAL_OPN 300
#define B_VAL_OPN 300
#define R_VAL_OPN 500
#define Q_VAL_OPN 900
#define K_VAL_OPN 20000
#define E_VAL_MID 0
#define P_VAL_MID 100
#define N_VAL_MID 300
#define B_VAL_MID 300
#define R_VAL_MID 500
#define Q_VAL_MID 900
#define K_VAL_MID 20000
#define E_VAL_END 0
#define P_VAL_END 100
#define N_VAL_END 300
#define B_VAL_END 300
#define R_VAL_END 500
#define Q_VAL_END 900
#define K_VAL_END 20000
/* some default values for pieces
*/
extern const struct piece_details {
char abbr; /* used for game notation */
char abbr_color; /* lowercase = black */
char *sym; /* used for game notation */
char *sym_color; /* different W & B */
char *name;
s64 opn_value; /* value opening */
s64 mid_value; /* value midgame */
s64 end_value; /* value endgame */
} piece_details[PIECE_MAX];
extern const char pieces_str[6+6+1]; /* to search from fen/user input */
#define OPPONENT(p) !(p)
#define MASK_PIECE 0x07 /* 00000111 */
#define MASK_COLOR 0x08 /* 00001000 */
#define COLOR(p) ((p) >> 3) /* bitmask */
#define PIECE(p) ((p) & MASK_PIECE)
#define MAKE_PIECE(p, c) ((p) | (c) << 3)
#define IS_WHITE(p) (!COLOR(p))
#define IS_BLACK(p) (COLOR(p))
#define SET_WHITE(p) ((p) &= ~MASK_COLOR)
#define SET_BLACK(p) ((p) |= MASK_COLOR)
#define SET_COLOR(p, c) (!(c)? SET_WHITE(p): SET_BLACK(p))
extern bool piece_ok(piece_t p);
extern char piece_to_char(piece_t p);
extern char piece_to_char_color(piece_t p);
extern char *piece_to_sym(piece_t p);
extern char *piece_to_sym_color(piece_t p);
extern char *piece_to_name(piece_t p);
extern piece_t char_to_piece(char c);
extern piece_t char_color_to_piece(char c);
/* use short name or symbol - no effect
*/
#define P_USE_UTF 1
//void piece_list_print(struct list_head *list);
//pool_t *piece_pool_init();
//void piece_pool_stats();
//piece_list_t *piece_add(pos_t *pos, piece_t piece, square_t square);
//void piece_del(struct list_head *ptr);
//int pieces_del(pos_t *pos, short color);
#endif