-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (37 loc) · 1.43 KB
/
main.py
File metadata and controls
51 lines (37 loc) · 1.43 KB
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
import pygame
from chess.variable_declaration import board_width, board_height, board_square_size, black_piece, white_piece
from chess.rules import Rules
from minimax.algorithm import minimax
# Initialising display
FPS: int = 60
window = pygame.display.set_mode((board_width, board_height))
pygame.display.set_caption('Chess Engine')
# User interaction with mouse
def get_board_row_col_from_mouse(position):
x, y = position
board_row = y // board_square_size
board_column = x // board_square_size
return board_row, board_column
# Event loop
def main():
start_chess_engine = True
runtime = pygame.time.Clock()
game_rules = Rules(window)
while start_chess_engine:
runtime.tick(FPS)
if game_rules.turn_taken == white_piece:
value, new_board = minimax(game_rules.get_board(), 3, white_piece, game_rules)
game_rules.algorithm_move(new_board)
if game_rules.winner() is not None:
print(game_rules.winner())
start_chess_engine = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
start_chess_engine = False
if event.type == pygame.MOUSEBUTTONDOWN:
position = pygame.mouse.get_pos()
board_row, board_column = get_board_row_col_from_mouse(position)
game_rules.select(board_row, board_column)
game_rules.update()
pygame.quit()
main()