-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrays.h
112 lines (91 loc) · 3.03 KB
/
rays.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Stormphrax, a UCI chess engine
* Copyright (C) 2024 Ciekce
*
* Stormphrax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Stormphrax is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Stormphrax. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "types.h"
#include <array>
#include "core.h"
#include "bitboard.h"
#include "attacks/util.h"
#include "util/multi_array.h"
namespace stormphrax
{
consteval auto generateBetweenRays()
{
util::MultiArray<Bitboard, 64, 64> dst{};
for (i32 from = 0; from < 64; ++from)
{
const auto srcSquare = static_cast<Square>(from);
const auto srcMask = squareBit(srcSquare);
const auto rookAttacks = attacks::EmptyBoardRooks [from];
const auto bishopAttacks = attacks::EmptyBoardBishops[from];
for (i32 to = 0; to < 64; ++to)
{
if (from == to)
continue;
const auto dstSquare = static_cast<Square>(to);
const auto dstMask = squareBit(dstSquare);
if (rookAttacks[dstSquare])
dst[from][to]
= attacks::genRookAttacks(srcSquare, dstMask)
& attacks::genRookAttacks(dstSquare, srcMask);
else if (bishopAttacks[dstSquare])
dst[from][to]
= attacks::genBishopAttacks(srcSquare, dstMask)
& attacks::genBishopAttacks(dstSquare, srcMask);
}
}
return dst;
}
consteval auto generateIntersectingRays()
{
util::MultiArray<Bitboard, 64, 64> dst{};
for (i32 from = 0; from < 64; ++from)
{
const auto srcSquare = static_cast<Square>(from);
const auto srcMask = squareBit(srcSquare);
const auto rookAttacks = attacks::EmptyBoardRooks [from];
const auto bishopAttacks = attacks::EmptyBoardBishops[from];
for (i32 to = 0; to < 64; ++to)
{
if (from == to)
continue;
const auto dstSquare = static_cast<Square>(to);
const auto dstMask = squareBit(dstSquare);
if (rookAttacks[dstSquare])
dst[from][to]
= (srcMask | attacks::genRookAttacks(srcSquare, Bitboard{}))
& (dstMask | attacks::genRookAttacks(dstSquare, Bitboard{}));
else if (bishopAttacks[dstSquare])
dst[from][to]
= (srcMask | attacks::genBishopAttacks(srcSquare, Bitboard{}))
& (dstMask | attacks::genBishopAttacks(dstSquare, Bitboard{}));
}
}
return dst;
}
constexpr auto BetweenRays = generateBetweenRays();
constexpr auto IntersectingRays = generateIntersectingRays();
constexpr auto rayBetween(Square src, Square dst)
{
return BetweenRays[static_cast<i32>(src)][static_cast<i32>(dst)];
}
constexpr auto rayIntersecting(Square src, Square dst)
{
return IntersectingRays[static_cast<i32>(src)][static_cast<i32>(dst)];
}
}