-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
148 lines (131 loc) · 3.75 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import numpy as np
from chess_standard.board_chess_pypi import BoardPypiChess
from chess_standard.mantis_chess import MantisChess
from chess_standard.random_chess import RandomChess
from connect4.board_c4 import BoardC4
import random
from connect4.mantis_c4 import MantisC4
from connect4.minimax_c4 import MinimaxC4
from connect4.c4net import C4Net
from connect4.minimax_c4 import TestNet
import time
import arcade
from connect4.random_c4 import RandomC4
from connect4.view import C4Game
def initializec4board():
moves = np.load("minimaxgamesample.npy")
moves = moves[:-2]
print(moves)
g = BoardC4.from_start()
for m in moves:
g = g.move_from_int(m)
g = g.move_from_int(3)
print(g)
bot = MantisC4("c4_58iter_1000mcts.pt", runs=1500)
print(bot.move_and_get_index(g))
print(moves)
def bot_v_bot():
game_board = BoardC4.from_start()
result = 2
# bot = MinimaxC4(depth=4)
bot2 = MinimaxC4(depth=4)
bot = MantisC4("c4_58iter_1000mcts.pt", runs=1500)
# bot2 = MantisC4("data6/net4.pt", True)
bot2 = RandomC4()
print(game_board)
indices = []
while result == 2:
if game_board.red_move:
# game_board = bot.move(game_board)
index = bot.move_and_get_index(game_board)
else:
# game_board = bot2.move(game_board)
index = bot2.move_and_get_index(game_board)
indices.append(index)
game_board = game_board.move_from_int(index)
print(game_board)
result = game_board.terminal_eval()
if result == 1:
print("x wins")
elif result == -1:
print("o wins")
else:
print("draw")
print(indices)
return result
def bot_v_human_C4():
SCREEN_WIDTH = 900
SCREEN_HEIGHT = 700
game = C4Game(SCREEN_WIDTH, SCREEN_HEIGHT, "c4_500mcts_80iter.pt")
game.setup()
arcade.run()
def bot_v_human_Chess():
# IMPLEMENT
print("Begun")
bot = MantisChess("chessbot.pt", runs=10)
starting_board = BoardPypiChess()
move1 = bot.move(starting_board)
print(move1.board)
def chess_metrics():
def bot_v_bot():
game_board = BoardPypiChess.from_start()
result = 2
# bot = MinimaxC4(depth=4)
bot = MantisChess("chessbot.pt", runs=300)
# bot2 = MantisC4("data6/net4.pt", True)
bot2 = RandomChess()
print(game_board.board)
indices = []
for _ in range(20):
if game_board.white_move:
# game_board = bot.move(game_board)
index = bot.move_and_get_index(game_board)
else:
# game_board = bot2.move(game_board)
index = bot2.move_and_get_index(game_board)
indices.append(index)
game_board = game_board.move_from_int(index)
print(game_board.board)
print("-" * 50)
result = game_board.terminate_from_local_stockfish()
if result == 1:
print("White wins")
elif result == -1:
print("Black wins")
else:
print("draw")
print(indices)
return result
w = 0
d = 0
b = 0
for i in range(25):
print(i)
st = time.time()
result = bot_v_bot()
print("et", time.time() - st)
if result == 1:
w += 1
if result == 0:
d += 1
if result == -1:
b += 1
print(w, d, b)
if __name__ == "__main__":
# bot_v_human_C4()
# bot_v_bot()
# bot_v_human_Chess()
# initializec4board()
# chess_metrics()
w = 0
d = 0
b = 0
for i in range(25):
result = bot_v_bot()
if result == 1:
w += 1
if result == 0:
d += 1
if result == -1:
b += 1
print(w, d, b)