|
17 | 17 | #include <cstddef> // IWYU pragma: keep - for size_t |
18 | 18 | #include <libbenbot/search/Options.hpp> |
19 | 19 | #include <libchess/uci/CommandParsing.hpp> |
| 20 | +#include <limits> |
20 | 21 | #include <optional> |
21 | 22 |
|
22 | 23 | namespace ben_bot::search { |
@@ -47,35 +48,33 @@ namespace { |
47 | 48 | void Options::update_from(const chess::uci::GoCommandOptions& goOptions) |
48 | 49 | { |
49 | 50 | movesToSearch = goOptions.moves; |
50 | | - maxNodes = goOptions.nodes; |
51 | 51 | infinite = goOptions.infinite; |
52 | 52 | mateIn = goOptions.mateIn; |
53 | 53 |
|
54 | | - if (goOptions.depth.has_value()) |
55 | | - depth = *goOptions.depth; |
| 54 | + static constexpr auto MAX = std::numeric_limits<size_t>::max(); |
56 | 55 |
|
57 | | - // search time |
58 | | - if (goOptions.searchTime.has_value()) { |
59 | | - searchTime = goOptions.searchTime; |
60 | | - } else if (goOptions.infinite) { |
61 | | - searchTime = std::nullopt; |
62 | | - } else { |
63 | | - const bool isWhite = position.is_white_to_move(); |
| 56 | + depth = goOptions.depth.value_or(MAX); |
| 57 | + maxNodes = goOptions.nodes.value_or(MAX); |
64 | 58 |
|
65 | | - const auto& timeLeft = isWhite ? goOptions.whiteTimeLeft : goOptions.blackTimeLeft; |
| 59 | + searchTime = goOptions.searchTime |
| 60 | + .or_else([&goOptions, isWhite = position.is_white_to_move()]() -> std::optional<milliseconds> { |
| 61 | + if (not goOptions.infinite) { |
| 62 | + const auto& timeLeft = isWhite ? goOptions.whiteTimeLeft : goOptions.blackTimeLeft; |
66 | 63 |
|
67 | | - // need to know at least our time remaining in order to calculate search time limit |
68 | | - if (timeLeft.has_value()) { |
69 | | - searchTime = determine_search_time( |
70 | | - *timeLeft, |
71 | | - isWhite ? goOptions.whiteInc : goOptions.blackInc, |
72 | | - goOptions.movesToGo); |
73 | | - } |
74 | | - } |
| 64 | + // need to know at least our time remaining in order to calculate search time limit |
| 65 | + if (timeLeft.has_value()) { |
| 66 | + return determine_search_time( |
| 67 | + *timeLeft, |
| 68 | + isWhite ? goOptions.whiteInc : goOptions.blackInc, |
| 69 | + goOptions.movesToGo); |
| 70 | + } |
| 71 | + } |
75 | 72 |
|
76 | | - searchTime = searchTime.and_then([overhead = moveOverhead](const milliseconds time) { |
77 | | - return std::optional { time - overhead }; |
78 | | - }); |
| 73 | + return std::nullopt; |
| 74 | + }) |
| 75 | + .transform([overhead = moveOverhead](const milliseconds time) { |
| 76 | + return time - overhead; |
| 77 | + }); |
79 | 78 | } |
80 | 79 |
|
81 | 80 | } // namespace ben_bot::search |
0 commit comments