forked from Alex-Addy/Euchre-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_globals.py
126 lines (105 loc) · 3.09 KB
/
my_globals.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# coding:utf-8
import codecs
if True: # black characters
heart = u"\u2665"
spade = u"\u2660"
diamond = u"\u2666"
club = u"\u2663"
else: # white characters
heart = u"\u2661"
spade = u"\u2664"
diamond = u"\u2662"
club = u"\u2667"
class Logger:
def __init__(self, logging_file):
self.the_log = codecs.open(logging_file, encoding='utf-8', mode='w')
def log(self, info):
self.the_log.write(info.replace('\n', '\r\n'))
self.the_log.write('\r\n')
out = Logger("log.txt")
class Info:
def __init__(self):
# trick level
self.dealer = None # player
self.lead = None # suit
self.center = {} # array of {card:player} for cards in center of table
# round level
self.trump = None # suit
self.caller = None # player
self.tricksA = 0 # tricks gotten
self.tricksB = 0
# game level
self.scoreA = 0 # total score
self.scoreB = 0
def resetTrick(self):
self.lead = None
self.center = {}
def resetRound(self):
self.trump = None
self.caller = None
self.tricksA = 0
self.tricksB = 0
game = Info()
class Card(object):
def __init__(self, suit, num):
self.suit = suit
self.num = num
def __str__(self):
if self.num > 10:
return ["Jack", "Queen", "King", "Ace"][self.num - 11] + "|" + self.suit
else:
return str(self.num) + "|" + self.suit
def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, self.__dict__)
# a list of all possible cards, done as a tuple so that it cannot be accidently changed at runtime
allcards = tuple([Card(s, c) for s in (diamond, spade, club, heart) for c in (14, 13, 12, 11, 10, 9)])
def offSuit(trump_suit):
"""
Takes a suit and returns what the off hand suit would be.
"""
if trump_suit == heart:
return diamond
elif trump_suit == diamond:
return heart
elif trump_suit == spade:
return club
else:
return spade
def query_yes_no(question, default="yes"):
"""
Ask a yes/no question via raw_input() and return their answer.
source: http://stackoverflow.com/a/3041990
"""
valid = {"yes":True, "y":True, "ye":True,
"no":False, "n":False}
if default == None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
print (question + prompt)
choice = raw_input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
print "Please respond with 'yes' or 'no' (or 'y' or 'n').\n"
def curCardVal(card):
# This might need to become a global function
if card.suit == game.trump:
if card.num == 11: # card is right bower
return card.num + 15
else:
return card.num + 10
elif card.num == 11 and card.suit == offSuit(game.trump):
# card is left bower
return card.num + 14
elif card.suit == game.lead:
return card.num
else:
return 0