-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
67 lines (52 loc) · 1.92 KB
/
game.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
from setup import Setup
from play import Play
from hand import Hand
import card
class Game:
prompt_history = []
prompt_queue = []
def play(self, reset_gamefile):
self.players = set()
self.hands = set()
self.cards = set()
self.me = None
self.conviction = None
self.gamefile = open('gamefile.txt', 'w+' if reset_gamefile else 'r+', buffering=1)
self.prompt_queue = [x.rstrip("\n") for x in self.gamefile]
setup = Setup()
setup.run(self)
play = Play()
play.run(self)
def prompt(self, prompt):
while True:
if len(self.prompt_queue) > 0:
response = self.prompt_queue.pop(0)
from_input = False
else:
response = input(prompt.question)
from_input = True
prompt.respond(response)
if prompt.satisfied():
if from_input:
self.gamefile.write(response + "\n")
self.prompt_history.append(response)
break
return prompt.response()
def notify_has(self, has_hand, card):
for hand in self.hands - set([has_hand]):
hand.lacks(card)
self.__compute_conviction()
def notify_lacks(self, has_hand, card):
self.__compute_conviction()
def __compute_conviction(self):
player_hands = [h for h in self.hands if h != self.conviction]
conviction_types = [c.type for c in self.conviction.has_set]
unconvicted_types = [t for t in card.TYPES if t not in conviction_types]
for card_type in unconvicted_types:
for c in [c for c in self.cards if c.type == card_type]:
all_lack = True
for hand in player_hands:
if c not in hand.lacks_set:
all_lack = False
if all_lack:
self.conviction.has(c)