Commit f9285de1 authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald
Browse files

make sure all MJ rule classes have method computeLastMelds

parent efbd5e75
......@@ -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
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment