-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
51 lines (40 loc) · 1.58 KB
/
gui.py
File metadata and controls
51 lines (40 loc) · 1.58 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
WIDTH, HEIGHT = 800, 800
ROWS, COLS = 8, 8
SQUARE_SIZE = WIDTH // COLS
BOARD_HEIGHT = SQUARE_SIZE * ROWS
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GRAY = (40, 100, 15)
FONT_SIZE = 36
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
def draw_board_from_bitboards(win, wp, wn, wb, wr, wq, wk, bp, bn, bb, br, bq, bk, images):
colours = [WHITE, GRAY]
for row in range(8):
for col in range(8):
colour = colours[(row + col) % 2]
pygame.draw.rect(win, colour, (col * SQUARE_SIZE, row * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE))
piece_bitboards = {
'wp': wp, 'wn': wn, 'wb': wb, 'wr': wr, 'wq': wq, 'wk': wk,
'bp': bp, 'bn': bn, 'bb': bb, 'br': br, 'bq': bq, 'bk': bk
}
for piece, bitboard in piece_bitboards.items():
for i in range(64):
if (bitboard >> i) & 1:
row = 7 - (i // 8)
col = i % 8
win.blit(images[piece], (col * SQUARE_SIZE, row * SQUARE_SIZE))
def display_winner(winner):
font = pygame.font.SysFont(None, 200)
text_surface = font.render(f"{winner} wins!", True, pygame.Color('green'))
text_rect = text_surface.get_rect(center=(WIDTH // 2, HEIGHT // 2))
WIN.blit(text_surface, text_rect)
pygame.display.flip()
pygame.time.delay(5000)
def display_draw():
font = pygame.font.SysFont(None, 200)
text_surface = font.render(f"Stalemate!", True, pygame.Color('red'))
text_rect = text_surface.get_rect(center=(WIDTH // 2, HEIGHT // 2))
WIN.blit(text_surface, text_rect)
pygame.display.flip()
pygame.time.delay(5000)