BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
TaperedScore.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
24namespace ben_bot::eval {
25
32struct TaperedScore final {
34 std::int32_t mg { 0 };
35
37 std::int32_t eg { 0 };
38
40 [[nodiscard]] static constexpr auto both(const std::int32_t value) noexcept -> TaperedScore
41 {
42 return { .mg = value, .eg = value };
43 }
44
47 [[nodiscard]] constexpr auto operator+(const TaperedScore& other) const noexcept -> TaperedScore
48 {
49 return { .mg = mg + other.mg, .eg = eg + other.eg };
50 }
51
52 [[nodiscard]] constexpr auto operator-(const TaperedScore& other) const noexcept -> TaperedScore
53 {
54 return { .mg = mg - other.mg, .eg = eg - other.eg };
55 }
56
57 [[nodiscard]] constexpr auto operator-() const noexcept -> TaperedScore
58 {
59 return { .mg = -mg, .eg = -eg };
60 }
61
62 [[nodiscard]] constexpr auto operator*(const int factor) const noexcept -> TaperedScore
63 {
64 return { .mg = mg * factor, .eg = eg * factor };
65 }
66
67 constexpr auto operator+=(const TaperedScore& other) noexcept -> TaperedScore&
68 {
69 mg += other.mg;
70 eg += other.eg;
71 return *this;
72 }
73
74 constexpr auto operator-=(const TaperedScore& other) noexcept -> TaperedScore&
75 {
76 mg -= other.mg;
77 eg -= other.eg;
78 return *this;
79 }
80
81
83 [[nodiscard]] constexpr auto operator==(const TaperedScore&) const noexcept -> bool = default;
84
89 [[nodiscard]] constexpr auto blend(
90 const std::int32_t mgPhase, const std::int32_t maxPhase) const noexcept -> std::int32_t
91 {
92 return ((mg * mgPhase) + (eg * (maxPhase - mgPhase))) / maxPhase;
93 }
94};
95
96} // namespace ben_bot::eval
constexpr auto operator-(const TaperedScore &other) const noexcept -> TaperedScore
constexpr auto operator==(const TaperedScore &) const noexcept -> bool=default
constexpr auto operator+(const TaperedScore &other) const noexcept -> TaperedScore
constexpr auto operator*(const int factor) const noexcept -> TaperedScore
constexpr auto operator-=(const TaperedScore &other) noexcept -> TaperedScore &
constexpr auto operator-() const noexcept -> TaperedScore
constexpr auto operator+=(const TaperedScore &other) noexcept -> TaperedScore &
constexpr auto blend(const std::int32_t mgPhase, const std::int32_t maxPhase) const noexcept -> std::int32_t
static constexpr auto both(const std::int32_t value) noexcept -> TaperedScore