mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Retire enum Direction
Use SquareDelta instead No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
f08a6eed0d
commit
cb7f20913e
4 changed files with 34 additions and 55 deletions
|
@ -455,25 +455,19 @@ namespace {
|
||||||
|
|
||||||
void init_between_bitboards() {
|
void init_between_bitboards() {
|
||||||
|
|
||||||
const SquareDelta directionToDelta[] = {
|
|
||||||
DELTA_E, DELTA_N, DELTA_NE, DELTA_NW, DELTA_W, DELTA_S, DELTA_SW, DELTA_SE
|
|
||||||
};
|
|
||||||
|
|
||||||
Square s1, s2, s3;
|
Square s1, s2, s3;
|
||||||
Direction d;
|
SquareDelta d;
|
||||||
|
|
||||||
for (s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
for (s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
||||||
for (s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
for (s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
||||||
{
|
{
|
||||||
BetweenBB[s1][s2] = EmptyBoardBB;
|
BetweenBB[s1][s2] = EmptyBoardBB;
|
||||||
d = direction_between_squares(s1, s2);
|
d = SquareDelta(DirectionTable[s1][s2]);
|
||||||
|
|
||||||
if (d == DIR_NONE)
|
if (d == DELTA_NONE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SquareDelta sd = directionToDelta[s2 > s1 ? d : d + 4];
|
for (s3 = s1 + d; s3 != s2; s3 += d)
|
||||||
|
|
||||||
for (s3 = s1 + sd; s3 != s2; s3 += sd)
|
|
||||||
set_bit(&(BetweenBB[s1][s2]), s3);
|
set_bit(&(BetweenBB[s1][s2]), s3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,44 +24,37 @@
|
||||||
|
|
||||||
#include "square.h"
|
#include "square.h"
|
||||||
|
|
||||||
uint8_t DirectionTable[64][64];
|
int8_t DirectionTable[64][64];
|
||||||
|
|
||||||
|
|
||||||
static bool reachable(Square orig, Square dest, Direction d) {
|
static SquareDelta direction(Square orig, Square dest) {
|
||||||
|
|
||||||
const SquareDelta directionToDelta[] = {
|
const SquareDelta directions[] = {
|
||||||
DELTA_E, DELTA_N, DELTA_NE, DELTA_NW, DELTA_W, DELTA_S, DELTA_SW, DELTA_SE
|
DELTA_E, DELTA_N, DELTA_NE, DELTA_NW, DELTA_W, DELTA_S, DELTA_SW, DELTA_SE
|
||||||
};
|
};
|
||||||
|
|
||||||
SquareDelta delta = directionToDelta[dest > orig ? d : d + 4];
|
Square from, to;
|
||||||
Square from = orig;
|
|
||||||
Square to = from + delta;
|
|
||||||
|
|
||||||
while (to != dest && square_distance(to, from) == 1 && square_is_ok(to))
|
for (int idx = 0; idx < 8; idx++)
|
||||||
{
|
{
|
||||||
from = to;
|
from = orig;
|
||||||
to += delta;
|
to = from + directions[idx];
|
||||||
|
|
||||||
|
while (to != dest && square_distance(to, from) == 1 && square_is_ok(to))
|
||||||
|
{
|
||||||
|
from = to;
|
||||||
|
to += directions[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (to == dest && square_distance(from, to) == 1)
|
||||||
|
return directions[idx];
|
||||||
}
|
}
|
||||||
return to == dest && square_distance(from, to) == 1;
|
return DELTA_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_direction_table() {
|
void init_direction_table() {
|
||||||
|
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
||||||
for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
||||||
{
|
DirectionTable[s1][s2] = uint8_t(direction(s1, s2));
|
||||||
DirectionTable[s1][s2] = uint8_t(DIR_NONE);
|
|
||||||
|
|
||||||
if (s1 == s2)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (Direction d = DIR_E; d != DIR_NONE; d++)
|
|
||||||
{
|
|
||||||
if (reachable(s1, s2, d))
|
|
||||||
{
|
|
||||||
DirectionTable[s1][s2] = uint8_t(d);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -638,9 +638,9 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
|
|
||||||
// A non-king move is legal if and only if it is not pinned or it
|
// A non-king move is legal if and only if it is not pinned or it
|
||||||
// is moving along the ray towards or away from the king.
|
// is moving along the ray towards or away from the king.
|
||||||
return ( !pinned
|
return !pinned
|
||||||
|| !bit_is_set(pinned, from)
|
|| !bit_is_set(pinned, from)
|
||||||
|| (direction_between_squares(from, king_square(us)) == direction_between_squares(move_to(m), king_square(us))));
|
|| squares_aligned(from, move_to(m), king_square(us));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -698,7 +698,7 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
|
||||||
{
|
{
|
||||||
// For pawn and king moves we need to verify also direction
|
// For pawn and king moves we need to verify also direction
|
||||||
if ( (pt != PAWN && pt != KING)
|
if ( (pt != PAWN && pt != KING)
|
||||||
||(direction_between_squares(from, ci.ksq) != direction_between_squares(to, ci.ksq)))
|
|| !squares_aligned(from, to, ci.ksq))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/square.h
24
src/square.h
|
@ -58,26 +58,20 @@ enum Rank {
|
||||||
|
|
||||||
enum SquareDelta {
|
enum SquareDelta {
|
||||||
|
|
||||||
DELTA_N = 8, DELTA_E = 1, DELTA_S = -8, DELTA_W = -1,
|
DELTA_N = 8, DELTA_E = 1, DELTA_S = -8, DELTA_W = -1, DELTA_NONE = 0,
|
||||||
|
|
||||||
DELTA_NN = DELTA_N + DELTA_N,
|
DELTA_NN = DELTA_N + DELTA_N,
|
||||||
DELTA_NE = DELTA_N + DELTA_E,
|
DELTA_NE = DELTA_N + DELTA_E,
|
||||||
DELTA_SE = DELTA_S + DELTA_E,
|
DELTA_SE = DELTA_S + DELTA_E,
|
||||||
DELTA_SS = DELTA_S + DELTA_S,
|
DELTA_SS = DELTA_S + DELTA_S,
|
||||||
DELTA_SW = DELTA_S + DELTA_W,
|
DELTA_SW = DELTA_S + DELTA_W,
|
||||||
DELTA_NW = DELTA_N + DELTA_W,
|
DELTA_NW = DELTA_N + DELTA_W
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Direction {
|
|
||||||
DIR_E = 0, DIR_N = 1, DIR_NE = 2, DIR_NW = 3, DIR_NONE = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ENABLE_OPERATORS_ON(Square);
|
ENABLE_OPERATORS_ON(Square);
|
||||||
ENABLE_OPERATORS_ON(File);
|
ENABLE_OPERATORS_ON(File);
|
||||||
ENABLE_OPERATORS_ON(Rank);
|
ENABLE_OPERATORS_ON(Rank);
|
||||||
ENABLE_OPERATORS_ON(SquareDelta);
|
ENABLE_OPERATORS_ON(SquareDelta);
|
||||||
ENABLE_OPERATORS_ON(Direction);
|
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
@ -87,7 +81,7 @@ ENABLE_OPERATORS_ON(Direction);
|
||||||
const int FlipMask = 56;
|
const int FlipMask = 56;
|
||||||
const int FlopMask = 7;
|
const int FlopMask = 7;
|
||||||
|
|
||||||
extern uint8_t DirectionTable[64][64];
|
extern int8_t DirectionTable[64][64];
|
||||||
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
@ -189,16 +183,14 @@ inline bool square_is_ok(Square s) {
|
||||||
return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
|
return file_is_ok(square_file(s)) && rank_is_ok(square_rank(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Direction direction_between_squares(Square s1, Square s2) {
|
inline bool squares_aligned(Square s1, Square s2, Square s3) {
|
||||||
return Direction(DirectionTable[s1][s2]);
|
return DirectionTable[s1][s2] != DELTA_NONE
|
||||||
}
|
&& abs(DirectionTable[s1][s2]) == abs(DirectionTable[s2][s3]);
|
||||||
|
|
||||||
inline int direction_is_diagonal(Square s1, Square s2) {
|
|
||||||
return DirectionTable[s1][s2] & 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool direction_is_straight(Square s1, Square s2) {
|
inline bool direction_is_straight(Square s1, Square s2) {
|
||||||
return DirectionTable[s1][s2] < 2;
|
return abs(DirectionTable[s1][s2]) == DELTA_N
|
||||||
|
|| abs(DirectionTable[s1][s2]) == DELTA_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
Loading…
Add table
Reference in a new issue