-
Notifications
You must be signed in to change notification settings - Fork 2
/
play_skat.py
67 lines (55 loc) · 1.99 KB
/
play_skat.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
"""High-level instructions for playing a round of skat.
Intended to be imported into a wrapper (skat_wrapper) so that more than one
round can be played. Low-level details, along with thorough documentation, are
in another module (skat_classes).
"""
from skat_classes import *
N_CARDS = 30 # Excluding kitty
def trick_taking(r, players):
for _ in range(N_CARDS):
r.get_play(players[r.whoseTurn])
r.next_turn()
def play_one_round(players, names, verbosity):
"""Play and return the scores (list of int) for one round."""
# Setup
r = Round(names, verbosity) # Instantiation of a single round of skat
r.generate_deck()
[p.assess_hand(r) for p in players] # List, not generator --> non-lazy
scores = [0, 0, 0] # Convention: p0 plays first, p1 bids first, p2 deals
# Bidding
while True: # Repeat until a player passes.
if not r.get_bid(players[1], 1):
advancer = 0
break
if not r.get_bid(players[0], 0):
advancer = 1
break
while True:
if not r.get_bid(players[2], 2):
declarer = advancer
break
if not r.get_bid(players[advancer], advancer):
declarer = 2
break
if r.bidHistory == [False, False]: # First players both passed.
if not r.get_bid(players[0], 0):
r.declarer = None
r.declaration = ['grand']
r.check_overbid()
trick_taking(r, players)
return r.score_minigame()
else:
declarer = 0
# Declaring (first kitty, then game type and other extras)
if r.get_kitty_declaration(players[declarer], declarer):
r.give_kitty()
r.get_kitty_discards(players[declarer])
r.get_declaration(players[declarer])
overbid = r.check_overbid()
if overbid:
scores[declarer] = -2 * overbid
return scores
trick_taking(r, players)
# Scoring
scores[declarer] = r.score()
return scores