forked from thexa4/Spades
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbids.py
62 lines (52 loc) · 1.83 KB
/
bids.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
from relative_data import RelativeData
class Bids(RelativeData):
def __init__(self, reference_id=0):
super().__init__(reference_id)
self.bids = self.data
def add_bid(self, bid, player_id):
""""Add a new bid."""
global_id = self.globalize_id(player_id)
assert len(self.bids) < self.data_size and global_id not in self.bids
if bid == 0:
bid = "N"
self.bids[global_id] = bid
def team_has_nill(self, team_id):
"""Return whether a player on a team has bid a Nill."""
global_team_id = (team_id + self.reference_id) % 2
player_ids = [global_team_id, global_team_id + 2]
for player_id in player_ids:
if player_id in self.bids and (self.bids[player_id] == "N" or self.bids[player_id] == "B"):
return True
return False
def get_blinder_id(self):
for player_id in self.bids:
if self.bids[player_id] == "B":
return self.localize_id(player_id)
return None
def get_team_bid(self, team_id):
""""
Get the bid of a team.
return: A list with a single entry if both players made a normal bid, or the separate bids if either player has bid a (Blind) Nill.
List will contain '?' if a player has not yet made a bid.
"""
player_ids = [(self.reference_id + team_id) % 4, (self.reference_id + team_id + 2) % 4]
res = []
summable = True
for player_id in player_ids:
if player_id in self.bids:
if self.bids[player_id] == "N" or self.bids[player_id] == "B":
summable = False
res.append(self.bids[player_id])
else:
summable = False
res.append('?')
if summable:
res = [res[0] + res[1]]
return res
def __str__(self):
str_bids = {i: '?' for i in range(4)}
for i in range(4):
if i in self.bids:
local_id = self.localize_id(i)
str_bids[local_id] = str(self.bids[i])
return "Bids: team 0: " + str_bids[0] + " + " + str_bids[2] + " team 1: " + str_bids[1] + " + " + str_bids[3]