diff src/tools/games.py @ 590:56531f9e9ac7

Fix pep8 support in src/tools.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
line wrap: on
line diff
--- a/src/tools/games.py	Fri Jan 18 17:55:35 2013 +0100
+++ b/src/tools/games.py	Fri Jan 18 17:55:35 2013 +0100
@@ -20,12 +20,11 @@
 """
 
 from logging import debug, info, error
-
 """This library help manage general games (e.g. card games)"""
 
+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)
+VALUES_ORDER = [str(i) for i in xrange(1, 11)] + ["valet", "cavalier", "dame", "roi"]
 
-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)
-values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"]
 
 class TarotCard(object):
     """This class is used to represent a car logically"""
@@ -34,7 +33,7 @@
     def __init__(self, tuple_card):
         """@param tuple_card: tuple (suit, value)"""
         self.suit, self.value = tuple_card
-        self.bout = True if self.suit=="atout" and self.value in ["1","21","excuse"] else False
+        self.bout = self.suit == "atout" and self.value in ["1", "21", "excuse"]
         if self.bout or self.value == "roi":
             self.points = 4.5
         elif self.value == "dame":
@@ -47,7 +46,7 @@
             self.points = 0.5
 
     def get_tuple(self):
-        return (self.suit,self.value)
+        return (self.suit, self.value)
 
     @staticmethod
     def from_tuples(tuple_list):
@@ -57,11 +56,11 @@
         return result
 
     def __cmp__(self, other):
-        if other == None:
+        if other is None:
             return 1
         if self.suit != other.suit:
-            idx1 = suits_order.index(self.suit)
-            idx2 = suits_order.index(other.suit)
+            idx1 = SUITS_ORDER.index(self.suit)
+            idx2 = SUITS_ORDER.index(other.suit)
             return idx1.__cmp__(idx2)
         if self.suit == 'atout':
             if self.value == other.value == 'excuse':
@@ -71,9 +70,9 @@
             if other.value == 'excuse':
                 return 1
             return int(self.value).__cmp__(int(other.value))
-        #at this point we have the same suit which is not 'atout'
-        idx1 = values_order.index(self.value)
-        idx2 = values_order.index(other.value)
+        # at this point we have the same suit which is not 'atout'
+        idx1 = VALUES_ORDER.index(self.value)
+        idx2 = VALUES_ORDER.index(other.value)
         return idx1.__cmp__(idx2)
 
     def __str__(self):