@@ -3,7 +3,7 @@ def minimax(depth, node_index, is_maximizing_player, values, alpha, beta):
3
3
return values [node_index ]
4
4
5
5
if is_maximizing_player :
6
- best_value = float (' -inf' )
6
+ best_value = float (" -inf" )
7
7
for i in range (2 ): # Two children (0 and 1)
8
8
value = minimax (depth - 1 , node_index * 2 + i , False , values , alpha , beta )
9
9
best_value = max (best_value , value )
@@ -12,7 +12,7 @@ def minimax(depth, node_index, is_maximizing_player, values, alpha, beta):
12
12
break # Beta cut-off
13
13
return best_value
14
14
else :
15
- best_value = float (' inf' )
15
+ best_value = float (" inf" )
16
16
for i in range (2 ): # Two children (0 and 1)
17
17
value = minimax (depth - 1 , node_index * 2 + i , True , values , alpha , beta )
18
18
best_value = min (best_value , value )
@@ -21,8 +21,9 @@ def minimax(depth, node_index, is_maximizing_player, values, alpha, beta):
21
21
break # Alpha cut-off
22
22
return best_value
23
23
24
+
24
25
# Example usage
25
26
values = [3 , 5 , 2 , 9 , 0 , 1 , 8 , 6 ] # Leaf node values
26
27
depth = 3 # Depth of the game tree
27
- result = minimax (depth , 0 , True , values , float (' -inf' ), float (' inf' ))
28
+ result = minimax (depth , 0 , True , values , float (" -inf" ), float (" inf" ))
28
29
print ("The optimal value is:" , result )
0 commit comments