-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·55 lines (42 loc) · 1.28 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
import pygame
from checkers.constants import SQUARE_SIZE, Color, WIDTH, HEIGHT
from checkers.game import Game
from ai.minimax import Minimax
from time import sleep
FPS = 60
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Checkers-AI")
def GetRowColFromMouse(pos):
"""It takes the current position of mouse and returns the
row and column of the square on the board."""
x,y = pos
row = y // SQUARE_SIZE
col = x // SQUARE_SIZE
return row, col
def main():
run = True
clock = pygame.time.Clock()
game = Game(WIN)
while run:
clock.tick(FPS)
# AI move.
if game.turn == Color.WHITE:
score, newBoard = Minimax(game.GetBoard(), 3, Color.WHITE, game)
game.AIMove(newBoard)
if game.Winner() != None:
print(game.Winner())
game.Reset()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
row, col = GetRowColFromMouse(pos)
game.Select(row, col)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
game.Reset()
game.Update()
pygame.quit()
if __name__ == "__main__":
main()