I'm trying to design a function template which searches for the best move for any game - of course the user of this function template has to implement some game specific functions. What i'm trying to do is to generalize the alpha beta search algorithm with a function template.
The declaration of this function template looks like this:
template<class GameState, class Move,
class EndGame, class Evaluate, class GetMoves, class MakeMove)
int alphaBetaMax(GameState g, int alpha, int beta, int depthleft);
Among other things the function has to:
- Determine if a game has ended:
bool EndGame(g)
- Evaluate the state of a game:
int Evaluate(g)
- Get the possible moves:
std::vector<Move> moves = GetMoves(g)
- Make a move:
Gamestate gnew = MakeMove(g, moves[i])
Do you think the function has to many template arguments? Is there a way to reduce the number of arguments? One idea is to extend the GameState class with members that evaluate the gamestate or decide if the game has ended. But a alpha beta search tree contains a lot of Gamestate instances which may leads to unnecessary memory requirements, thus i like to keep Gamestate small. In general, is a function template actually the right way?