refactor position: now contains board (not board *)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
core
|
||||
vgcore.*
|
||||
GPATH
|
||||
GRTAGS
|
||||
GTAGS
|
||||
|
4
Makefile
4
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)
|
||||
|
@@ -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
|
||||
|
@@ -17,7 +17,6 @@
|
||||
#include <stdint.h>
|
||||
#include "chessdefs.h"
|
||||
#include "piece.h"
|
||||
#include "position.h"
|
||||
|
||||
typedef struct board_s {
|
||||
piece_t piece;
|
||||
|
12
src/move.c
12
src/move.c
@@ -14,6 +14,7 @@
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
#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)
|
||||
|
@@ -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 */
|
||||
|
@@ -12,10 +12,13 @@
|
||||
*/
|
||||
|
||||
#include <malloc.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
#include "piece.h"
|
||||
#include "ctype.h"
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
#include "position.h"
|
||||
|
||||
static pool_t *pieces_pool;
|
||||
|
||||
|
@@ -17,9 +17,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
#include "board.h"
|
||||
#include "list.h"
|
||||
#include "position.h"
|
||||
#include "pool.h"
|
||||
|
||||
#define PIECE_DEFAULT_VALUE 0
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user