-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulation.py
More file actions
80 lines (63 loc) · 2.36 KB
/
simulation.py
File metadata and controls
80 lines (63 loc) · 2.36 KB
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
import itertools
import pydealer
from cribbage import CribbageHand
def deal_hand():
deck = pydealer.Deck()
deck.shuffle()
hand = deck.deal(7)
return CribbageHand(cards=hand)
def simulate_hand(strategy):
initial_hand = deal_hand()
hand = strategy(initial_hand)
return hand
def random_strategy(initial_hand):
"""This strategy throws two random cards"""
saved_cards = initial_hand._cards[2:]
return CribbageHand(cards=saved_cards)
def best_oracle_strategy(initial_hand):
"""This strategy waits to see what the cut is before throwing
the two best cards. Obviously, it is not a possible strategy"""
best_hand = None
for cards in itertools.combinations(initial_hand._cards[:6], 4):
hand = CribbageHand(list(cards) + [initial_hand._cards[6]])
if not best_hand:
best_hand = hand
if hand > best_hand:
best_hand = hand
return best_hand
def worst_oracle_strategy(initial_hand):
"""This strategy waits to see what the cut is before throwing
the worst cards. Obviously, it is not a possible strategy"""
worst_hand = None
for cards in itertools.combinations(initial_hand._cards[:6], 4):
hand = CribbageHand(list(cards) + [initial_hand._cards[6]])
if not worst_hand:
worst_hand = hand
if hand < worst_hand:
worst_hand = hand
return worst_hand
def best_blind_strategy(initial_hand):
"""This strategy saves the most pre-cut points possible"""
best_hand = None
for cards in itertools.combinations(initial_hand._cards[:6], 4):
hand = CribbageHand(list(cards))
if not best_hand:
best_hand = hand
if hand > best_hand:
best_hand = hand
final_hand = CribbageHand(list(best_hand._cards) +
[initial_hand._cards[6]])
return final_hand
def best_blind_strategy_3player(initial_hand):
"""This strategy saves the most pre-cut points possible
for a 3 player hand"""
best_hand = None
for cards in itertools.combinations(initial_hand._cards[:5], 4):
hand = CribbageHand(list(cards))
if not best_hand:
best_hand = hand
if hand > best_hand:
best_hand = hand
final_hand = CribbageHand(list(best_hand._cards) +
[initial_hand._cards[6]])
return final_hand