BenBot
1.7.5
A chess engine
Loading...
Searching...
No Matches
Material.hpp
Go to the documentation of this file.
1
/*
2
* ======================================================================================
3
*
4
* ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5
* ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6
* ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7
* ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8
* ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9
* ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10
* ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11
*
12
* ======================================================================================
13
*/
14
19
20
#pragma once
21
22
#include <cstdint>
23
#include <
libbenbot/eval/Score.hpp
>
24
#include <
libchess/board/Pieces.hpp
>
25
#include <
libchess/game/Position.hpp
>
26
#include <
libchess/pieces/PieceTypes.hpp
>
27
28
namespace
ben_bot::eval
{
29
30
using
chess::game::Position;
31
using
PieceType
=
chess::pieces::Type
;
32
36
namespace
piece_values
{
37
40
42
inline
constexpr
Value
PAWN
{ UINT16_C(100) };
43
45
inline
constexpr
Value
KNIGHT
{ UINT16_C(320) };
46
48
inline
constexpr
Value
BISHOP
{ UINT16_C(330) };
49
51
inline
constexpr
Value
ROOK
{ UINT16_C(500) };
52
54
inline
constexpr
Value
QUEEN
{ UINT16_C(900) };
55
60
inline
constexpr
Value
KING
{ UINT16_C(10000) };
61
63
67
[[nodiscard, gnu::const]]
constexpr
auto
get
(
PieceType
type)
noexcept
->
Value
;
68
69
}
// namespace piece_values
70
76
[[nodiscard, gnu::pure]]
constexpr
auto
score_material
(
const
Position
& position)
noexcept
->
Value
;
77
78
/*
79
___ ,--,
80
,---, ,--.'|_ ,--, ,--.'|
81
,---.'| | | :,' ,--.'| | | :
82
| | : : : ' : | |, : : ' .--.--.
83
| | | ,---. .;__,' / ,--.--. `--'_ | ' | / / '
84
,--.__| | / \ | | | / \ ,' ,'| ' | | | : /`./
85
/ ,' | / / |:__,'| : .--. .-. | ' | | | | : | : ;_
86
. ' / |. ' / | ' : |__ \__\/: . . | | : ' : |__ \ \ `.
87
' ; |: |' ; /| | | '.'| ," .--.; | ' : |__ | | '.'| `----. \
88
| | '/ '' | / | ; : ;/ / ,. | | | '.'|; : ;/ /`--' /__ ___ ___
89
| : :|| : | | , /; : .' \; : ;| , /'--'. / .\/ .\/ .\
90
\ \ / \ \ / ---`-' | , .-./| , / ---`-' `--'---'\ ; \ ; \ ; |
91
`----' `----' `--`---' ---`-' `--" `--" `--"
92
93
*/
94
95
namespace
piece_values {
96
97
constexpr
auto
get
(
const
PieceType
type)
noexcept
->
Value
98
{
99
switch
(type) {
100
case
PieceType::Pawn :
return
PAWN
;
101
case
PieceType::Knight:
return
KNIGHT
;
102
case
PieceType::Bishop:
return
BISHOP
;
103
case
PieceType::Rook :
return
ROOK
;
104
case
PieceType::Queen :
return
QUEEN
;
105
default : [[fallthrough]];
106
case
PieceType::King :
return
KING
;
107
}
108
}
109
110
}
// namespace piece_values
111
112
namespace
detail {
113
114
template
<
bool
IncludePawns = true>
115
[[nodiscard, gnu::pure]]
constexpr
auto
count_material
(
116
const
chess::board::Pieces
& pieces)
noexcept
117
->
Value
118
{
119
auto
total = (
static_cast<
Value
>
(pieces.knights.count()) *
piece_values::KNIGHT
)
120
+ (
static_cast<
Value
>
(pieces.bishops.count()) *
piece_values::BISHOP
)
121
+ (
static_cast<
Value
>
(pieces.rooks.count()) *
piece_values::ROOK
)
122
+ (
static_cast<
Value
>
(pieces.queens.count()) *
piece_values::QUEEN
);
123
124
if
constexpr
(IncludePawns) {
125
total += (
static_cast<
Value
>
(pieces.pawns.count()) *
piece_values::PAWN
);
126
}
127
128
return
static_cast<
Value
>
(total);
129
}
130
131
}
// namespace detail
132
133
constexpr
auto
score_material
(
const
Position
& position)
noexcept
->
Value
134
{
135
return
detail::count_material
(position.our_pieces())
136
-
detail::count_material
(position.their_pieces());
137
}
138
139
}
// namespace ben_bot::eval
PieceTypes.hpp
Pieces.hpp
Position.hpp
Score.hpp
ben_bot::eval::piece_values::get
constexpr auto get(PieceType type) noexcept -> Value
Definition
Material.hpp:97
ben_bot::eval::piece_values::QUEEN
constexpr Value QUEEN
Definition
Material.hpp:54
ben_bot::eval::Value
std::int16_t Value
Definition
Score.hpp:38
ben_bot::eval::score_material
constexpr auto score_material(const Position &position) noexcept -> Value
Definition
Material.hpp:133
ben_bot::eval::piece_values::PAWN
constexpr Value PAWN
Definition
Material.hpp:42
ben_bot::eval::piece_values::KING
constexpr Value KING
Definition
Material.hpp:60
ben_bot::eval::piece_values::KNIGHT
constexpr Value KNIGHT
Definition
Material.hpp:45
ben_bot::eval::piece_values::BISHOP
constexpr Value BISHOP
Definition
Material.hpp:48
ben_bot::eval::piece_values::ROOK
constexpr Value ROOK
Definition
Material.hpp:51
chess::pieces::Type
Type
Definition
PieceTypes.hpp:48
ben_bot::eval::detail::count_material
constexpr auto count_material(const chess::board::Pieces &pieces) noexcept -> Value
Definition
Material.hpp:115
ben_bot::eval::piece_values
Definition
Material.hpp:36
ben_bot::eval
Definition
DefaultWeights.hpp:30
ben_bot::eval::PieceType
chess::pieces::Type PieceType
Definition
Material.hpp:31
chess::board::Pieces
Definition
Pieces.hpp:49
chess::game::Position
Definition
Position.hpp:74
libbenbot
include
libbenbot
eval
Material.hpp
Generated on
for BenBot by
1.16.1