diff --git a/.gitignore b/.gitignore index 18b6970..9f2cd5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ core +vgcore.* GPATH GRTAGS GTAGS diff --git a/fentests.txt b/FENTESTS.txt similarity index 100% rename from fentests.txt rename to FENTESTS.txt diff --git a/Makefile b/Makefile index 2991294..a41733d 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ BIN=fen pool piece move debug eval bits CFLAGS += -std=gnu99 -CFLAGS += -O2 +#CFLAGS += -O2 CFLAGS += -g CFLAGS += -Wall CFLAGS += -Wextra @@ -67,7 +67,7 @@ $(DEPS): $(SRC) $(INC) include $(DEPS) clean: - rm -rf $(OBJ) core $(BIN) $(DEPS) + rm -rf $(OBJ) core $(BIN) #$(OBJ): $(OBJDIR)/%.o: $(SRCDIR)/%.c # @mkdir -p $(@D) diff --git a/make.deps b/make.deps index 5fed552..947bf82 100644 --- a/make.deps +++ b/make.deps @@ -4,10 +4,10 @@ src/debug.h src/board.h src/piece.h src/list.h src/pool.h ./obj/fen.o:: src/fen.c src/debug.h src/chessdefs.h src/bits.h src/position.h \ src/board.h src/piece.h src/list.h src/pool.h src/fen.h -./obj/move.o:: src/move.c src/chessdefs.h src/bits.h src/debug.h src/piece.h \ - src/board.h src/position.h src/pool.h src/list.h src/move.h +./obj/move.o:: src/move.c src/chessdefs.h src/bits.h src/debug.h src/board.h \ + src/piece.h src/list.h src/pool.h src/move.h src/position.h ./obj/piece.o:: src/piece.c src/chessdefs.h src/bits.h src/debug.h src/piece.h \ - src/board.h src/position.h src/pool.h src/list.h + src/list.h src/pool.h src/board.h src/position.h ./obj/pool.o:: src/pool.c src/list.h src/pool.h src/debug.h ./obj/position.o:: src/position.c src/chessdefs.h src/bits.h src/debug.h \ src/position.h src/board.h src/piece.h src/list.h src/pool.h src/fen.h diff --git a/src/board.h b/src/board.h index cb9ef80..296b5de 100644 --- a/src/board.h +++ b/src/board.h @@ -17,7 +17,6 @@ #include #include "chessdefs.h" #include "piece.h" -#include "position.h" typedef struct board_s { piece_t piece; diff --git a/src/move.c b/src/move.c index 3593237..683dee1 100644 --- a/src/move.c +++ b/src/move.c @@ -14,6 +14,7 @@ #include #include #include "chessdefs.h" +#include "board.h" #include "piece.h" #include "move.h" #include "list.h" @@ -149,6 +150,7 @@ static move_t *move_add(pos_t *pos, piece_t piece, square_t from, move->to = to; move->taken = board[to].piece; move->flags = M_NORMAL; + move->pos = NULL; if (move->taken) move->flags |= M_CAPTURE; list_add(&move->list, &pos->moves); @@ -472,6 +474,16 @@ int moves_gen(pos_t *pos, bool color, bool doit) return count; } +int move_doit(pos_t *pos, move_t *move) +{ +# ifdef DEBUG_MOVE_TOTO + log_f(1, "color:%s doit:%d\n", color? "Black": "White", doit); +# endif + if (pos && move) + return 1; + return 0; +} + #ifdef BIN_move #include "fen.h" int main(int ac, char**av) diff --git a/src/move.h b/src/move.h index 0062193..c7dd420 100644 --- a/src/move.h +++ b/src/move.h @@ -60,4 +60,6 @@ int pseudo_moves_gen(pos_t *pos, piece_list_t *piece, bool doit); int pseudo_moves_pawn(pos_t *pos, piece_list_t *piece, bool doit); int moves_gen(pos_t *pos, bool color, bool doit); +int move_doit(pos_t *pos, move_t *move); + #endif /* MODE_H */ diff --git a/src/piece.c b/src/piece.c index 31682ba..8e777fb 100644 --- a/src/piece.c +++ b/src/piece.c @@ -12,10 +12,13 @@ */ #include +#include + #include "chessdefs.h" #include "piece.h" -#include "ctype.h" +#include "board.h" #include "debug.h" +#include "position.h" static pool_t *pieces_pool; diff --git a/src/piece.h b/src/piece.h index 357a8ab..4e28b2a 100644 --- a/src/piece.h +++ b/src/piece.h @@ -17,9 +17,7 @@ #include #include "chessdefs.h" -#include "board.h" #include "list.h" -#include "position.h" #include "pool.h" #define PIECE_DEFAULT_VALUE 0 diff --git a/src/position.c b/src/position.c index 58db82b..426eef2 100644 --- a/src/position.c +++ b/src/position.c @@ -168,14 +168,35 @@ pos_t *pos_get() pos_t *pos = pool_get(pos_pool); if (pos) { //printf("sizeof(board)=%lu\n", sizeof (board_t)); - pos->board = malloc(sizeof (board_t)*BOARDSIZE); + //pos->board = malloc(sizeof (board_t)*BOARDSIZE); + //printf("board mem: %p-%p\n", pos->board, pos->board+sizeof (board_t)); + //if (pos->board) + pos_clear(pos); + //else { + // free(pos); + // pos = NULL; + //} + } + return pos; +} + +/* TODO: merge with pos_get - NULL for init, non null for duplicate */ +pos_t *pos_dup(pos_t *pos) +{ + pos_t *new = pool_get(pos_pool); + if (new) { + //printf("sizeof(board)=%lu\n", sizeof (board_t)); + //new->board = malloc(sizeof (board_t)*BOARDSIZE); + //if (!new->board) { + // pool_add(pos_pool, new); + // return NULL; + //} + + *new = *pos; + INIT_LIST_HEAD(&new->pieces[WHITE]); + INIT_LIST_HEAD(&new->pieces[BLACK]); + INIT_LIST_HEAD(&new->moves); //printf("board mem: %p-%p\n", pos->board, pos->board+sizeof (board_t)); - if (pos->board) - pos_clear(pos); - else { - free(pos); - pos = NULL; - } } return pos; } diff --git a/src/position.h b/src/position.h index 2b12fa7..160f01b 100644 --- a/src/position.h +++ b/src/position.h @@ -27,7 +27,7 @@ typedef struct pos_s { u16 curmove; u16 mobility[2]; eval_t eval; - board_t *board; + board_t board[BOARDSIZE]; square_t en_passant; square_t king[2]; @@ -46,5 +46,6 @@ pos_t *pos_startpos(pos_t *pos); pos_t *pos_create(); pool_t *pos_pool_init(); pos_t *pos_get(); +pos_t *pos_dup(pos_t *pos); #endif