|
CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
Select an action using a given method (min_max, alpha_beta). More...
#include <game_ai.hpp>
Public Types | |
| typedef Method::state | state |
| typedef Method::action | action |
| typedef Method::score | score |
Public Member Functions | |
| void | operator() (int depth, const state ¤t_state, action &new_action, bool computer_turn) const |
| Select an action using the given method. | |
Select an action using a given method (min_max, alpha_beta).
Template parameters:
Definition at line 188 of file game_ai.hpp.
| typedef Method::action claw::ai::game::select_action< Method >::action |
Definition at line 192 of file game_ai.hpp.
| typedef Method::score claw::ai::game::select_action< Method >::score |
Definition at line 193 of file game_ai.hpp.
| typedef Method::state claw::ai::game::select_action< Method >::state |
Definition at line 191 of file game_ai.hpp.
| void claw::ai::game::select_action< Method >::operator() | ( | int | depth, |
| const state & | current_state, | ||
| action & | new_action, | ||
| bool | computer_turn | ||
| ) | const |
Select an action using the given method.
| depth | Maximum depth of the search tree. |
| current_state | The state of the game. |
| new_action | (in/out) Best known action. |
| computer_turn | Tell if the action is done by the computer. |
Definition at line 328 of file game_ai.tpp.
{
std::list<action> l;
typename std::list<action>::iterator it;
score best_eval;
Method method;
// get all reachable states
current_state.next_actions( l );
best_eval = current_state.min_score();
for (it=l.begin(); it!=l.end(); ++it)
{
state* new_state;
score eval;
// try and evaluate each action
new_state = static_cast<state*>(current_state.do_action(*it));
eval = method(depth-1, *new_state, !computer_turn);
delete new_state;
// we keep one of the best actions
if (eval > best_eval)
{
best_eval = eval;
new_action = *it;
}
}
} // select_action::operator()
1.7.3