-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_start.py
executable file
·79 lines (64 loc) · 2.18 KB
/
game_start.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
from numpy import random
from . import constants
from math import ceil
class Lotery:
""" Assigns roles to players.
We know that the number of players is valid."""
def __init__(self, n):
self.n = n
self.roles = numpy.random.permutation(self.n)
def assign(self, players):
l = ceil((self.n+1)/2)
f = n-l-1
# there should be one Hittler
assert(l + f = self.n - 1)
for i in range(self.roles):
if (self.roles[i] < liberal):
players[i].party = "liberal"
players[i].id = "liberal"
else if (self.roles[i] < l + f):
players[i].party = "fascist"
players[i].id = "fascist"
else:
players[i].party = "fascist"
players[i].id = "Hittler"
class GameBoard:
""" The game board which will be used during the game. """
def __init__(self, n):
""" Constructs an initial game board. """
self.n = n
self.laws_agreed = {
l = 0,
f = 0
}
self.laws_l = constants.laws_l
self.laws_f = constants.laws_f
self.laws_available = constants.laws_l + constants.laws_f
self.laws_discarded_l = 0
self.laws_discarded_f = 0
self.specials = constants.f_specials[n]
self.president = None
self.prev_president = None
self.chancelor = None
self.prev_chancelor = None
self.check_chancelor = False
def take_three_laws(self):
""" Chooses three laws at random. """
laws = ()
for i in range(3):
if(self.laws_available == 0):
self.refresh_laws()
law = numpy.random.randint(self.laws_available--)
if(law < self.laws_l):
self.laws_l--
laws.append(True)
else:
self.laws_f--
laws.append(False)
return laws
def refresh_laws(self):
self.laws_l = self.laws_discarded_l
self.laws_f = self.laws_discarded_f
self.laws_discarded_l = 0
self.laws_discarded_f = 0
self.laws_available = self.laws_l + self.laws_f