-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLTK_board.py
151 lines (96 loc) · 4.85 KB
/
LTK_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import LTK_deck
import LTK_player
import random
import logging
log = logging.getLogger('default')
class board:
##################################################################################################################################################
#
# Initialization functions
#
##################################################################################################################################################
def __init__(self, n_players):
self.table = {} #key is position, and stores player object
self.deadPlayers = []
self.deck = LTK_deck.Deck()
self.assignPositionsandRoles(n_players)
self.characterChoices()
self.deal()
self.playerturn = 0
self.rounds = 0
self.winner = None
# assigns everyone a random role, put monarch at position 0, put everyone else at a random position
def assignPositionsandRoles(self, n_players):
roles = []
for key,val in RoleDistribution[n_players].items():
roles.extend([key]*val)
names = []
for i in range(1, n_players + 1):
inputname = input("Please input player {n}'s name:\n".format(n = i))
while inputname in names:
inputname = input("That name has already been chosen, please input another name for player {n}:\n".format(n = i))
names.append(inputname)
for i in range(n_players):
if i == 0:
self.table[i] = [names.pop(random.randrange(0,len(names))), "Monarch"]
else:
self.table[i] = [names.pop(random.randrange(0,len(names))), roles.pop(random.randrange(0,len(roles)))]
log.info("Assigned positions and rolls")
def characterChoices(self):
for i in range(len(self.table)):
# have player at 0 (Monarch) choose character first, put the ones they didn't choose back in pool
# for others, don't put choices back in pool
# everything except Monarch should be simultaneous.... but for now..... a loop will do
# initialize players from LTK_player based on character selection - for now generic player
self.table[i] = LTK_player.Player(self.table[i][0], self.table[i][1], i, self.deck, self)
def deal(self):
for p in self.table.values():
p.draw(4)
##################################################################################################################################################
#
# Gameplay
#
##################################################################################################################################################
def play(self):
# basic rules for going around in order and having each character play
while not self.winner:
log.info("Round: {rounds}".format(rounds = self.rounds))
log.info("Player Turn: {name}".format(name = self.table[self.playerturn].name))
for i in self.table:
log.info("Player {name} currently has {health} health".format(name = self.table[i].name, health = self.table[i].health))
if self.playerturn == 0:
self.rounds += 1 #everytime it's the monarch's turn, it counts as a new round
self.table[self.playerturn].turn()
self.playerturn = (self.playerturn + 1) % len(self.table) # just an update for who goes next
if self.rounds > 20: #safety for now, remove later
log.info("Reached over 5 rounds, we're quitting the game")
self.winner = "No one"
log.info("The winner was: " + self.winner)
def isGameOver(self):
stillMonarch = False
stillRebel = False
stillTurncoat = False
for i in self.table.values():
if i.role == "Monarch":
stillMonarch = True
if i.role == "Rebel":
stillRebel = True
if i.role == "Turncoat":
stillTurncoat = True
if stillMonarch and (stillRebel or stillTurncoat):
return False
if stillMonarch:
self.winner = "Team Monarch"
elif stillRebel:
self.winner = "Team Rebel"
else:
self.winner = "The Lone Turncoat"
#Monarch is always 1
#TODO: check if this role distribution is correct
RoleDistribution = {4: {"Minister": 0, "Rebel": 2, "Turncoat": 1},
5: {"Minister": 1, "Rebel": 2, "Turncoat": 1},
6: {"Minister": 1, "Rebel": 3, "Turncoat": 1},
7: {"Minister": 2, "Rebel": 3, "Turncoat": 1},
8: {"Minister": 2, "Rebel": 4, "Turncoat": 1},
9: {"Minister": 3, "Rebel": 4, "Turncoat": 1},
10: {"Minister": 3, "Rebel": 4, "Turncoat": 2}}