Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (45 loc) · 1.6 KB
/
Copy pathmain.py
File metadata and controls
55 lines (45 loc) · 1.6 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
52
53
54
55
import pygame
from data.classes.Board import Board
from target.bot import Bot as RandomBot
from data.classes.bots.minimax_bot import Bot as MinimaxBot
pygame.init()
WINDOW_SIZE = (600, 600)
screen = pygame.display.set_mode(WINDOW_SIZE)
board = Board(WINDOW_SIZE[0], WINDOW_SIZE[1])
def draw(display):
display.fill("white")
board.draw(display)
pygame.display.update()
if __name__ == "__main__":
running = True
bot1 = RandomBot()
bot2 = MinimaxBot()
while running:
mx, my = pygame.mouse.get_pos()
for event in pygame.event.get():
# Quit the game if the user presses the close button
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
# If the mouse is clicked
if event.button == 1:
board.handle_click(mx, my)
print(board.last_captured)
# Comment out the next 6 lines if you want to disable bot moves
if board.turn == "black":
m = bot1.move("black", board)
board.handle_move(m[0], m[1])
else:
m = bot2.move("white", board)
board.handle_move(m[0], m[1])
if board.is_in_checkmate("black"): # If black is in checkmate
print("White wins!")
running = False
elif board.is_in_checkmate("white"): # If white is in checkmate
print("Black wins!")
running = False
elif board.is_in_draw():
print("Draw!")
running = False
# Draw the board
draw(screen)