-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
82 lines (63 loc) · 2.54 KB
/
game.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pygame
from board import Board
from board import pixel_to_chess
from board import chess_to_pixel
from bot import minmaxroot
import time
gameEnded = False
board = Board()
while not gameEnded:
danger = []
move = []
for event in pygame.event.get() :
if event.type == pygame.QUIT:
gameEnded = True
if board.turn == 'b':
i = minmaxroot(2,board,True)
print(i)
piece = board.board[i[0][0]][i[0][1]]
board.make_move(i[1],piece)
if board.turn == "w":
board.turn = "b"
else:
board.turn = "w"
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
# print("poss",pos)
chess_coord = pixel_to_chess(pos)
if board.col == chess_coord[1] and board.row == chess_coord[0] and board.isselected == True:
board.row = -1
board.col = -1
board.isselected = False
else:
board.row = chess_coord[1]
board.col = chess_coord[0]
print(f"row {board.row}, col {board.col}")
board.isselected = True
if board.isselected:
piece = board.board[board.row][board.col]
if piece == 0:
move = []
else:
if board.turn == piece.color:
piece.selected = True
move = piece.update_move(board)
if piece.selected:
if event.type == pygame.MOUSEBUTTONDOWN:
pos1 = pygame.mouse.get_pos()
chess_coord1 = pixel_to_chess(pos1)
row = chess_coord1[1]
col = chess_coord1[0]
if (row,col) in move:
board.make_move((row,col),piece)
if board.turn == "w":
board.turn = "b"
else:
board.turn = "w"
else:
piece.selected = False
else:
move = []
board.draw(move)
pygame.display.update()
pygame.quit()