start bitboard init (see commit details)

- bitboard.c: make attacks for knight/king
- square macros (BB, BBfile, BBrank) renamed sq_make, sq_file,
  sq_rank, moved to board.h (and become temporarily inline funcs)
- different macros/defs moved to "correct place" (bitboard/board/piece):
  board.[ch]: everything related to board/square
  bitboard.[ch]: everything related to bitboards
  piece.[ch]: everything related to pieces
This commit is contained in:
2024-02-11 20:47:09 +01:00
parent 4f25c1416d
commit d5906b1fb9
10 changed files with 208 additions and 164 deletions

View File

@@ -11,32 +11,79 @@
*
*/
#include <stdio.h>
#include "brlib.h"
#include "chessdefs.h"
#include "board.h"
#include "bitboard.h"
/* maps are clockwise from N */
static char knight_vector[8] = {
NORTH*2 + EAST, NORTH + EAST*2, SOUTH + EAST*2, SOUTH*2 + EAST,
SOUTH*2 + WEST, SOUTH + WEST*2, NORTH + WEST*2, NORTH*2 + WEST
/* vectors are clockwise from N */
static int knight_vector[] = {
NORTH_EAST + NORTH, NORTH_EAST + EAST,
SOUTH_EAST + EAST, SOUTH_EAST + SOUTH,
SOUTH_WEST + SOUTH, SOUTH_WEST + WEST,
NORTH_WEST + WEST, NORTH_WEST + NORTH
};
static char king_vector[8] = {
static int king_vector[8] = {
NORTH, NORTH_EAST, EAST, SOUTH_EAST,
SOUTH, SOUTH_WEST, WEST, NORTH_WEST
};
static u64 knight_attacks[64], king_attacks[64];
static int zob=0;
bitboard_t sq_bb[SQUARE_MAX];
bitboard_t knight_attacks[64], king_attacks[64];
/* we will create only dest squares for A1-D4 square, then flip
*/
/**
* raw_bitboard_print() - print simple bitboard representation
* @bb: the bitboard
* @tit: a string or NULL
*/
void bitboard_init(void)
{
for (int sq = SQ_0; sq < SQ_N; ++sq) {
/* knight/king */
for (int j = 0; j < 8; ++j) {
zob += *knight_attacks + *king_attacks + *knight_vector +
*king_vector;
//int dest_knight = sq + knight_vector[j];
//if ()
}
square_t sq, dst;
for (sq = A1; sq <= H8; ++sq)
sq_bb[sq] = mask(sq);
for (sq = A1; sq <= H8; ++sq) {
for (int vec = 0; vec < 8; ++vec) {
dst = sq + knight_vector[vec];
if (sq_ok(dst)) {
if (sq_dist(dst, sq) == 2) {
knight_attacks[sq] |= sq_bb[dst];
}
}
dst = sq + king_vector[vec];
if (sq_ok(dst)) {
if (sq_dist(dst, sq) == 1) {
king_attacks[sq] |= sq_bb[dst];
}
}
}
}
}
/**
* bitboard_print() - print simple bitboard representation
* @bb: the bitboard
* @tit: a string or NULL
*/
void bitboard_print(const bitboard_t bb, const char *tit)
{
//char c = p? p: 'X';
if (tit)
printf("%s\n", tit);
for (rank_t r = RANK_8; r >= RANK_1; --r) {
printf("%d ", r);
for (file_t f = FILE_A; f <= FILE_H; ++f) {
printf(" %c", bb & sq_bb[sq_make(f, r)] ? 'X': '.');
}
printf("\n");
}
printf("\n A B C D E F G H\n");
return;
}