-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
49 lines (37 loc) · 1.14 KB
/
play.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 constants import *
from game import Game
pygame.font.init()
pygame.display.set_caption("Connect 4")
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
agent = {
"human": 0,
"AI": 1
}
def play():
game = Game(agent["human"], agent["AI"], 6)
clock = pygame.time.Clock()
run = True
ai_processing = False
while run:
if not ai_processing:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
game.make_move_human()
WIN.fill((0, 0, 0))
game.board.draw_board(WIN)
pygame.display.update()
ai_processing = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
game.restart()
if ai_processing:
game.make_move_AI()
ai_processing = False
WIN.fill((0, 0, 0))
game.board.draw_board(WIN)
pygame.display.update()
pygame.quit()
play()