Compare commits
3 Commits
f4280dfa13
...
ffd5d056cc
Author | SHA1 | Date | |
---|---|---|---|
ffd5d056cc | |||
5cb90f5396 | |||
da489bad65 |
@@ -14,7 +14,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "brlib.h"
|
#include <brlib.h>
|
||||||
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#ifndef _BOARD_H
|
#ifndef _BOARD_H
|
||||||
#define _BOARD_H
|
#define _BOARD_H
|
||||||
|
|
||||||
#include "brlib.h"
|
#include <brlib.h>
|
||||||
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#ifndef _CHESSDEFS_H
|
#ifndef _CHESSDEFS_H
|
||||||
#define _CHESSDEFS_H
|
#define _CHESSDEFS_H
|
||||||
|
|
||||||
#include "brlib.h" /* brlib types */
|
#include <brlib.h> /* brlib types */
|
||||||
|
|
||||||
#define ONE 1ul
|
#define ONE 1ul
|
||||||
#define U64(const_u64) const_u64##UL
|
#define U64(const_u64) const_u64##UL
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "brlib.h"
|
#include <brlib.h>
|
||||||
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "brlib.h"
|
#include <brlib.h>
|
||||||
#include "likely.h"
|
#include <likely.h>
|
||||||
#include "bug.h"
|
#include <bug.h>
|
||||||
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
@@ -86,7 +86,7 @@ pos_t *move_do(pos_t *pos, const move_t move, state_t *state)
|
|||||||
pos_clr_sq(pos, to); /* clear square */
|
pos_clr_sq(pos, to); /* clear square */
|
||||||
} else if (is_castle(move)) { /* handle rook move */
|
} else if (is_castle(move)) { /* handle rook move */
|
||||||
square_t rookfrom, rookto;
|
square_t rookfrom, rookto;
|
||||||
if (is_castle_K(move)) {
|
if (to > from) {
|
||||||
rookfrom = sq_rel(H1, us);
|
rookfrom = sq_rel(H1, us);
|
||||||
rookto = sq_rel(F1, us);
|
rookto = sq_rel(F1, us);
|
||||||
} else {
|
} else {
|
||||||
@@ -193,7 +193,7 @@ pos_t *move_undo(pos_t *pos, const move_t move, const state_t *state)
|
|||||||
pos_set_sq(pos, to, pos->captured); /* restore captured piece */
|
pos_set_sq(pos, to, pos->captured); /* restore captured piece */
|
||||||
} else if (is_castle(move)) { /* make reverse rook move */
|
} else if (is_castle(move)) { /* make reverse rook move */
|
||||||
square_t rookfrom, rookto;
|
square_t rookfrom, rookto;
|
||||||
if (is_castle_K(move)) {
|
if (to > from) {
|
||||||
rookfrom = sq_rel(F1, us);
|
rookfrom = sq_rel(F1, us);
|
||||||
rookto = sq_rel(H1, us);
|
rookto = sq_rel(H1, us);
|
||||||
} else {
|
} else {
|
||||||
@@ -254,7 +254,7 @@ pos_t *move_do_alt(pos_t *pos, const move_t move, state_t *state)
|
|||||||
pos_clr_sq(pos, to); /* clear square */
|
pos_clr_sq(pos, to); /* clear square */
|
||||||
} else if (is_castle(move)) { /* handle rook move */
|
} else if (is_castle(move)) { /* handle rook move */
|
||||||
square_t rookfrom, rookto;
|
square_t rookfrom, rookto;
|
||||||
if (is_castle_K(move)) {
|
if (to > from) {
|
||||||
rookfrom = sq_rel(H1, us);
|
rookfrom = sq_rel(H1, us);
|
||||||
rookto = sq_rel(F1, us);
|
rookto = sq_rel(F1, us);
|
||||||
} else {
|
} else {
|
||||||
@@ -344,7 +344,7 @@ pos_t *move_undo_alt(pos_t *pos, const move_t move, const state_t *state)
|
|||||||
pos_set_sq(pos, to, pos->captured); /* restore captured piece */
|
pos_set_sq(pos, to, pos->captured); /* restore captured piece */
|
||||||
} else if (is_castle(move)) { /* make reverse rook move */
|
} else if (is_castle(move)) { /* make reverse rook move */
|
||||||
square_t rookfrom, rookto;
|
square_t rookfrom, rookto;
|
||||||
if (is_castle_K(move)) {
|
if (to > from) {
|
||||||
rookfrom = sq_rel(F1, us);
|
rookfrom = sq_rel(F1, us);
|
||||||
rookto = sq_rel(H1, us);
|
rookto = sq_rel(H1, us);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -379,13 +379,13 @@ movelist_t *pos_gen_pseudo(pos_t *pos, movelist_t *movelist)
|
|||||||
/* CHANGE HERE, either with bitmask >> or direct sq check */
|
/* CHANGE HERE, either with bitmask >> or direct sq check */
|
||||||
bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb);
|
bitboard_t occmask = rel_rank1 & (FILE_Fbb | FILE_Gbb);
|
||||||
if (!(occ & occmask)) {
|
if (!(occ & occmask)) {
|
||||||
*moves++ = move_make_flags(king, king + 2, M_CASTLE_K);
|
*moves++ = move_make_flags(king, king + 2, M_CASTLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)) { // &&
|
||||||
*moves++ = move_make_flags(king, king - 2, M_CASTLE_Q);
|
*moves++ = move_make_flags(king, king - 2, M_CASTLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/move.h
33
src/move.h
@@ -19,18 +19,15 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
/* move structure:
|
/* move structure:
|
||||||
* 3 3 2 2 1 1 1 1 1 1
|
* 1 1 1 1 1
|
||||||
* 1 0 4 3 8 7 5 4 2 1 6 5 0
|
* 8 5 4 2 1 6 5 0
|
||||||
* S UUUUUUU FFFFFF ccc ppp tttttt ffffff
|
* FFFF ppp tttttt ffffff
|
||||||
*
|
*
|
||||||
* bits len off range type mask get desc
|
* bits len off range type mask get desc
|
||||||
* ffffff 6 0 0-5 square_t 077 &077 from
|
* ffffff 6 0 0-5 square_t 077 &077 from
|
||||||
* tttttt 6 6 6-11 square_t 07700 (>>6) &077 to
|
* tttttt 6 6 6-11 square_t 07700 (>>6) &077 to
|
||||||
* ppp 3 12 12-14 piece_type_t 070000 (>>12) &07 promoted
|
* ppp 3 12 12-14 piece_type_t 070000 (>>12) &07 promoted
|
||||||
* ccc 3 15 15-17 piece_type_t 0700000 (>>15) &07 captured
|
* FFF 3 15 15-17 move_flags_t 0700000 (>>15) &07 flags
|
||||||
* FFFFFF 6 18 18-23 move_flags_t 077000000 (>>18) &077 N/A flags
|
|
||||||
* UUUUUUU 7 24 24-30 unused 017700000000 future usage
|
|
||||||
* S 1 31 31-31 - 020000000000 sign
|
|
||||||
*/
|
*/
|
||||||
typedef s32 move_t;
|
typedef s32 move_t;
|
||||||
|
|
||||||
@@ -42,30 +39,24 @@ enum {
|
|||||||
M_OFF_FROM = 0,
|
M_OFF_FROM = 0,
|
||||||
M_OFF_TO = 6,
|
M_OFF_TO = 6,
|
||||||
M_OFF_PROMOTED = 12,
|
M_OFF_PROMOTED = 12,
|
||||||
// M_OFF_CAPTURED = 15,
|
|
||||||
M_OFF_FLAGS = 15
|
M_OFF_FLAGS = 15
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
M_PROMOTION = 070000,
|
M_PROMOTION = 070000,
|
||||||
// M_CAPTURE = BIT(M_OFF_FLAGS + 0),
|
M_FLAGS_MASK = 0700000,
|
||||||
M_ENPASSANT = BIT(M_OFF_FLAGS + 0),
|
M_ENPASSANT = (1 << M_OFF_FLAGS),
|
||||||
M_CASTLE_K = BIT(M_OFF_FLAGS + 1), /* maybe only one ? */
|
M_CASTLE = (2 << M_OFF_FLAGS), /* maybe only one ? */
|
||||||
M_CASTLE_Q = BIT(M_OFF_FLAGS + 2), /* maybe only one ? */
|
// M_CHECK = (3 << M_OFF_FLAGS) /* maybe unknown/useless ? */
|
||||||
M_CHECK = BIT(M_OFF_FLAGS + 3), /* maybe unknown/useless ? */
|
|
||||||
// M_DPUSH = BIT(M_OFF_FLAGS + 7) /* pawn double push */
|
|
||||||
} move_flags_t;
|
} move_flags_t;
|
||||||
|
|
||||||
#define move_set_flags(move, flags) ((move) | (flags))
|
#define move_set_flags(move, flags) ((move) | (flags))
|
||||||
|
#define move_flags(move) ((move) & M_FLAGS_MASK)
|
||||||
|
|
||||||
//#define is_capture(m) ((m) & M_CAPTURE)
|
|
||||||
#define is_enpassant(m) ((m) & M_ENPASSANT)
|
|
||||||
#define is_promotion(m) ((m) & M_PROMOTION)
|
#define is_promotion(m) ((m) & M_PROMOTION)
|
||||||
#define is_castle(m) ((m) & (M_CASTLE_K | M_CASTLE_Q))
|
#define is_enpassant(m) (move_flags(m) == M_ENPASSANT)
|
||||||
#define is_castle_K(m) ((m) & M_CASTLE_K)
|
#define is_castle(m) (move_flags(m) == M_CASTLE)
|
||||||
#define is_castle_Q(m) ((m) & M_CASTLE_Q)
|
#define is_check(m) (move_flags(m) == M_CHECK)
|
||||||
#define is_check(m) ((m) & M_CHECK)
|
|
||||||
//#define is_dpush(m) ((m) & M_DPUSH)
|
|
||||||
|
|
||||||
#define MOVES_MAX 256
|
#define MOVES_MAX 256
|
||||||
|
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
#include "../src/fen.h"
|
|
||||||
#include "../src/move.h"
|
|
||||||
|
|
||||||
int main(int ac, char**av)
|
|
||||||
{
|
|
||||||
pos_t *pos;
|
|
||||||
|
|
||||||
debug_init(5, stderr, true);
|
|
||||||
piece_pool_init();
|
|
||||||
moves_pool_init();
|
|
||||||
pos_pool_init();
|
|
||||||
pos = pos_get();
|
|
||||||
|
|
||||||
if (ac == 1) {
|
|
||||||
fen2pos(pos, "rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2");
|
|
||||||
//pos_startpos(pos);
|
|
||||||
} else {
|
|
||||||
fen2pos(pos, av[1]);
|
|
||||||
}
|
|
||||||
//printf("turn = %d opponent = %d\n", pos->turn, OPPONENT(pos->turn));
|
|
||||||
moves_gen_all(pos);
|
|
||||||
pos_print(pos);
|
|
||||||
pos_pieces_print(pos);
|
|
||||||
moves_print(pos, M_PR_SEPARATE);
|
|
||||||
|
|
||||||
//bitboard_print2(castle_squares[0].controlled, castle_squares[1].controlled);
|
|
||||||
//bitboard_print2(castle_squares[0].occupied, castle_squares[1].occupied);
|
|
||||||
}
|
|
Reference in New Issue
Block a user