comparison sat_frontends/tools/games.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/tools/games.py@0046283a285d
children 56f94936df1e
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # SAT: a jabber client
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 """This library help manage general games (e.g. card games) and it is shared by the frontends"""
21
22 SUITS_ORDER = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] # I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red)
23 VALUES_ORDER = [str(i) for i in xrange(1, 11)] + ["valet", "cavalier", "dame", "roi"]
24
25
26 class TarotCard(object):
27 """This class is used to represent a car logically"""
28
29 def __init__(self, tuple_card):
30 """@param tuple_card: tuple (suit, value)"""
31 self.suit, self.value = tuple_card
32 self.bout = self.suit == "atout" and self.value in ["1", "21", "excuse"]
33 if self.bout or self.value == "roi":
34 self.points = 4.5
35 elif self.value == "dame":
36 self.points = 3.5
37 elif self.value == "cavalier":
38 self.points = 2.5
39 elif self.value == "valet":
40 self.points = 1.5
41 else:
42 self.points = 0.5
43
44 def get_tuple(self):
45 return (self.suit, self.value)
46
47 @staticmethod
48 def from_tuples(tuple_list):
49 result = []
50 for card_tuple in tuple_list:
51 result.append(TarotCard(card_tuple))
52 return result
53
54 def __cmp__(self, other):
55 if other is None:
56 return 1
57 if self.suit != other.suit:
58 idx1 = SUITS_ORDER.index(self.suit)
59 idx2 = SUITS_ORDER.index(other.suit)
60 return idx1.__cmp__(idx2)
61 if self.suit == 'atout':
62 if self.value == other.value == 'excuse':
63 return 0
64 if self.value == 'excuse':
65 return -1
66 if other.value == 'excuse':
67 return 1
68 return int(self.value).__cmp__(int(other.value))
69 # at this point we have the same suit which is not 'atout'
70 idx1 = VALUES_ORDER.index(self.value)
71 idx2 = VALUES_ORDER.index(other.value)
72 return idx1.__cmp__(idx2)
73
74 def __str__(self):
75 return "[%s,%s]" % (self.suit, self.value)
76
77
78 # These symbols are diplayed by Libervia next to the player's nicknames
79 SYMBOLS = {"Radiocol": [u"♬"], "Tarot": [u"♠", u"♣", u"♥", u"♦"]}