-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (46 loc) · 1.88 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
56
57
58
59
60
import pygame
from game import Game
from gui import GUI
def main():
"""
Main function
"""
game = Game()
gui = GUI(game)
gui.display_start_menu()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
click_x = event.pos[0]
click_y = event.pos[1]
board_row = int(click_y // (gui.height / 3))
board_column = int(click_x // (gui.width / 3))
if game.player == 1:
if game.is_blank_position(board_row, board_column):
game.select_board_position(board_row, board_column, 1)
winner = game.check_winner()
if winner is not None:
gui.display_game_over(winner)
continue
game.player = 2
if (game.get_difficulty() == "Easy"):
game.select_random_board_position()
winner = game.check_winner()
if winner is not None:
gui.display_game_over(winner)
continue
elif game.get_difficulty() == "Hard":
best_move = game.get_best_move_alphabeta()
game.select_board_position(
best_move[0], best_move[1], 2)
winner = game.check_winner()
if winner is not None:
gui.display_game_over(winner)
continue
pass
game.player = 1
gui.updateScreen()
if __name__ == "__main__":
main()