-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (35 loc) · 1.07 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
import pygame
from checkers.constants import WIDTH, HEIGHT, SQUARE_SIZE, RED, WHITE
from checkers.game import Game
from minimax.minimax import minimax
import time
FPS = 60
WHITE_DEPTH = 3
RED_DEPTH = 1
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Checkers')
def getRowColFromMouse(pos):
x, y = pos
row = y // SQUARE_SIZE
col = x // SQUARE_SIZE
return row, col
if __name__ == '__main__':
run = True
clock = pygame.time.Clock()
game = Game(WIN)
game.update()
while run:
clock.tick(FPS)
if game.turn == WHITE:
value, newBoard = minimax(game.getBoard(), WHITE_DEPTH, True)
game.aiMove(newBoard)
else:
value, newBoard = minimax(game.getBoard(), RED_DEPTH, False)
game.aiMove(newBoard)
if game.winner() != None:
run = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
game.update()
pygame.quit()