यदि आप कुछ सी ++ का उपयोग करने के इच्छुक हैं, तो आप "फ़ंक्शन ऑब्जेक्ट" का उपयोग कर सकते हैं:
struct MoveHandler {
chess_game *game;
int depth;
MoveHandler(chess_game *g, int d): game(g), depth(d) {}
void operator() (chess_move*) {
//now you can use the game and the depth
}
};
और एक टेम्पलेट में अपना foreachMove
चालू करें:
template
void foreachMove(T action, chess_game* game);
और आप इसे इस तरह से कॉल कर सकते हैं:
chess_move getNextMove(chess_game* game, int depth){
//for each valid move, determine how good the move is
foreachMove(MoveHandler(game, depth), game);
}
लेकिन यह MoveHandler
के आपके अन्य उपयोगों को बाधित नहीं करेगा।