move list taken off from pos_t
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
# Makefile - brchess Makefile, **GNU make only**
|
# Makefile - brchess Makefile, **GNU make only**
|
||||||
#
|
#
|
||||||
# Copyright (C) 2021-2023 Bruno Raoult ("br")
|
# Copyright (C) 2021-2024 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.
|
||||||
#
|
#
|
||||||
|
2
brlib
2
brlib
Submodule brlib updated: e55ac95301...8ff163dcf5
@@ -103,7 +103,8 @@ bool pseudo_is_legal(const pos_t *pos, const move_t move)
|
|||||||
/**
|
/**
|
||||||
* pos_next_legal() - get next legal move in position.
|
* pos_next_legal() - get next legal move in position.
|
||||||
* @pos: position
|
* @pos: position
|
||||||
* @start: &int, starting position in move list
|
* @movelist: &pseudo-legal movelist
|
||||||
|
* @start: &int, starting position in @movelist
|
||||||
*
|
*
|
||||||
* Get next valid move in @pos move list, from move @start, or MOVE_NONE.
|
* Get next valid move in @pos move list, from move @start, or MOVE_NONE.
|
||||||
* @start is set to next non-checked move in pseudo-legal list.
|
* @start is set to next non-checked move in pseudo-legal list.
|
||||||
@@ -111,10 +112,10 @@ bool pseudo_is_legal(const pos_t *pos, const move_t move)
|
|||||||
*
|
*
|
||||||
* @return: move, or MOVE_NONE if no move.
|
* @return: move, or MOVE_NONE if no move.
|
||||||
*/
|
*/
|
||||||
move_t pos_next_legal(const pos_t *pos, int *start)
|
move_t pos_next_legal(const pos_t *pos, movelist_t *movelist, int *start)
|
||||||
{
|
{
|
||||||
const int nmoves = pos->moves.nmoves;
|
const int nmoves = movelist->nmoves;
|
||||||
const move_t *moves = pos->moves.move;
|
const move_t *moves = movelist->move;
|
||||||
move_t move;
|
move_t move;
|
||||||
|
|
||||||
while (*start < nmoves) {
|
while (*start < nmoves) {
|
||||||
@@ -127,20 +128,20 @@ move_t pos_next_legal(const pos_t *pos, int *start)
|
|||||||
/**
|
/**
|
||||||
* pos_all_legal() - get the list of legal moves from pseudo-legal.
|
* pos_all_legal() - get the list of legal moves from pseudo-legal.
|
||||||
* @pos: position
|
* @pos: position
|
||||||
* @dest: destination &movelist_t
|
* @movelist: &pseudo-legal movelist_t
|
||||||
|
* @dest: &destination movelist_t
|
||||||
*
|
*
|
||||||
* The pseudo-legal moves must be already calculated before calling this function.
|
* The pseudo-legal moves must be already calculated before calling this function.
|
||||||
* No check is done on @dest limits.
|
* No check is done on @dest limits.
|
||||||
*
|
*
|
||||||
* @Return: @dest
|
* @Return: @dest
|
||||||
*/
|
*/
|
||||||
movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest)
|
movelist_t *pos_all_legal(const pos_t *pos, movelist_t *movelist, movelist_t *dest)
|
||||||
{
|
{
|
||||||
int tmp = dest->nmoves = 0;
|
int tmp = dest->nmoves = 0;
|
||||||
move_t move;
|
move_t move;
|
||||||
//int tmp = 0;
|
|
||||||
|
|
||||||
while ((move = pos_next_legal(pos, &tmp)) != MOVE_NONE)
|
while ((move = pos_next_legal(pos, movelist, &tmp)) != MOVE_NONE)
|
||||||
dest->move[dest->nmoves++] = move;
|
dest->move[dest->nmoves++] = move;
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
@@ -148,9 +149,10 @@ movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest)
|
|||||||
/**
|
/**
|
||||||
* pos_gen_pseudomoves() - generate position pseudo-legal moves
|
* pos_gen_pseudomoves() - generate position pseudo-legal moves
|
||||||
* @pos: position
|
* @pos: position
|
||||||
|
* @movelist: &movelist_t array to store pseudo-moves
|
||||||
*
|
*
|
||||||
* Generate all @pos pseudo moves for player-to-move.
|
* Generate all @pos pseudo moves for player-to-move.
|
||||||
* The @pos->moves table is filled with the moves.
|
* @movelist is filled with the moves.
|
||||||
*
|
*
|
||||||
* Only a few validity checks are done here (i.e. moves are not generated):
|
* Only a few validity checks are done here (i.e. moves are not generated):
|
||||||
* - castling, if king is in check
|
* - castling, if king is in check
|
||||||
@@ -167,7 +169,7 @@ movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest)
|
|||||||
*
|
*
|
||||||
* @Return: The total number of moves.
|
* @Return: The total number of moves.
|
||||||
*/
|
*/
|
||||||
int pos_gen_pseudomoves(pos_t *pos)
|
int pos_gen_pseudomoves(pos_t *pos, movelist_t *movelist)
|
||||||
{
|
{
|
||||||
color_t us = pos->turn;
|
color_t us = pos->turn;
|
||||||
color_t them = OPPONENT(us);
|
color_t them = OPPONENT(us);
|
||||||
@@ -181,43 +183,43 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
bitboard_t movebits, from_pawns;
|
bitboard_t movebits, from_pawns;
|
||||||
bitboard_t tmp1, tmp2;
|
bitboard_t tmp1, tmp2;
|
||||||
|
|
||||||
move_t *moves = pos->moves.move;
|
move_t *moves = movelist->move;
|
||||||
int nmoves = pos->moves.nmoves;
|
int *nmoves = &movelist->nmoves;
|
||||||
int from, to;
|
int from, to;
|
||||||
|
|
||||||
bug_on(nmoves != 0);
|
*nmoves = 0;
|
||||||
|
|
||||||
/* king - MUST BE FIRST (we stop if doubler check) */
|
/* king - MUST BE FIRST (we stop if doubler check) */
|
||||||
from = pos->king[us];
|
from = pos->king[us];
|
||||||
movebits = bb_king_moves(not_my_pieces, from);
|
movebits = bb_king_moves(not_my_pieces, from);
|
||||||
bit_for_each64(to, tmp1, movebits & empty) {
|
bit_for_each64(to, tmp1, movebits & empty) {
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
}
|
}
|
||||||
bit_for_each64(to, tmp1, movebits & enemy_pieces) {
|
bit_for_each64(to, tmp1, movebits & enemy_pieces) {
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (popcount64(pos->checkers) > 1) /* double check, we stop here */
|
if (popcount64(pos->checkers) > 1) /* double check, we stop here */
|
||||||
return (pos->moves.nmoves = nmoves);
|
return *nmoves;
|
||||||
|
|
||||||
/* sliding pieces */
|
/* sliding pieces */
|
||||||
bit_for_each64(from, tmp1, pos->bb[us][BISHOP] | pos->bb[us][QUEEN]) {
|
bit_for_each64(from, tmp1, pos->bb[us][BISHOP] | pos->bb[us][QUEEN]) {
|
||||||
movebits = hyperbola_bishop_moves(occ, from) & not_my_pieces;
|
movebits = hyperbola_bishop_moves(occ, from) & not_my_pieces;
|
||||||
bit_for_each64(to, tmp2, movebits & empty) {
|
bit_for_each64(to, tmp2, movebits & empty) {
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
}
|
}
|
||||||
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bit_for_each64(from, tmp1, pos->bb[us][ROOK] | pos->bb[us][QUEEN]) {
|
bit_for_each64(from, tmp1, pos->bb[us][ROOK] | pos->bb[us][QUEEN]) {
|
||||||
// printf("rook=%d/%s\n", from, sq_to_string(from));
|
// printf("rook=%d/%s\n", from, sq_to_string(from));
|
||||||
movebits = hyperbola_rook_moves(occ, from) & not_my_pieces;
|
movebits = hyperbola_rook_moves(occ, from) & not_my_pieces;
|
||||||
bit_for_each64(to, tmp2, movebits & empty) {
|
bit_for_each64(to, tmp2, movebits & empty) {
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
}
|
}
|
||||||
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,10 +227,10 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
bit_for_each64(from, tmp1, pos->bb[us][KNIGHT]) {
|
bit_for_each64(from, tmp1, pos->bb[us][KNIGHT]) {
|
||||||
movebits = bb_knight_moves(not_my_pieces, from);
|
movebits = bb_knight_moves(not_my_pieces, from);
|
||||||
bit_for_each64(to, tmp2, movebits & empty) {
|
bit_for_each64(to, tmp2, movebits & empty) {
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
}
|
}
|
||||||
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
bit_for_each64(to, tmp2, movebits & enemy_pieces) {
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,13 +243,13 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_up(to, them); /* reverse push */
|
from = pawn_push_up(to, them); /* reverse push */
|
||||||
//printf("push %d->%d %s->%s", from, to, sq_to_string(from), sq_to_string(to));
|
//printf("push %d->%d %s->%s", from, to, sq_to_string(from), sq_to_string(to));
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
}
|
}
|
||||||
/* possible second push */
|
/* possible second push */
|
||||||
movebits = pawn_shift_up(movebits & rel_rank3, us) & empty;
|
movebits = pawn_shift_up(movebits & rel_rank3, us) & empty;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_up(pawn_push_up(to, them), them);
|
from = pawn_push_up(pawn_push_up(to, them), them);
|
||||||
moves[nmoves++] = move_make_flags(from, to, M_DPUSH);
|
moves[(*nmoves)++] = move_make_flags(from, to, M_DPUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pawn: ranks 2-6 captures left */
|
/* pawn: ranks 2-6 captures left */
|
||||||
@@ -255,14 +257,14 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
movebits = pawn_shift_upleft(from_pawns, us) & enemy_pieces;
|
movebits = pawn_shift_upleft(from_pawns, us) & enemy_pieces;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_upleft(to, them); /* reverse capture */
|
from = pawn_push_upleft(to, them); /* reverse capture */
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
/* pawn: ranks 2-6 captures right */
|
/* pawn: ranks 2-6 captures right */
|
||||||
from_pawns = pos->bb[us][PAWN] & ~rel_rank7; // & ~rel_fileh;
|
from_pawns = pos->bb[us][PAWN] & ~rel_rank7; // & ~rel_fileh;
|
||||||
movebits = pawn_shift_upright(from_pawns, us) & enemy_pieces;
|
movebits = pawn_shift_upright(from_pawns, us) & enemy_pieces;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_upright(to, them);
|
from = pawn_push_upright(to, them);
|
||||||
moves[nmoves++] = move_make_capture(from, to);
|
moves[(*nmoves)++] = move_make_capture(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pawn: en-passant */
|
/* pawn: en-passant */
|
||||||
@@ -271,7 +273,7 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
from_pawns = pos->bb[us][PAWN]
|
from_pawns = pos->bb[us][PAWN]
|
||||||
& (pawn_shift_upleft(movebits, them) | pawn_shift_upright(movebits, them));
|
& (pawn_shift_upleft(movebits, them) | pawn_shift_upright(movebits, them));
|
||||||
bit_for_each64(from, tmp1, from_pawns) {
|
bit_for_each64(from, tmp1, from_pawns) {
|
||||||
moves[nmoves++] = move_make_enpassant(from, to);
|
moves[(*nmoves)++] = move_make_enpassant(from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,30 +281,30 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
movebits = pawn_shift_up(pos->bb[us][PAWN] & rel_rank7, us) & empty;
|
movebits = pawn_shift_up(pos->bb[us][PAWN] & rel_rank7, us) & empty;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_up(to, them); /* reverse push */
|
from = pawn_push_up(to, them); /* reverse push */
|
||||||
moves[nmoves++] = move_make_promote(from, to, QUEEN);
|
moves[(*nmoves)++] = move_make_promote(from, to, QUEEN);
|
||||||
moves[nmoves++] = move_make_promote(from, to, ROOK);
|
moves[(*nmoves)++] = move_make_promote(from, to, ROOK);
|
||||||
moves[nmoves++] = move_make_promote(from, to, BISHOP);
|
moves[(*nmoves)++] = move_make_promote(from, to, BISHOP);
|
||||||
moves[nmoves++] = move_make_promote(from, to, KNIGHT);
|
moves[(*nmoves)++] = move_make_promote(from, to, KNIGHT);
|
||||||
}
|
}
|
||||||
/* pawn promotion: rank 7 captures left */
|
/* pawn promotion: rank 7 captures left */
|
||||||
from_pawns = pos->bb[us][PAWN] & rel_rank7; // & ~rel_filea;
|
from_pawns = pos->bb[us][PAWN] & rel_rank7; // & ~rel_filea;
|
||||||
movebits = pawn_shift_upleft(from_pawns, us) & enemy_pieces;
|
movebits = pawn_shift_upleft(from_pawns, us) & enemy_pieces;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_upleft(to, them); /* reverse capture */
|
from = pawn_push_upleft(to, them); /* reverse capture */
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, QUEEN);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, QUEEN);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, ROOK);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, ROOK);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, BISHOP);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, BISHOP);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, KNIGHT);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, KNIGHT);
|
||||||
}
|
}
|
||||||
/* pawn: rank 7 captures right */
|
/* pawn: rank 7 captures right */
|
||||||
from_pawns = pos->bb[us][PAWN] & rel_rank7; // & ~rel_fileh;
|
from_pawns = pos->bb[us][PAWN] & rel_rank7; // & ~rel_fileh;
|
||||||
movebits = pawn_shift_upright(from_pawns, us) & enemy_pieces;
|
movebits = pawn_shift_upright(from_pawns, us) & enemy_pieces;
|
||||||
bit_for_each64(to, tmp1, movebits) {
|
bit_for_each64(to, tmp1, movebits) {
|
||||||
from = pawn_push_upright(to, them); /* reverse capture */
|
from = pawn_push_upright(to, them); /* reverse capture */
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, QUEEN);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, QUEEN);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, ROOK);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, ROOK);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, BISHOP);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, BISHOP);
|
||||||
moves[nmoves++] = move_make_promote_capture(from, to, KNIGHT);
|
moves[(*nmoves)++] = move_make_promote_capture(from, to, KNIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* castle - Attention ! Castling flags are assumed correct
|
/* castle - Attention ! Castling flags are assumed correct
|
||||||
@@ -319,14 +321,14 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb);
|
bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb);
|
||||||
if (!(occ & occmask) &&
|
if (!(occ & occmask) &&
|
||||||
!sq_attackers(pos, occ, from+1, them)) { /* f1/f8 */
|
!sq_attackers(pos, occ, from+1, them)) { /* f1/f8 */
|
||||||
moves[nmoves++] = move_make_flags(from, from + 2, M_CASTLE_K);
|
moves[(*nmoves)++] = move_make_flags(from, from + 2, M_CASTLE_K);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (can_ooo(pos->castle, us)) {
|
if (can_ooo(pos->castle, us)) {
|
||||||
bitboard_t occmask = rel_rank1 & (FILE_Bbb | FILE_Cbb | FILE_Dbb);
|
bitboard_t occmask = rel_rank1 & (FILE_Bbb | FILE_Cbb | FILE_Dbb);
|
||||||
if (!(occ & occmask) &&
|
if (!(occ & occmask) &&
|
||||||
!sq_attackers(pos, occ, from-1, them)) { /* d1/d8 */
|
!sq_attackers(pos, occ, from-1, them)) { /* d1/d8 */
|
||||||
moves[nmoves++] = move_make_flags(from, from - 2, M_CASTLE_Q);
|
moves[(*nmoves)++] = move_make_flags(from, from - 2, M_CASTLE_Q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,5 +343,5 @@ int pos_gen_pseudomoves(pos_t *pos)
|
|||||||
* add function per piece, and type, for easier debug
|
* add function per piece, and type, for easier debug
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
return (pos->moves.nmoves = nmoves);
|
return *nmoves;
|
||||||
}
|
}
|
||||||
|
@@ -22,8 +22,8 @@
|
|||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
|
||||||
bool pseudo_is_legal(const pos_t *pos, const move_t move);
|
bool pseudo_is_legal(const pos_t *pos, const move_t move);
|
||||||
move_t pos_next_legal(const pos_t *pos, int *start);
|
move_t pos_next_legal(const pos_t *pos, movelist_t *movelist, int *start);
|
||||||
movelist_t *pos_all_legal(const pos_t *pos, movelist_t *dest);
|
movelist_t *pos_all_legal(const pos_t *pos, movelist_t *movelist, movelist_t *dest);
|
||||||
int pos_gen_pseudomoves(pos_t *pos);
|
int pos_gen_pseudomoves(pos_t *pos, movelist_t *movelist);
|
||||||
|
|
||||||
#endif /* MOVEGEN_H */
|
#endif /* MOVEGEN_H */
|
||||||
|
@@ -105,8 +105,7 @@ pos_t *pos_clear(pos_t *pos)
|
|||||||
pos->pinners = 0;
|
pos->pinners = 0;
|
||||||
pos->blockers = 0;
|
pos->blockers = 0;
|
||||||
|
|
||||||
//pos->moves.curmove = 0;
|
//pos->moves.nmoves = 0;
|
||||||
pos->moves.nmoves = 0;
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,11 +156,13 @@ bool pos_cmp(const pos_t *pos1, const pos_t *pos2)
|
|||||||
if (warn_on(_cmpf(blockers)))
|
if (warn_on(_cmpf(blockers)))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (warn_on(_cmpf(moves.nmoves)))
|
/*
|
||||||
goto end;
|
* if (warn_on(_cmpf(moves.nmoves)))
|
||||||
for (int i = 0; i < pos1->moves.nmoves; ++i)
|
* goto end;
|
||||||
if (warn_on(_cmpf(moves.move[i])))
|
* for (int i = 0; i < pos1->moves.nmoves; ++i)
|
||||||
goto end;
|
* if (warn_on(_cmpf(moves.move[i])))
|
||||||
|
* goto end;
|
||||||
|
*/
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
end:
|
end:
|
||||||
|
@@ -52,7 +52,7 @@ typedef struct __pos_s {
|
|||||||
bitboard_t checkers; /* opponent checkers */
|
bitboard_t checkers; /* opponent checkers */
|
||||||
bitboard_t pinners; /* opponent pinners */
|
bitboard_t pinners; /* opponent pinners */
|
||||||
bitboard_t blockers; /* pieces blocking pin */
|
bitboard_t blockers; /* pieces blocking pin */
|
||||||
movelist_t moves;
|
//movelist_t moves;
|
||||||
} pos_t;
|
} pos_t;
|
||||||
|
|
||||||
typedef struct state_s state_t;
|
typedef struct state_s state_t;
|
||||||
|
@@ -29,6 +29,7 @@ int main(int __unused ac, __unused char**av)
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
char *fen, movebuf[8];;
|
char *fen, movebuf[8];;
|
||||||
pos_t *pos, *savepos;
|
pos_t *pos, *savepos;
|
||||||
|
movelist_t pseudo;
|
||||||
move_t move;
|
move_t move;
|
||||||
|
|
||||||
setlinebuf(stdout); /* line-buffered stdout */
|
setlinebuf(stdout); /* line-buffered stdout */
|
||||||
@@ -41,14 +42,14 @@ int main(int __unused ac, __unused char**av)
|
|||||||
printf("wrong fen %d: [%s]\n", i, fen);
|
printf("wrong fen %d: [%s]\n", i, fen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pos_gen_pseudomoves(pos);
|
pos_gen_pseudomoves(pos, &pseudo);
|
||||||
savepos = pos_dup(pos);
|
savepos = pos_dup(pos);
|
||||||
if (pos_cmp(pos, savepos) != true) {
|
if (pos_cmp(pos, savepos) != true) {
|
||||||
printf("*** positions differ 1\n");
|
printf("*** positions differ 1\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
int tmp = 0, j = 1;
|
int tmp = 0, j = 1;
|
||||||
while ((move = pos_next_legal(pos, &tmp)) != MOVE_NONE) {
|
while ((move = pos_next_legal(pos, &pseudo, &tmp)) != MOVE_NONE) {
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
pos_print(pos);
|
pos_print(pos);
|
||||||
|
@@ -76,7 +76,7 @@ static FILE *open_stockfish()
|
|||||||
return out_desc;
|
return out_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_stockfish_fen(FILE *desc, pos_t *pos, char *fen)
|
static void send_stockfish_fen(FILE *desc, pos_t *pos, movelist_t *movelist, char *fen)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int count, __unused mycount = 0, fishcount;
|
int count, __unused mycount = 0, fishcount;
|
||||||
@@ -85,8 +85,9 @@ static void send_stockfish_fen(FILE *desc, pos_t *pos, char *fen)
|
|||||||
|
|
||||||
pos_clear(pos);
|
pos_clear(pos);
|
||||||
|
|
||||||
move_t *moves = pos->moves.move;
|
move_t *moves = movelist->move;
|
||||||
int nmoves = pos->moves.nmoves;
|
int *nmoves = &movelist->nmoves;
|
||||||
|
*nmoves = 0;
|
||||||
//char nodescount[] = "Nodes searched";
|
//char nodescount[] = "Nodes searched";
|
||||||
//printf("nmoves = %d\n", nmoves);
|
//printf("nmoves = %d\n", nmoves);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -109,7 +110,7 @@ static void send_stockfish_fen(FILE *desc, pos_t *pos, char *fen)
|
|||||||
// buf[0], buf[1], buf[2], buf[3],
|
// buf[0], buf[1], buf[2], buf[3],
|
||||||
// sq_to_string(from), sq_to_string(to),
|
// sq_to_string(from), sq_to_string(to),
|
||||||
// count);
|
// count);
|
||||||
moves[nmoves++] = move_make(from, to);
|
moves[(*nmoves)++] = move_make(from, to);
|
||||||
|
|
||||||
} else if (sscanf(buf, "%*5s: %d", &count) == 1) {
|
} else if (sscanf(buf, "%*5s: %d", &count) == 1) {
|
||||||
square_t from = sq_from_string(buf);
|
square_t from = sq_from_string(buf);
|
||||||
@@ -120,10 +121,10 @@ static void send_stockfish_fen(FILE *desc, pos_t *pos, char *fen)
|
|||||||
// buf[0], buf[1], buf[2], buf[3],
|
// buf[0], buf[1], buf[2], buf[3],
|
||||||
// sq_to_string(from), sq_to_string(to),
|
// sq_to_string(from), sq_to_string(to),
|
||||||
// count);
|
// count);
|
||||||
moves[nmoves++] = move_make_promote(from, to, promoted);
|
moves[(*nmoves)++] = move_make_promote(from, to, promoted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos->moves.nmoves = nmoves;
|
//pos->moves.nmoves = nmoves;
|
||||||
// printf("fishcount=%d mycount=%d\n", fishcount, mycount);
|
// printf("fishcount=%d mycount=%d\n", fishcount, mycount);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
@@ -215,7 +216,7 @@ int main(int __unused ac, __unused char**av)
|
|||||||
FILE *outfd;
|
FILE *outfd;
|
||||||
char *fen;
|
char *fen;
|
||||||
pos_t *pos, *fishpos = pos_new();
|
pos_t *pos, *fishpos = pos_new();
|
||||||
movelist_t legal;
|
movelist_t pseudo, legal, fishmoves;
|
||||||
//bitboard_t wrong = 0x5088000040, tmp, loop;
|
//bitboard_t wrong = 0x5088000040, tmp, loop;
|
||||||
//bit_for_each64(loop, tmp, )
|
//bit_for_each64(loop, tmp, )
|
||||||
//printf("fishpos 1=%p\n", fishpos);
|
//printf("fishpos 1=%p\n", fishpos);
|
||||||
@@ -235,9 +236,9 @@ int main(int __unused ac, __unused char**av)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* print movelists */
|
/* print movelists */
|
||||||
send_stockfish_fen(outfd, fishpos, fen);
|
send_stockfish_fen(outfd, fishpos, &fishmoves, fen);
|
||||||
pos_gen_pseudomoves(pos);
|
pos_gen_pseudomoves(pos, &pseudo);
|
||||||
pos_all_legal(pos, &legal);
|
pos_all_legal(pos, &pseudo, &legal);
|
||||||
//printf("Fu ");
|
//printf("Fu ");
|
||||||
//moves_print(fishpos, 0);
|
//moves_print(fishpos, 0);
|
||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
@@ -246,7 +247,7 @@ int main(int __unused ac, __unused char**av)
|
|||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
|
|
||||||
/* sort and print movelists */
|
/* sort and print movelists */
|
||||||
move_sort_by_sq(&fishpos->moves);
|
move_sort_by_sq(&fishmoves);
|
||||||
move_sort_by_sq(&legal);
|
move_sort_by_sq(&legal);
|
||||||
// printf("\nFs ");
|
// printf("\nFs ");
|
||||||
// moves_print(fishpos, 0);
|
// moves_print(fishpos, 0);
|
||||||
@@ -256,10 +257,10 @@ int main(int __unused ac, __unused char**av)
|
|||||||
// fflush(stdout);
|
// fflush(stdout);
|
||||||
|
|
||||||
/* compare movelists */
|
/* compare movelists */
|
||||||
if (!movelists_equal(&fishpos->moves, &legal)) {
|
if (!movelists_equal(&fishmoves, &legal)) {
|
||||||
pos_print(pos);
|
pos_print(pos);
|
||||||
printf("F: ");
|
printf("F: ");
|
||||||
moves_print(&fishpos->moves, 0);
|
moves_print(&fishmoves, 0);
|
||||||
printf("M: ");
|
printf("M: ");
|
||||||
moves_print(&legal, 0);
|
moves_print(&legal, 0);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user