-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiece.py
More file actions
78 lines (61 loc) · 1.38 KB
/
Copy pathpiece.py
File metadata and controls
78 lines (61 loc) · 1.38 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Piece module
"""
from enum import Enum
import pygame
from constants import (
GREY,
MAX_SCORE,
RED,
ROWS,
SQUARE_HEIGHT,
PADDING,
OUTLINE,
SQUARE_WIDTH,
WHITE_BASE,
)
class Turn(Enum):
"""
Turn enum
"""
YELLOW = True
RED = False
class EndStatus(Enum):
"""
End status
"""
YELLOW = 0
RED = 1
DRAW = 2
def convert_status_to_score(status: EndStatus, current_turn: Turn):
match status, current_turn:
case EndStatus.DRAW, _:
return 0
case (EndStatus.YELLOW, Turn.YELLOW) | (EndStatus.RED, Turn.RED):
return MAX_SCORE
case _:
return -MAX_SCORE
class Piece(Enum):
"""
Piece enum
"""
YELLOW = 0
RED = 1
EMPTY = 2
def calculate_position(row, col):
"""
Convert row column to screen coords
"""
x = col * SQUARE_WIDTH + SQUARE_WIDTH // 2
y = (ROWS - 1 - row) * SQUARE_HEIGHT + SQUARE_HEIGHT // 2
return x, y
def draw_piece(screen, piece: Piece, row: int, col: int):
"""
Draw piece
"""
radius = min(SQUARE_WIDTH, SQUARE_HEIGHT) // 2 - PADDING
pos = calculate_position(row, col)
pygame.draw.circle(screen, GREY, pos, radius + OUTLINE)
if piece != Piece.EMPTY:
color = RED if piece == Piece.RED else WHITE_BASE
pygame.draw.circle(screen, pygame.Color(color), pos, radius)