refactor position: now contains board (not board *)

This commit is contained in:
2021-11-12 20:22:20 +01:00
parent bd7d9f8551
commit 451afea6b5
11 changed files with 54 additions and 17 deletions

View File

@@ -17,7 +17,6 @@
#include <stdint.h>
#include "chessdefs.h"
#include "piece.h"
#include "position.h"
typedef struct board_s {
piece_t piece;

View File

@@ -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)

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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