我有一个描述系统状态的类。
class Game_state { stack history; perform(Move); wind_back_last_move(); Game_state(Game_state); // prohibitively slow }
然后我进行了极小极大搜索
int minimax(Game_state& state, int depth, bool maximizingPlayer) { if(depth==0) { return heuristic(state); } if(maximizingPlayer) { value = -LARGE_SCORE; for(const auto& move : movelist(state)) state.perform(move); value = max(value, minimax(state, depth − 1, false)); state.wind_back_last_move(); } return value; } else { value = LARGE_SCORE; state.perform(move); for(const auto& move : movelist(state)) state.perform(move); value = min(value, minimax(state, depth − 1, true)); state.wind_back_last_move(); } return value }
我希望能够使用RAII进行回风操作,就像lock_guard释放互斥锁一样。有人可以在这种模式下为我提供很好的资源,也可以建议我在这种情况下这是否是一个明智的主意?