-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.py
116 lines (103 loc) · 4.19 KB
/
Board.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from Bench import Bench
from Card import Card
from Consts import bcolors, COLORS, COLOR_NAME
from StatsForNerds import calculateNextCardStats, calculateReturnPointStats
from Player import Player
import random
class Board:
def __init__(self, showGame:bool, players:list[Player]):
self.showGame = showGame
self.stacks: list[list[Card]] = [[],[],[]]
self.reverse: bool = False
self.deck: list[Card] = self.buildDeck()
self.discard: list[Card] = []
self.events: list[str] = []
self.pTurn: int = 0
self.players: int = len(players)
self.playerAI: list[Player] = []
self.playerInfo: list[Bench] = []
self.playerStackReturnStats = []
for i in range(self.players):
self.playerInfo.append(Bench())
self.playerStackReturnStats.append(calculateReturnPointStats(self, i))
self.playerAI = players
self.resetRound()
def getReturnStats(self, playerNum:int=None):
if playerNum == None:
playerNum = self.pTurn
return self.playerStackReturnStats[playerNum]
def resetRound(self):
self.stacks: list[list[Card]] = [[],[],[]]
self.reverse: bool = False
self.nextCardStats = calculateNextCardStats(self)
for i in range(self.players):
self.playerStackReturnStats.append(calculateReturnPointStats(self, i))
def rollDie(self):
return random.choice(['Purple', 'Blue', 'Green', 'Yellow', 'Red', 'None'])
def addEvent(self, event: str):
self.events.insert(0,'> ' + event)
def drawCard(self):
if len(self.deck) == 0:
return None
toReturn = self.deck[0]
self.deck.remove(toReturn)
self.discard.append(toReturn)
self.nextCardStats = calculateNextCardStats(self)
return toReturn
def canPlaceInStack(self, stackIndex, card):
if stackIndex >= 3:
return None
matches = [c for c in self.stacks[stackIndex] if c.match(card)]
return len(matches) == 0
def placeStack(self, card: Card, index: int):
if index > 2:
return
self.stacks[index].append(card)
self.nextCardStats = calculateNextCardStats(self)
for i in range(self.players):
self.playerStackReturnStats[i] = calculateReturnPointStats(self, i)
def ApplyStack(self, stackIndex: int, playerNum: int):
points = self.playerInfo[playerNum].points
newPoints = 0
hasRollCard = False
for card in self.stacks[stackIndex]:
if card.type == 'num':
points[COLORS.index(card.color)] += card.number
newPoints += card.number
elif card.type == 'roll':
hasRollCard = True
if hasRollCard == True:
color = self.rollDie()
if color != 'None':
colorIndex = COLOR_NAME.index(color)
newPoints -= points[colorIndex]
self.addEvent(f'Player {playerNum+1}: Rolled {COLORS[colorIndex]}{color}{bcolors.ENDC}, {-points[colorIndex]} Points')
points[colorIndex] = 0
else:
self.addEvent(f'Player {playerNum+1}: Rolled {color}, -0 Points')
self.stacks[stackIndex] = []
for i in range(self.players):
self.playerStackReturnStats[i] = calculateReturnPointStats(self, i)
return newPoints
def getPlayerScore(self, i: int, colorIndex:int=-1):
if i >= self.players:
return 0
if colorIndex == -1:
return sum(self.playerInfo[i].points)
else:
return self.playerInfo[i].points[colorIndex]
def buildDeck(self):
deck = []
for i in range(1, 7):
for j in range(3):
deck.append(Card(bcolors.GREEN, i))
deck.append(Card(bcolors.YELLOW, i))
deck.append(Card(bcolors.RED, i))
deck.append(Card(bcolors.BLUE, i))
deck.append(Card(bcolors.PURPLE, i))
for i in range(18):
deck.append(Card(cardType='roll'))
for i in range(12):
deck.append(Card(cardType='switch'))
random.shuffle(deck)
return deck