2 Commits

Author SHA1 Message Date
1154f141c9 start bitboard integration 2023-06-22 16:08:57 +02:00
cb94ca52b9 rename to brchess 2023-06-22 16:07:16 +02:00
16 changed files with 215 additions and 99 deletions

2
.gitignore vendored
View File

@@ -13,6 +13,8 @@ debug
brchess brchess
*.o *.o
*.s *.s
*.old
*.save
/test/ /test/
/obj/ /obj/
/lib/ /lib/

115
Makefile
View File

@@ -1,44 +1,56 @@
# Makefile - GNU make only. # Makefile - GNU make only.
# #
# Copyright (C) 2021 Bruno Raoult ("br") # Copyright (C) 2021-2023 Bruno Raoult ("br")
# Licensed under the GNU General Public License v3.0 or later. # Licensed under the GNU General Public License v3.0 or later.
# Some rights reserved. See COPYING. # 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.htmlL>. # 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> # SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
# #
BINDIR := ./bin SHELL := /bin/bash
SRCDIR := ./src CC := gcc
OBJDIR := ./obj BEAR := bear
DEPS := make.deps CCLSFILE := compile_commands.json
DEPFILE := make.deps
SRC=$(wildcard $(SRCDIR)/*.c) BINDIR := ./bin
INC=$(wildcard $(SRCDIR)/*.h) SRCDIR := ./src
SRC_S=$(notdir $(SRC)) OBJDIR := ./obj
INCDIR := ./include
LIBDIR := ./lib
LIBSRCDIR := ./libsrc
LDFLAGS := -L$(LIBDIR)
LIB := br_$(shell uname -m)
SLIB := $(LIBDIR)/lib$(LIB).a
DLIB := $(LIBDIR)/lib$(LIB).so
LIBSRC := $(wildcard $(LIBSRCDIR)/*.c)
LIBOBJ := $(patsubst %.c,%.o,$(LIBSRC))
CC=gcc SRC := $(wildcard $(SRCDIR)/*.c)
INC := $(wildcard $(SRCDIR)/*.h)
SRC_S := $(notdir $(SRC))
.SECONDEXPANSION: .SECONDEXPANSION:
OBJ=$(addprefix $(OBJDIR)/,$(SRC_S:.c=.o)) OBJ=$(addprefix $(OBJDIR)/,$(SRC_S:.c=.o))
BIN=fen pool piece move debug eval bits bodichess BIN=fen piece move eval brchess
LIBS = -lreadline -lncurses LIBS = -l$(LIB) -lreadline -lncurses
CFLAGS += -std=gnu99
CFLAGS += -std=gnu11
#CFLAGS += -O2 #CFLAGS += -O2
CFLAGS += -g CFLAGS += -g
CFLAGS += -Wall CFLAGS += -Wall
CFLAGS += -Wextra CFLAGS += -Wextra
CFLAGS += -march=native CFLAGS += -march=native
#CFLAGS += -pedantic
#CFLAGS += -Wno-pointer-arith
#CFLAGS += -Werror
CFLAGS += -Wmissing-declarations CFLAGS += -Wmissing-declarations
##################################### DEBUG flags ##################################### DEBUG flags
CFLAGS += -DDEBUG # global CFLAGS += -DDEBUG # global
CFLAGS += -DDEBUG_DEBUG # enable log() functions
CFLAGS += -DDEBUG_POOL # memory pools management CFLAGS += -DDEBUG_POOL # memory pools management
CFLAGS += -DDEBUG_FEN # FEN decoding CFLAGS += -DDEBUG_FEN # FEN decoding
CFLAGS += -DDEBUG_MOVE # move generation CFLAGS += -DDEBUG_MOVE # move generation
@@ -51,33 +63,50 @@ CFLAGS += -DDEBUG_PIECE # piece list management
#CFLAGS += -DDEBUG_EVAL3 # eval 3 #CFLAGS += -DDEBUG_EVAL3 # eval 3
#CFLAGS += -DDEBUG_MEM # malloc #CFLAGS += -DDEBUG_MEM # malloc
.PHONY: all cflags clean ##################################### General targets
.PHONY: compile cflags all clean
compile: cflags $(OBJ) $(BIN) compile: lib $(OBJ) $(BIN)
cflags: cflags:
@echo CFLAGS used: $(CFLAGS) @echo CFLAGS used: $(CFLAGS)
all: clean compile all: clean compile
$(DEPS): $(SRC) $(INC)
@echo generating dependancies.
@$(CC) -MM $(SRC) > $@
@sed -i "s|\(.*\.o\):|${OBJDIR}/\0:|" $@
include $(DEPS)
clean: clean:
rm -rf $(OBJ) core $(BIN) rm -rf $(OBJ) core $(BIN)
##################################### Generate and include dependencies
.PHONY: deps cleandeps $(DEPFILE)
cleandeps:
rm -f $(DEPFILE)
deps: $(DEPFILE)
$(DEPFILE): $(SRC) $(INC)
@echo generating dependancies.
$(CC) -MM -MF $(DEPFILE) -I $(INCDIR) $(SRC)
#cp $@ $@.sav
sed -i "s|\(.*\.o\):|${OBJDIR}/\0:|" $@
include $(DEPFILE)
##################################### objects
.PHONY: obj
obj: $(OBJ)
#$(OBJ): $(OBJDIR)/%.o: $(SRCDIR)/%.c #$(OBJ): $(OBJDIR)/%.o: $(SRCDIR)/%.c
# @mkdir -p $(@D) # @mkdir -p $(@D)
# $(CC) -c $(CFLAGS) -o $@ $< # $(CC) -c $(CFLAGS) -o $@ $<
$(OBJDIR)/%.o: $(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(@D) echo SRC_S=$(SRC_S)
@echo compiling $@. echo O=$(OBJ)
@$(CC) -c $(CFLAGS) -o $@ $< mkdir -p $(@D)
@echo compiling A=$@ I=$<
$(CC) -c $(CFLAGS) -I $(INCDIR) -o $@ $<
##################################### binaries
#fen: CFLAGS+=-DBIN_$$@ #fen: CFLAGS+=-DBIN_$$@
#$(BIN): $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c #$(BIN): $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c
# @echo compiling $@. # @echo compiling $@.
@@ -87,7 +116,7 @@ $(OBJDIR)/%.o:
$(BIN): $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c $(BIN): $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c
@echo compiling $@. @echo compiling $@.
@echo NEED_TO_CHANGE_THIS=$^ @echo NEED_TO_CHANGE_THIS=$^
@$(CC) -DBIN_$@ $(CFLAGS) $^ $(LIBS) -o $@ $(CC) -DBIN_$@ $(CFLAGS) -I $(INCDIR) $^ $(LDFLAGS) $(LIBS) -o $@
#pool: CFLAGS+=-DPOOLBIN #pool: CFLAGS+=-DPOOLBIN
#pool: $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c #pool: $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c
@@ -109,3 +138,27 @@ $(BIN): $$(subst $(OBJDIR)/$$@.o,,$(OBJ)) $(SRCDIR)/$$@.c
#bits2: src/bits.c #bits2: src/bits.c
# $(CC) $(CFLAGS) -S $^ -o $@.s # $(CC) $(CFLAGS) -S $^ -o $@.s
# $(CC) $(CFLAGS) $^ -o $@ # $(CC) $(CFLAGS) $^ -o $@
##################################### br library
.PHONY: cleanlib lib
cleanlib: clean
@$(RM) -f $(SLIB) $(DLIB) $(LIBOBJ)
lib: $(DLIB) $(SLIB)
$(SLIB): $(LIBOBJ)
@echo building $@ static library.
@mkdir -p $(LIBDIR)
@$(AR) $(ARFLAGS) -o $@ $^
$(DLIB): CFLAGS += -fPIC
$(DLIB): LDFLAGS += -shared
$(DLIB): $(LIBOBJ)
@echo building $@ shared library.
@mkdir -p $(LIBDIR)
@$(CC) $(LDFLAGS) $^ -o $@
.c.o:
@echo compiling $<.
@$(CC) -c $(CFLAGS) $(LDFLAGS) -I $(INCDIR) -o $@ $<

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -79,7 +79,7 @@ enum x88_square {
/* necessary not to become mad to set bitboards /* necessary not to become mad to set bitboards
*/ */
enum bb_square{ enum bb_square {
A1=(u64)1, B1=(u64)A1<<1, C1=(u64)B1<<1, D1=(u64)C1<<1, A1=(u64)1, B1=(u64)A1<<1, C1=(u64)B1<<1, D1=(u64)C1<<1,
E1=(u64)D1<<1, F1=(u64)E1<<1, G1=(u64)F1<<1, H1=(u64)G1<<1, E1=(u64)D1<<1, F1=(u64)E1<<1, G1=(u64)F1<<1, H1=(u64)G1<<1,

View File

@@ -1,11 +1,11 @@
/* bodichess.c - main loop. /* brchess.c - main loop.
* *
* Copyright (C) 2021 Bruno Raoult ("br") * Copyright (C) 2021 Bruno Raoult ("br")
* Licensed under the GNU General Public License v3.0 or later. * Licensed under the GNU General Public License v3.0 or later.
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -27,11 +27,11 @@
#include "debug.h" #include "debug.h"
#include "fen.h" #include "fen.h"
#include "eval.h" #include "eval.h"
#include "bodichess.h" #include "brchess.h"
typedef struct { typedef struct {
char *name; /* User printable name */ char *name; /* User printable name */
int (*func)(pos_t *, char *); /* function doing the job */ int (*func)(pos_t *, char *); /* function doing the job */
char *doc; /* function doc */ char *doc; /* function doc */
} COMMAND; } COMMAND;
@@ -78,7 +78,7 @@ COMMAND commands[] = {
static int done=0; static int done=0;
int bodichess(pos_t *pos) int brchess(pos_t *pos)
{ {
char *buffer, *s; char *buffer, *s;
@@ -372,10 +372,10 @@ int do_help(__attribute__((unused)) pos_t *pos,
return 0; return 0;
} }
#ifdef BIN_bodichess #ifdef BIN_brchess
/** main() /** main()
* options: * options:
int bodichess(pos_t *pos) int brchess(pos_t *pos)
* *
*/ */
static int usage(char *prg) static int usage(char *prg)
@@ -413,6 +413,6 @@ int main(int ac, char **av)
if (optind < ac) if (optind < ac)
return usage(*av); return usage(*av);
return bodichess(pos); return brchess(pos);
} }
#endif /* BIN_bodichess */ #endif /* BIN_brchess */

View File

@@ -5,17 +5,17 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
*/ */
#ifndef BODICHESS_H #ifndef BRCHESS_H
#define BODICHESS_H #define BRCHESS_H
#include "position.h" #include "position.h"
int bodichess(pos_t *pos); int brchess(pos_t *pos);
#endif /* BODICHESS_H */ #endif /* BRCHESS_H */

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -14,7 +14,7 @@
#ifndef CHESSDEFS_H #ifndef CHESSDEFS_H
#define CHESSDEFS_H #define CHESSDEFS_H
#include "bits.h" #include <bits.h>
/* piece_t bits structure /* piece_t bits structure
*/ */
@@ -31,6 +31,19 @@ enum {
E_KING, E_KING,
}; };
/* pos_t bitboards tables
*/
enum {
BB_ALL = 0, /* OR of all bitboards */
BB_UNUSED, /* future use ? */
BB_PAWN = E_PAWN,
BB_KNIGHT,
BB_BISHOP,
BB_ROOK,
BB_QUEEN,
BB_KING,
BB_END
};
/* piece bitmask in piece_t /* piece bitmask in piece_t
*/ */
@@ -44,6 +57,8 @@ enum {
KING = 1 << (E_KING - 1), /* 0x40 01000000 */ KING = 1 << (E_KING - 1), /* 0x40 01000000 */
}; };
#define PIECETOBB(p) (ffs64(PIECE(p))) /* from piece_t to bb piece array */
#define WHITE 0 /* 0x00 00000000 */ #define WHITE 0 /* 0x00 00000000 */
#define BLACK 1 /* 0x01 00000001 */ #define BLACK 1 /* 0x01 00000001 */
#define OPPONENT(p) !(p) #define OPPONENT(p) !(p)

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -13,26 +13,33 @@
#include <stdio.h> #include <stdio.h>
#include <list.h>
#include <debug.h>
#include "eval.h" #include "eval.h"
#include "list.h"
#include "debug.h"
eval_t eval(pos_t *pos) eval_t eval(pos_t *pos)
{ {
eval_t material[2] = {0}; eval_t material[2] = {0};
eval_t control[2] = {0}; eval_t control[2] = {0};
eval_t res = 0; eval_t res = 0;
struct list_head *p_cur, *p_tmp, *list;
piece_list_t *piece;
//printf("val(%d-%c) = %lu\n", PAWN, P_LETTER(PAWN), P_VALUE(PAWN));
//printf("val(%d-%c) = %lu\n", KNIGHT, P_LETTER(KNIGHT), P_VALUE(KNIGHT));
//bitboard_print2(pos->bb[0][BB_PAWN], pos->bb[1][BB_PAWN]);
//bitboard_print2(pos->bb[0][BB_QUEEN], pos->bb[1][BB_QUEEN]);
/* 1) pieces value /* 1) pieces value
*/ */
for (int color=0; color <2; ++color) { for (uint color = 0; color < 2; ++color) {
list = &pos->pieces[color]; for (uint piece = PAWN; piece <= KING; piece <<= 1) {
list_for_each_safe(p_cur, p_tmp, list) { uint bb = PIECETOBB(piece);
piece = list_entry(p_cur, piece_list_t, list); # ifdef DEBUG_EVAL
if (PIECE(piece->piece) != KING) log_f(2, "color=%u piece=%u bb=%u=%c count=%ul val=%ld\n",
material[color] += piece->value; color, piece, bb, P_LETTER(piece), popcount64(pos->bb[color][bb]),
P_VALUE(piece));
# endif
/* attention here */
material[color] += popcount64(pos->bb[color][bb]) * P_VALUE(piece);
} }
} }
@@ -54,11 +61,11 @@ eval_t eval(pos_t *pos)
res, (float)res/10); res, (float)res/10);
# endif # endif
/* 3) mobility: 5 mobility diff = 1 pawn /* 3) mobility: 10 mobility diff = 1 pawn
*/ */
res = pos->mobility[WHITE] - pos->mobility[BLACK]; res = pos->mobility[WHITE] - pos->mobility[BLACK];
# ifdef DEBUG_EVAL # ifdef DEBUG_EVAL
log_f(2, "mobility: W:%ld B:%ld eval=%ld (%.3f pawns)\n", log_f(2, "mobility: W:%ud B:%ud eval=%ld (%.3f pawns)\n",
pos->mobility[WHITE], pos->mobility[BLACK], pos->mobility[WHITE], pos->mobility[BLACK],
res, (float)res/5); res, (float)res/5);
# endif # endif
@@ -83,7 +90,7 @@ int main(int ac, char**av)
pos_t *pos; pos_t *pos;
eval_t res; eval_t res;
debug_init(2); debug_level_set(9);
piece_pool_init(); piece_pool_init();
moves_pool_init(); moves_pool_init();
pos_pool_init(); pos_pool_init();
@@ -95,10 +102,15 @@ int main(int ac, char**av)
fen2pos(pos, av[1]); fen2pos(pos, av[1]);
} }
moves_gen(pos, OPPONENT(pos->turn), false);
moves_gen(pos, pos->turn, true);
pos_print(pos); pos_print(pos);
pos_pieces_print(pos); pos_pieces_print(pos);
moves_gen(pos, OPPONENT(pos->turn), false);
moves_print(pos, M_PR_SEPARATE);
//pos_print(pos);
//pos_pieces_print(pos);
moves_gen(pos, pos->turn, false);
moves_print(pos, M_PR_SEPARATE);
res = eval(pos); res = eval(pos);
printf("eval=%ld (%.3f pawns)\n", res, (float)res/100); printf("eval=%ld (%.3f pawns)\n", res, (float)res/100);
} }

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -17,7 +17,8 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "debug.h" #include <debug.h>
#include "chessdefs.h" #include "chessdefs.h"
#include "position.h" #include "position.h"
#include "board.h" #include "board.h"
@@ -48,7 +49,7 @@
pos_t *fen2pos(pos_t *pos, char *fen) pos_t *fen2pos(pos_t *pos, char *fen)
{ {
char *p = fen; char *p = fen;
short rank, file, skip, color; short rank, file, skip, color, bbpiece;
piece_t piece; piece_t piece;
board_t *board = pos->board; board_t *board = pos->board;
# define SKIP_BLANK(p) for(;*(p) == ' '; (p)++) # define SKIP_BLANK(p) for(;*(p) == ' '; (p)++)
@@ -61,29 +62,36 @@ pos_t *fen2pos(pos_t *pos, char *fen)
char cp = toupper(*p); char cp = toupper(*p);
switch (cp) { switch (cp) {
case CHAR_PAWN: case CHAR_PAWN:
bbpiece = BB_PAWN;
piece = PAWN; piece = PAWN;
goto set_square; goto set_square;
case CHAR_KNIGHT: case CHAR_KNIGHT:
bbpiece = BB_KNIGHT;
piece = KNIGHT; piece = KNIGHT;
goto set_square; goto set_square;
case CHAR_BISHOP: case CHAR_BISHOP:
bbpiece = BB_BISHOP;
piece = BISHOP; piece = BISHOP;
goto set_square; goto set_square;
case CHAR_ROOK: case CHAR_ROOK:
bbpiece = BB_ROOK;
piece = ROOK; piece = ROOK;
goto set_square; goto set_square;
case CHAR_QUEEN: case CHAR_QUEEN:
bbpiece = BB_QUEEN;
piece = QUEEN; piece = QUEEN;
goto set_square; goto set_square;
case CHAR_KING: case CHAR_KING:
bbpiece = BB_KING;
piece = KING; piece = KING;
pos->king[color]=SQ88(file, rank); //pos->bb[color][BB_KING] = BB(file, rank);
//goto set_square; //goto set_square;
set_square: set_square:
# ifdef DEBUG_FEN # ifdef DEBUG_FEN
log_i(5, "f=%d r=%d *p=%c piece=%c color=%d\n", log_i(5, "f=%d r=%d *p=%c piece=%c color=%d\n",
file, rank, *p, cp, color); file, rank, *p, cp, color);
# endif # endif
pos->bb[color][bbpiece] |= BB(file, rank);
pos->occupied[color] |= BB(file, rank); pos->occupied[color] |= BB(file, rank);
SET_COLOR(piece, color); SET_COLOR(piece, color);
board[SQ88(file, rank)].piece = piece; board[SQ88(file, rank)].piece = piece;
@@ -158,8 +166,11 @@ pos_t *fen2pos(pos_t *pos, char *fen)
* 6) current move number * 6) current move number
*/ */
SKIP_BLANK(p); SKIP_BLANK(p);
log_i(5, "pos=%d\n", (int)(p-fen)); //log_i(5, "pos=%d\n", (int)(p-fen));
sscanf(p, "%hd %hd", &pos->clock_50, &pos->curmove); sscanf(p, "%hd %hd", &pos->clock_50, &pos->curmove);
# ifdef DEBUG_FEN
log_i(5, "50 rule=%d current move=%d\n", pos->clock_50, pos->curmove);
# endif
return pos; return pos;
} }

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -14,12 +14,13 @@
#include <malloc.h> #include <malloc.h>
#include <ctype.h> #include <ctype.h>
#include <list.h>
#include <debug.h>
#include "chessdefs.h" #include "chessdefs.h"
#include "board.h" #include "board.h"
#include "piece.h" #include "piece.h"
#include "move.h" #include "move.h"
#include "list.h"
#include "debug.h"
static pool_t *moves_pool; static pool_t *moves_pool;
@@ -50,7 +51,7 @@ static struct can_castle {
pool_t *moves_pool_init() pool_t *moves_pool_init()
{ {
if (!moves_pool) if (!moves_pool)
moves_pool = pool_init("moves", 128, sizeof(move_t)); moves_pool = pool_create("moves", 128, sizeof(move_t));
return moves_pool; return moves_pool;
} }
@@ -530,8 +531,8 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *ppiece, bool doit)
//bitboard_print(pos->occupied[color]); //bitboard_print(pos->occupied[color]);
//bitboard_print(pos->occupied[OPPONENT(color)]); //bitboard_print(pos->occupied[OPPONENT(color)]);
# ifdef DEBUG_MOVE # ifdef DEBUG_MOVE
log_i(2, "BB: skipping %#llx [%c%c] (same color piece)\n", log_i(2, "BB: skipping %#lx [%c%c] (same color piece)\n",
new, FILE2C(F88(new)), RANK2C(R88(new))); bb_new, FILE2C(F88(new)), RANK2C(R88(new)));
# endif # endif
break; break;
} }
@@ -565,7 +566,8 @@ int moves_gen(pos_t *pos, bool color, bool doit)
# endif # endif
piece_list = &pos->pieces[color]; piece_list = &pos->pieces[color];
pos->mobility[color]=0; pos->mobility[color] = 0;
pos->controlled[color] = 0;
if (doit) if (doit)
pseudo_moves_castle(pos); pseudo_moves_castle(pos);
list_for_each_safe(p_cur, tmp, piece_list) { list_for_each_safe(p_cur, tmp, piece_list) {

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -14,10 +14,13 @@
#include <malloc.h> #include <malloc.h>
#include <ctype.h> #include <ctype.h>
#include <debug.h>
#include <pool.h>
#include <list.h>
#include "chessdefs.h" #include "chessdefs.h"
#include "piece.h" #include "piece.h"
#include "board.h" #include "board.h"
#include "debug.h"
#include "position.h" #include "position.h"
static pool_t *pieces_pool; static pool_t *pieces_pool;
@@ -50,7 +53,7 @@ void piece_list_print(struct list_head *list)
pool_t *piece_pool_init() pool_t *piece_pool_init()
{ {
if (!pieces_pool) if (!pieces_pool)
pieces_pool = pool_init("pieces", 128, sizeof(piece_list_t)); pieces_pool = pool_create("pieces", 128, sizeof(piece_list_t));
return pieces_pool; return pieces_pool;
} }
@@ -115,30 +118,37 @@ int pieces_del(pos_t *pos, short color)
int main(int ac, char**av) int main(int ac, char**av)
{ {
pos_t *pos; pos_t *pos;
printf("zobi\n");fflush(stdout);
debug_init(5); debug_level_set(6);
log_f(5, "kfsjdhg\n");
pos_pool_init(); pos_pool_init();
pos = pos_get(); pos = pos_get();
piece_pool_init(); piece_pool_init();
if (ac == 1) { if (ac == 1) {
printf("zoba\n");fflush(stdout);
pos_startpos(pos); pos_startpos(pos);
} else { } else {
fen2pos(pos, av[1]); fen2pos(pos, av[1]);
} }
pos_print(pos); pos_print(pos);
pos_pieces_print(pos); pos_pieces_print(pos);
printf("0x1c:\n");
printf("0x1c = 11100 = C1-E1:\n");
bitboard_print(0x1c); bitboard_print(0x1c);
printf("0x70:\n");
printf("0x70 = 111 = A1-C1\n");
bitboard_print(0x70); bitboard_print(0x70);
printf("0x0e:\n");
printf("0x0e = 1110 = B1-D1\n");
bitboard_print(0x0e); bitboard_print(0x0e);
printf("0x60:\n");
printf("0x60 = 1100000 = F1-G1\n");
bitboard_print(0x60); bitboard_print(0x60);
printf("A1:\n"); printf("A1:\n");
bitboard_print(A1); bitboard_print(A1);
printf("1:\n"); printf("1:\n");
bitboard_print(1L); bitboard_print(1L);
printf("H1:\n"); printf("H1:\n");

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -56,6 +56,7 @@ extern struct piece_details {
piece_details[E_PIECE(p)].abbrev_b) piece_details[E_PIECE(p)].abbrev_b)
#define P_CSYM(p) (IS_WHITE(p)? piece_details[E_PIECE(p)].symbol_w: \ #define P_CSYM(p) (IS_WHITE(p)? piece_details[E_PIECE(p)].symbol_w: \
piece_details[E_PIECE(p)].symbol_b) piece_details[E_PIECE(p)].symbol_b)
#define P_VALUE(p) (piece_details[E_PIECE(p)].value)
/* use short name or symbol - no effect /* use short name or symbol - no effect
*/ */
#define P_USE_UTF 1 #define P_USE_UTF 1

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -147,6 +147,9 @@ pos_t *pos_clear(pos_t *pos)
pos->king[BLACK] = 0; pos->king[BLACK] = 0;
pos->occupied[WHITE] = 0; pos->occupied[WHITE] = 0;
pos->occupied[BLACK] = 0; pos->occupied[BLACK] = 0;
for (int color=0; color<2; ++color)
for (int piece = BB_ALL; piece < BB_END; ++piece)
pos->bb[color][piece] = 0;
pos->controlled[WHITE] = 0; pos->controlled[WHITE] = 0;
pos->controlled[BLACK] = 0; pos->controlled[BLACK] = 0;
pos->mobility[WHITE] = 0; pos->mobility[WHITE] = 0;
@@ -172,8 +175,11 @@ pos_t *pos_get()
if (pos) { if (pos) {
INIT_LIST_HEAD(&pos->pieces[WHITE]); INIT_LIST_HEAD(&pos->pieces[WHITE]);
INIT_LIST_HEAD(&pos->pieces[BLACK]); INIT_LIST_HEAD(&pos->pieces[BLACK]);
INIT_LIST_HEAD(&pos->moves); INIT_LIST_HEAD(&pos->moves);
pos_clear(pos); pos_clear(pos);
} else {
fprintf(stderr, "zobaaa\n");
} }
return pos; return pos;
} }
@@ -211,7 +217,7 @@ pos_t *pos_dup(pos_t *pos)
pool_t *pos_pool_init() pool_t *pos_pool_init()
{ {
if (!pos_pool) if (!pos_pool)
pos_pool = pool_init("positions", 128, sizeof(pos_t)); pos_pool = pool_create("positions", 128, sizeof(pos_t));
return pos_pool; return pos_pool;
} }

View File

@@ -5,7 +5,7 @@
* Some rights reserved. See COPYING. * Some rights reserved. See COPYING.
* *
* You should have received a copy of the GNU General Public License along with this * 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.htmlL>. * 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> * SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
* *
@@ -15,10 +15,12 @@
#define POSITION_H #define POSITION_H
#include <stdint.h> #include <stdint.h>
#include "chessdefs.h"
#include "board.h" #include "board.h"
#include "pool.h" #include <pool.h>
#include "list.h" #include <list.h>
#include <bits.h>
#include "chessdefs.h"
typedef struct pos_s { typedef struct pos_s {
piece_t turn; /* we use only color bit */ piece_t turn; /* we use only color bit */
@@ -30,8 +32,10 @@ typedef struct pos_s {
board_t board[BOARDSIZE]; board_t board[BOARDSIZE];
square_t en_passant; square_t en_passant;
square_t king[2]; square_t king[2]; /* obsolete by bb array */
bitboard_t occupied[2];
bitboard_t bb[2][BB_END]; /* use: pieces[BLACK][BB_PAWN] */
bitboard_t occupied[2]; /* OR of bb[COLOR][x] */
bitboard_t controlled[2]; bitboard_t controlled[2];
struct list_head pieces[2]; struct list_head pieces[2];
struct list_head moves; struct list_head moves;