-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_runner.py
145 lines (135 loc) · 4.2 KB
/
old_runner.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
import board as bd
import bot as bp
import minimaxV1 as v1
import botV2 as bv2
import time
import pygame
# Constant and Pygame setup
WIDTH = 800
HEIGHT = 800
SQUARE_SIZE = WIDTH // 8
RADIUS = SQUARE_SIZE // 2 - 5
WHITE = (255, 255, 255)
WHITEGREEN = (239, 255, 251)
BLACK = (0, 0, 0)
GREY = (128, 128, 128)
BLUE = (0, 0, 255)
GREEN = (95, 208, 104)
RED = (255, 0, 0)
YELLOW = (255, 255, 0)
SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
##
intialPos = '0b0b0b0bb0b0b0b00b0b0b0b0000000000000000w0w0w0w00w0w0w0ww0w0w0w0'
customPos = '0b0b0b0bb0b0b0b00b0b0b000000000000000000w0w0w0w00w0w0w0ww0w0w0w0'
evalCalls = 0
#To force draw:
def countPieces(bstr):
#Count how many 0 in the string
count = 0
for i in range(64):
if bstr[i] == '0':
count += 1
return count
def playGame():
board = bd.Board('000b0b0b0000b0b00b0b000bb000b000000w0w000000w0000w0b0w0ww0w0w0w0')
board.printBoard()
turn = 1
while not board.endGame(turn):
print("Player ", turn, " turn")
x = int(input("Enter x coordinate: "))
y = int(input("Enter y coordinate: "))
direction = input("Enter direction: ")
if board.move(x, y, direction, turn):
board.printBoard()
turn = -turn
else:
print("Invalid move")
if board.utility(turn) == 1:
print("Player 1 wins")
else:
print("Player 2 wins")
def playGameBot():
board = bd.Board(intialPos)
board.betterPrintBoard()
turn = 1
while not board.endGame(turn):
print("Player ", turn, " turn")
if turn == 1:
x = int(input("Enter x coordinate: "))
y = int(input("Enter y coordinate: "))
direction = input("Enter direction: ")
if board.move(x, y, direction, turn):
board.betterPrintBoard()
turn = -turn
else:
print("Invalid move")
else:
timeStart = time.time()
curPos = board.getString()
suggestedPos = bp.botPlay(curPos, 10, turn)
timeEnd = time.time()
print('Time to evaluate: ', timeEnd - timeStart)
print('Number of evaluations: ', evalCalls)
board.editBoard(suggestedPos)
board.betterPrintBoard()
turn = -turn
if board.utility(turn) == 1:
print("Player 1 wins")
else:
print("Player 2 wins")
def twoBotGame():
board = bd.Board(customPos)
board.betterPrintBoard()
turn = 1
while not board.endGame(turn):
print("Player ", turn, " turn")
timeStart = time.time()
curPos = board.getString()
suggestedPos = bp.botPlay(curPos, 4, turn)
timeEnd = time.time()
print('Time to evaluate: ', timeEnd - timeStart)
board.editBoard(suggestedPos)
board.betterPrintBoard()
turn = -turn
if board.utility(turn) == 1:
print("Player 1 wins")
else:
print("Player 2 wins")
def oldBotnewBot():
board = bd.Board(intialPos)
board.betterPrintBoard()
turn = 1
moves = 0
global evalCalls
while not board.endGame(turn) and moves < 51:
cp1 = countPieces(board.getString())
print("Player ", turn, " turn")
if turn == 1:
timeStart = time.time()
curPos = board.getString()
suggestedPos = bv2.botPlay(curPos, 6, turn, moves, True)
timeEnd = time.time()
print('Time to evaluate: ', timeEnd - timeStart)
board.editBoard(suggestedPos)
board.betterPrintBoard()
turn = -turn
evalCalls = 0
else:
timeStart = time.time()
curPos = board.getString()
suggestedPos = bp.botPlay(curPos, 6, turn, moves, True)
timeEnd = time.time()
print('Time to evaluate: ', timeEnd - timeStart)
board.editBoard(suggestedPos)
board.betterPrintBoard()
turn = -turn
evalCalls = 0
cp2 = countPieces(board.getString())
if cp1 == cp2:
moves += 1
else:
moves = 0
if board.utility(turn) == 1:
print("Player 1 wins")
else:
print("Player 2 wins")