-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.py
More file actions
42 lines (32 loc) · 1.1 KB
/
Copy pathrules.py
File metadata and controls
42 lines (32 loc) · 1.1 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
from models import Card
def can_play(card: Card, top: Card | None, current_color: str) -> bool:
if card.is_wild():
return True
if card.color == current_color:
return True
if top is None:
return True
if card.kind == top.kind:
if card.kind == "number":
return card.value == top.value
return True
return False
def color_name(code: str) -> str:
return {"r": "RED", "g": "GREEN", "b": "BLUE", "y": "YELLOW"}.get(code, str(code))
def top_card_label(top: Card | None, current_color: str) -> str:
if top is None:
return "TOP: (none)"
if top.is_wild():
if top.kind == "+4":
return f"TOP: WILD +4 (Color: {color_name(current_color)})"
return f"TOP: WILD (Color: {color_name(current_color)})"
c = color_name(top.color)
if top.kind == "number":
return f"TOP: {c} {top.value}"
if top.kind == "skip":
return f"TOP: {c} SKIP"
if top.kind == "reverse":
return f"TOP: {c} REVERSE"
if top.kind == "+2":
return f"TOP: {c} +2"
return f"TOP: {c} {top.kind}"