-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminiMax.py
More file actions
45 lines (30 loc) · 1001 Bytes
/
miniMax.py
File metadata and controls
45 lines (30 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
MAX = 10000
MIN = -10000
terminal = []
def minimax(depht, nodeIndex, maxPlayer, terminal, alpha, beta):
if depht == 3:
return terminal[nodeIndex]
if maxPlayer:
move = MIN
for i in range(0, 2):
val = minimax(depht + 1, nodeIndex * 2 + i, False, terminal, alpha, beta)
move = max(move, val)
alpha = max(alpha, move)
if beta <= alpha:
break
return move
else:
move = MAX
for i in range(0, 2):
val = minimax(depht + 1, nodeIndex * 2 + i, True, terminal, alpha, beta)
move = min(move, val)
alpha = min(alpha, move)
if beta <= alpha:
break
return move
if __name__ == "__main__":
n = int(input("Enter lenght of terminal: "))
for i in range(0, n):
x = int(input())
terminal.append(x)
print("The optimal value of MiniMax is : ",minimax(0,0,True,terminal,MIN,MAX))