diff --git a/backtracking/minimax.cpp b/backtracking/minimax.cpp index eab29040c..e52049477 100644 --- a/backtracking/minimax.cpp +++ b/backtracking/minimax.cpp @@ -1,29 +1,31 @@ +/** + * @file + * @brief brief one line description here + */ #include #include #include #include -using std::cout; -using std::endl; -using std::max; -using std::min; -using std::vector; - -int minimax(int depth, int node_index, bool is_max, vector scores, +int minimax(int depth, int node_index, bool is_max, std::vector scores, int height) { - if (depth == height) + if (depth == height) { return scores[node_index]; + } int v1 = minimax(depth + 1, node_index * 2, !is_max, scores, height); int v2 = minimax(depth + 1, node_index * 2 + 1, !is_max, scores, height); - return is_max ? max(v1, v2) : min(v1, v2); + return is_max ? std::max(v1, v2) : std::min(v1, v2); } +/** + * Main function + */ int main() { - vector scores = {90, 23, 6, 33, 21, 65, 123, 34423}; + std::vector scores = {90, 23, 6, 33, 21, 65, 123, 34423}; int height = log2(scores.size()); - cout << "Optimal value: " << minimax(0, 0, true, scores, height) << endl; + std::cout << "Optimal value: " << minimax(0, 0, true, scores, height) << std::endl; return 0; }