-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckersMain.py
52 lines (37 loc) · 1.49 KB
/
checkersMain.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
import pygame
from checkers.constants import WIDTH, HEIGHT, SQUARE_SIZE, RED, WHITE
from checkers.game import Game
from minimax.algorithm import minimax
# Create a main loop that checks for user input (mouse, keyboard, etc)
# Draw all the pieces, the board, etc.
FPS = 60 # do we need this in the constants file? No, only references drawing the game
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
# set caption for display here: shows up in top title bar
pygame.display.set_caption('AI Minimax Checkers')
def get_row_col_from_mouse(pos):
x, y = pos
row = y // SQUARE_SIZE
col = x // SQUARE_SIZE
return row, col
def main (): ## define main event loop
run = True
clock = pygame.time.Clock()
game = Game(WINDOW)
while run:
clock.tick(FPS)
if game.turn == WHITE: # Start AI HERE:
value, new_board = minimax(game.get_board(), 3, WHITE, game)
game.ai_move(new_board)
if game.winner() != None:
print(game.winner()) # prints red (255, 0, 0) or white (255, 255, 255) to the terminal
run = False # Terminates the game
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False # Teminate Game
if event.type == pygame.MOUSEBUTTONDOWN: # Select game piece with mouse
pos = pygame.mouse.get_pos()
row, col = get_row_col_from_mouse(pos)
game.select(row, col)
game.update()
pygame.quit()
main()