add move.c from pre-bitboard version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* chessdefs.h - generic chess definitions.
|
||||
/* chessdefs.h - generic/catchall chess definitions.
|
||||
*
|
||||
* Copyright (C) 2021 Bruno Raoult ("br")
|
||||
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||
* Licensed under the GNU General Public License v3.0 or later.
|
||||
* Some rights reserved. See COPYING.
|
||||
*
|
||||
@@ -48,7 +48,9 @@ typedef enum {
|
||||
#define ENDGAME 2
|
||||
|
||||
/* forward defs */
|
||||
typedef struct _pos_s pos_t;
|
||||
typedef struct __pos_s pos_t;
|
||||
typedef struct __movelist_s movelist_t;
|
||||
|
||||
/* bitboard
|
||||
*/
|
||||
//typedef u64 bitboard_t;
|
||||
|
@@ -48,7 +48,6 @@ uchar bb_rank_attacks[64 * 8];
|
||||
* to save one operation in hyperbola_moves().
|
||||
* TODO ? replace rank attack with this idea, mapping rank to diagonal ?
|
||||
* See http://timcooijmans.blogspot.com/2014/04/
|
||||
*
|
||||
*/
|
||||
void hyperbola_init()
|
||||
{
|
||||
@@ -56,7 +55,8 @@ void hyperbola_init()
|
||||
*/
|
||||
for (int occ = 0; occ < 64; ++occ) {
|
||||
for (int file = 0; file < 8; ++file) {
|
||||
uchar attacks = 0;
|
||||
int attacks = 0;
|
||||
//int o = mask << 1; /* skip right square */
|
||||
|
||||
/* set f left attacks */
|
||||
for (int slide = file - 1; slide >= 0; --slide) {
|
||||
@@ -69,10 +69,18 @@ void hyperbola_init()
|
||||
for (int slide = file + 1; slide < 8; ++slide) {
|
||||
int b = bb_sq[slide];
|
||||
attacks |= b;
|
||||
if ((occ << 1) & b)
|
||||
if ((occ << 1) & b) /* piece on b, we stop */
|
||||
//if ((o & b) == b)
|
||||
break;
|
||||
}
|
||||
bb_rank_attacks[occ * 8 + file] = attacks;
|
||||
bb_rank_attacks[(occ << 3) + file] = attacks;
|
||||
|
||||
//if (((occ << 3) + file) == 171) {
|
||||
//char str[64], str2[64];
|
||||
//printf("mask=%x=%s file=%d att=%x=%s\n",
|
||||
// occ, bitboard_rank_sprint(str, occ), file,
|
||||
// attacks, bitboard_rank_sprint(str2, attacks));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,11 +96,16 @@ void hyperbola_init()
|
||||
*/
|
||||
static bitboard_t hyperbola_rank_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
uint32_t rank = sq & SQ_FILEMASK;
|
||||
uint32_t file = sq & SQ_RANKMASK;
|
||||
uint64_t o = (occ >> rank) & 0x7e; /* 01111110 clear bits 0 & 7 */
|
||||
|
||||
return ((bitboard_t)bb_rank_attacks[o * 4 + file]) << rank;
|
||||
u32 rank = sq & SQ_RANKMASK;
|
||||
u32 file = sq & SQ_FILEMASK;
|
||||
u64 o = (occ >> rank) & 0176; /* 01111110 clear bits 0 & 7 */
|
||||
//char zob[128], zob2[128];
|
||||
//printf("rank_moves: occ=%lx=%s file=%d o=%lx=%s index=%ld=%ld attack=%lx=%s\n", occ,
|
||||
// bitboard_rank_sprint(zob, occ), file, o,
|
||||
// bitboard_rank_sprint(zob, o), (o << 2) + file, (o * 4) + file,
|
||||
// (bitboard_t)bb_rank_attacks[(o << 2) + file] << rank,
|
||||
// bitboard_rank_sprint(zob2, (bitboard_t)bb_rank_attacks[(o << 2) + file] << rank));
|
||||
return ((bitboard_t)bb_rank_attacks[(o << 2) + file]) << rank;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,30 +132,30 @@ static bitboard_t hyperbola_moves(const bitboard_t pieces, const square_t sq,
|
||||
|
||||
static bitboard_t hyperbola_file_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_file[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_file[sq]);
|
||||
}
|
||||
|
||||
static bitboard_t hyperbola_diag_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_diag[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_diag[sq]);
|
||||
}
|
||||
|
||||
static bitboard_t hyperbola_anti_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_anti[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_anti[sq]);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_bishop_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_diag_moves(occ, sq) + hyperbola_anti_moves(occ, sq);
|
||||
return hyperbola_diag_moves(occ, sq) | hyperbola_anti_moves(occ, sq);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_rook_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_file_moves(occ, sq) + hyperbola_rank_moves(occ, sq);
|
||||
return hyperbola_file_moves(occ, sq) | hyperbola_rank_moves(occ, sq);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_queen_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_bishop_moves(occ, sq) + hyperbola_rook_moves(occ, sq);
|
||||
return hyperbola_bishop_moves(occ, sq) | hyperbola_rook_moves(occ, sq);
|
||||
}
|
||||
|
1644
src/move.c
1644
src/move.c
File diff suppressed because it is too large
Load Diff
26
src/move.h
26
src/move.h
@@ -15,9 +15,8 @@
|
||||
#define MOVE_H
|
||||
|
||||
#include "chessdefs.h"
|
||||
#include "position.h"
|
||||
//#include "pool.h"
|
||||
#include "piece.h"
|
||||
#include "board.h"
|
||||
|
||||
/* move structure:
|
||||
* 3 2 2 1 1 1 1 1 1
|
||||
@@ -52,7 +51,7 @@
|
||||
|
||||
static inline move_t move_make(square_t from, square_t to)
|
||||
{
|
||||
return (to << 3) | from;
|
||||
return (to << 6) | from;
|
||||
}
|
||||
|
||||
static inline move_t move_make_promote(square_t from, square_t to, piece_type_t piece)
|
||||
@@ -60,9 +59,13 @@ static inline move_t move_make_promote(square_t from, square_t to, piece_type_t
|
||||
return move_make(from, to) | M_ENPASSANT | (piece << 15);
|
||||
}
|
||||
|
||||
static inline move_t move_from(move_t move)
|
||||
static inline square_t move_from(move_t move)
|
||||
{
|
||||
return move & 56;
|
||||
return move & 077;
|
||||
}
|
||||
static inline square_t move_to(move_t move)
|
||||
{
|
||||
return (move >> 6) & 077;
|
||||
}
|
||||
|
||||
/* moves_print flags
|
||||
@@ -75,7 +78,7 @@ static inline move_t move_from(move_t move)
|
||||
#define M_PR_SEPARATE 0x40 /* separate captures */
|
||||
#define M_PR_LONG 0x80
|
||||
|
||||
typedef struct {
|
||||
typedef struct __movelist_s {
|
||||
move_t move[MOVES_MAX];
|
||||
int nmoves; /* total moves (fill) */
|
||||
int curmove; /* current move (use) */
|
||||
@@ -83,19 +86,20 @@ typedef struct {
|
||||
|
||||
//pool_t *moves_pool_init();
|
||||
//void moves_pool_stats();
|
||||
|
||||
//int move_print(int movenum, move_t *move, move_flags_t flags);
|
||||
//void moves_print(pos_t *move, move_flags_t flags);
|
||||
|
||||
//void move_del(struct list_head *ptr);
|
||||
//int moves_del(pos_t *pos);
|
||||
extern void moves_print(pos_t *pos, int flags);
|
||||
extern void move_sort_by_sq(pos_t *pos);
|
||||
|
||||
int pseudo_moves_castle(pos_t *pos, bool color, bool doit, bool do_king);
|
||||
//extern int pseudo_moves_castle(pos_t *pos, bool color, bool doit, bool do_king);
|
||||
//int pseudo_moves_gen(pos_t *pos, piece_list_t *piece, bool doit, bool do_king);
|
||||
//int pseudo_moves_pawn(pos_t *pos, piece_list_t *piece, bool doit);
|
||||
//extern int moves_gen(pos_t *pos, bool color, bool doit, bool do_king);
|
||||
//extern int moves_gen_king_moves(pos_t *pos, bool color, bool doit);
|
||||
|
||||
//extern void moves_sort(pos_t *pos);
|
||||
// extern void moves_sort(pos_t *pos);
|
||||
|
||||
//extern void moves_gen_eval_sort(pos_t *pos);
|
||||
|
||||
//extern void moves_gen_all(pos_t *pos);
|
||||
|
Reference in New Issue
Block a user