-
Notifications
You must be signed in to change notification settings - Fork 1
/
MinimaxVsMinimax.py
57 lines (50 loc) · 1.58 KB
/
MinimaxVsMinimax.py
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
46
47
48
49
50
51
52
53
54
55
56
57
from Checkers import Checkers
wins = 0
draws = 0
games = 200
START_PLAYER = Checkers.BLACK
for i in range(games):
game = Checkers()
# game.printBoard()
player = START_PLAYER
cnt = 0
# statesCounter = {}
# state = None
while cnt < 100:
# state = game.encodeBoard()
# if state not in statesCounter:
# statesCounter[state] = 0
# statesCounter[state] += 1
# # the exact same state repeated 3 times -> draw
# if statesCounter[state] == 3:
# print("state repeated 3 times")
# break
evaluator1 = Checkers.evaluate1
evaluator2 = Checkers.evaluate2
if cnt > 25:
evaluator1 = evaluator2 = Checkers.endGame
if player == START_PLAYER:
cont, reset = game.minimaxPlay(player, maxDepth=3, evaluate=evaluator1, enablePrint=False)
if not cont:
break
else:
cont, reset = game.minimaxPlay(player, maxDepth=3, evaluate=evaluator2, enablePrint=False)
if not cont:
break
player = 1-player
cnt += 1
if reset:
cnt = 0
# if stateCounter[state] == 3:
# print("Draw")
# draws += 1
if cnt == 100:
# print("Draw")
draws += 1
else:
# print (("WHITE" if player == Checkers.BLACK else "BLACK") + " Player wins")
if player != START_PLAYER:
wins += 1
print(i, end='\r')
loses = games - wins - draws
print(f"total wins of {wins}/{games}, draws of {draws}/{games} and loses of {loses}/{games}")