forked from kongo2002/pyskat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyskatrc.py
195 lines (177 loc) · 5.6 KB
/
pyskatrc.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python
# This file is part of pyskat.
#
# Copyright (C) 2009, 2010 by Gregor Uhlenheuer
#
# pyskat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyskat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyskat. If not, see <http://www.gnu.org/licenses/>.
KARO = 40
HERZ = 60
PIK = 80
KREUZ = 100
BUBE = 11
DAME = 12
KOENIG = 13
ASS = 1
SUITS = { PIK: 'Pik',
KREUZ: 'Kreuz',
KARO: 'Karo',
HERZ: 'Herz' }
RANKS = { ASS: 'Ass',
7: 'Sieben',
8: 'Acht',
9: 'Neun',
10: 'Zehn',
BUBE: 'Bube',
DAME: 'Dame',
KOENIG: 'Koenig' }
POINTS = { ASS: 11,
7: 0,
8: 0,
9: 0,
10: 10,
BUBE: 2,
DAME: 3,
KOENIG: 4 }
REIZEN = { PIK: 11,
KREUZ: 12,
KARO: 9,
HERZ: 10 }
S_REIZEN = 1
S_SKAT = 2
S_SPIELEN = 3
S_WARTEN = 4
class Card:
def __init__(self, id):
self.suit = id - id % 20
self.rank = id % 20
self.point = POINTS[self.rank]
self.owner = None
def __repr__(self):
return str(self)
def __str__(self):
return "%s %s (%d)" % (SUITS[self.suit], RANKS[self.rank], self.point)
def __cmp__(self, other):
# jack
if self.rank == BUBE and other.rank != BUBE:
return 1
elif self.rank == BUBE and other.rank == BUBE:
if self.suit > other.suit:
return 1
elif self.suit == other.suit:
return 0
else:
return -1
# no jack
else:
if other.rank == BUBE:
return -1
# ace
if self.rank == ASS and other.rank != ASS:
return 1
elif (self.rank == ASS and other.rank == ASS and
self.suit == other.suit):
return 0
elif other.rank == ASS:
return -1
# ten
elif self.rank == 10 and other.rank != 10:
return 1
elif (self.rank == 10 and other.rank == 10 and
self.suit == other.suit):
return 0
elif other.rank == 10:
return -1
# others
elif self.rank > other.rank:
return 1
elif (self.rank == other.rank and
self.suit == other.suit):
return 0
else:
return -1
def own(self, player):
self.owner = player
def isGreater(self, other, trumpf, null=False):
# NULLSPIEL (RAMSCH)
if null:
# nicht bedient
if other.suit != self.suit:
return True
# ass
elif self.rank == ASS and other.rank != ASS:
return True
elif other.rank == ASS and self.rank != ASS:
return False
elif self.rank > other.rank:
return True
else:
return False
# GRANDSPIEL
elif not trumpf:
# bube
if self.rank == BUBE:
if other.rank != BUBE:
return True
elif self.suit > other.suit:
return True
else:
return False
# kein bube
else:
if other.rank == BUBE:
return False
# nicht bedient
elif other.suit != self.suit:
return True
elif self > other:
return True
else:
return False
# NORMALSPIEL
else:
# trumpf ueber fehl
if ((self.suit == trumpf or self.rank == BUBE) and
other.suit != trumpf and
other.rank != BUBE):
return True
# beide trumpf
elif ((self.suit == trumpf or self.rank == BUBE) and
(other.suit == trumpf or other.rank == BUBE)):
# bube ueber normal
if self.rank == BUBE and other.rank != BUBE:
return True
# besserer bube
elif ((self.rank == BUBE and other.rank == BUBE) and
self.suit > other.suit):
return True
# besserer trumpf
elif ((self.rank != BUBE and other.rank != BUBE) and
self > other):
return True
else:
return False
# beide fehl
elif (self.suit != trumpf and self.rank != BUBE and
other.suit != trumpf and other.rank != BUBE):
# nicht bedient
if other.suit != self.suit:
return True
# hoeherer fehl
elif self > other:
return True
else:
return False
else:
return False
# vim:et sw=4 sts=4 tw=80: