Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
backtracking Namespace Reference

for std::vector More...

Functions

template<size_t T>
int minimax (int depth, int node_index, bool is_max, const std::array< int, T > &scores, double height)
 Check which is the maximum/minimum number in the array.
 

Detailed Description

for std::vector

Backtracking algorithms.

for IO operations

for std::array for IO operations

Backtracking algorithms

for std::array

Backtracking algorithms

for std::count for assert for IO operations for std::list for std::accumulate

Backtracking algorithms

for std::max, std::min for std::array for log2

Backtracking algorithms

for std::array for assert

Backtracking algorithms

for assert for IO operations for unordered_map

Backtracking algorithms

for assert for IO operations

Backtracking algorithms

for assert

Backtracking algorithms

Function Documentation

◆ minimax()

template<size_t T>
int backtracking::minimax ( int  depth,
int  node_index,
bool  is_max,
const std::array< int, T > &  scores,
double  height 
)

Check which is the maximum/minimum number in the array.

Parameters
depthcurrent depth in game tree
node_indexcurrent index in array
is_maxif current index is the longest number
scoressaved numbers in array
heightmaximum height for game tree
Returns
the maximum or minimum number
40 {
41 if (depth == height) {
42 return scores[node_index];
43 }
44
45 int v1 = minimax(depth + 1, node_index * 2, !is_max, scores, height);
46 int v2 = minimax(depth + 1, node_index * 2 + 1, !is_max, scores, height);
47
48 return is_max ? std::max(v1, v2) : std::min(v1, v2);
49}
int height(node *root)
Definition: avltree.cpp:31
T max(T... args)
STL namespace.
Here is the call graph for this function: