summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2015-11-24 12:01:36 (GMT)
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-24 11:47:07 (GMT)
commitf9285de1ab7c01a66e0474b1f87aa699dc5cdcc1 (patch)
tree4b3eb34578f1ef6a07bda5be3dd81b731cb1dba5
parentefbd5e75c4889bc1933f4fcbc01759876e303adc (diff)
make sure all MJ rule classes have method computeLastMelds
-rw-r--r--src/hand.py2
-rw-r--r--src/rulecode.py18
2 files changed, 13 insertions, 7 deletions
diff --git a/src/hand.py b/src/hand.py
index 8147023..4cf745c 100644
--- a/src/hand.py
+++ b/src/hand.py
@@ -373,7 +373,7 @@ class Hand(object):
not yet the final choice, see __applyBestLastMeld"""
self.__lastMeld = None
if self.lastTile and self.__won:
- if self.mjRule and hasattr(self.mjRule, 'computeLastMelds'):
+ if self.mjRule:
self.__lastMelds = self.mjRule.computeLastMelds(self)
if self.__lastMelds:
# syncHandBoard may return nothing
diff --git a/src/rulecode.py b/src/rulecode.py
index 172e5eb..c8f31d0 100644
--- a/src/rulecode.py
+++ b/src/rulecode.py
@@ -50,6 +50,11 @@ class RuleCode(object):
# pylint: disable=no-self-argument, no-self-use, no-value-for-parameter, no-member
# pylint: disable=too-many-function-args, unused-argument, arguments-differ
+class MJRule(RuleCode):
+
+ def computeLastMelds(hand):
+ """returns all possible last melds"""
+
class DragonPungKong(RuleCode):
@@ -286,7 +291,8 @@ class AllTerminals(RuleCode):
return all(x.isTerminal for x in hand.tiles)
-class StandardMahJongg(RuleCode):
+class StandardMahJongg(MJRule):
+
cache = ('appliesToHand',)
def computeLastMelds(hand):
@@ -490,7 +496,7 @@ class SquirmingSnake(StandardMahJongg):
return set()
-class WrigglingSnake(RuleCode):
+class WrigglingSnake(MJRule):
def shouldTry(hand, maxMissing=3):
if hand.declaredMelds:
@@ -561,7 +567,7 @@ class CallingHand(RuleCode):
return False
-class TripleKnitting(RuleCode):
+class TripleKnitting(MJRule):
def computeLastMelds(cls, hand):
"""returns all possible last melds"""
@@ -667,7 +673,7 @@ class TripleKnitting(RuleCode):
return tuple(result), tuple(tilesS + tilesB + tilesC)
-class Knitting(RuleCode):
+class Knitting(MJRule):
def computeLastMelds(cls, hand):
"""returns all possible last melds"""
@@ -775,7 +781,7 @@ class Knitting(RuleCode):
return result
-class AllPairHonors(RuleCode):
+class AllPairHonors(MJRule):
def computeLastMelds(hand):
return [hand.lastTile.pair]
@@ -1084,7 +1090,7 @@ class GatesOfHeaven(StandardMahJongg):
yield tuple(melds), tuple(rest)
-class ThirteenOrphans(RuleCode):
+class ThirteenOrphans(MJRule):
def computeLastMelds(hand):
meldSize = hand.tilesInHand.count(hand.lastTile)