50struct ArtificialGameState
57struct ArtificialGameMove
63class ArtificialGameDomain
66 using State = ArtificialGameState;
67 using Move = ArtificialGameMove;
70 static bool is_terminal(
const State &state)
72 return state.depth == 2;
75 static Score evaluate(
const State &state)
77 return root_score(state.code)*state.player;
80 static void apply(State &state,
const Move &move)
82 state.code = move.next_code;
83 state.player = -state.player;
87 static void undo(State &state,
const Move&)
90 state.player = -state.player;
94 template <
typename Visitor>
95 static bool for_each_successor(
const State &state, Visitor visit)
103 if (not visit(Move{2,
'A'}))
105 return visit(Move{3,
'B'});
108 if (not visit(Move{4,
'a'}))
110 return visit(Move{5,
'b'});
113 if (not visit(Move{6,
'a'}))
115 return visit(Move{7,
'b'});
123 [[nodiscard]]
static Score root_score(
const size_t code)
noexcept
141 for (
const auto &move : path)
142 out.push_back(move.label);
146template <
typename Result>
147void print_summary(
const char *title,
const Result &result)
149 std::cout << title <<
'\n';
150 std::cout <<
" value: " << result.value <<
'\n';
151 std::cout <<
" pv: " << signature(result.principal_variation) <<
'\n';
152 std::cout <<
" visited: " << result.stats.visited_states <<
'\n';
153 std::cout <<
" cutoffs: " << result.stats.alpha_beta_cutoffs <<
'\n';
160 const ArtificialGameState
root;
165 print_summary(
"Negamax", negamax);
166 print_summary(
"Alpha-Beta", alpha_beta);
Umbrella header for the implicit state-space search framework.
size_t size_t int32_t * out
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Main namespace for Aleph-w library functions.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
auto alpha_beta_search(Domain domain, typename Domain::State initial_state, ExplorationPolicy policy=Alpha_Beta< Domain >::default_policy(), SearchLimits limits={})
Convenience wrapper for one-shot Alpha-Beta search.
auto negamax_search(Domain domain, typename Domain::State initial_state, ExplorationPolicy policy=Negamax< Domain >::default_policy(), SearchLimits limits={})
Convenience wrapper for one-shot Negamax search.
std::string next_code(const Aleph::Adaptive_Huffman_Encoder &encoder, const unsigned char byte)
Probe a byte's code without changing the source encoder.