summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2015-11-27 07:32:58 (GMT)
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-25 06:41:35 (GMT)
commit31eb5919990d99b3de497894564f4de0a4aad64f (patch)
treedfa01c8e961f5c96e05fd3e35ce238762dfaa4d4
parent427ace1cc7aa8dbe03e81adc7de7fe34db494c6f (diff)
Hand.__NotWon exception: use msg argument, reducing duplicate code
This moves __NotWon messages from Debug.hand to Debug.mahJongg
-rw-r--r--src/hand.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/hand.py b/src/hand.py
index f67980e..81603da 100644
--- a/src/hand.py
+++ b/src/hand.py
@@ -134,7 +134,9 @@ class Hand(object):
self.__arrange()
self.__calculate()
self.__arranged = True
- except Hand.__NotWon:
+ except Hand.__NotWon as notwon:
+ if Debug.mahJongg:
+ self.debug(fmt(notwon.message))
self.__won = False
self.__score = Score()
finally:
@@ -296,7 +298,7 @@ class Hand(object):
def debug(self, msg):
"""try to use Game.debug so we get a nice prefix"""
- self.player.game.debug(dbgIndent(self, self.prevHand) + msg)
+ self.player.game.debug(dbgIndent(self, self.prevHand) + ' ' + msg)
def __applyRules(self):
"""find out which rules apply, collect in self.usedRules"""
@@ -316,11 +318,8 @@ class Hand(object):
if self.__won:
matchingMJRules = self.__maybeMahjongg()
if not matchingMJRules:
- if Debug.hand:
- self.debug(fmt(
- 'no matching MJ Rule for {id(self)} {self}'))
self.__score = Score()
- raise Hand.__NotWon
+ raise Hand.__NotWon('no matching MJ Rule')
self.__mjRule = matchingMJRules[0]
self.usedRules.append(UsedRule(self.__mjRule))
self.usedRules.extend(self.matchingWinnerRules())
@@ -348,10 +347,7 @@ class Hand(object):
self.usedRules = exclusive
self.__score = self.__totalScore()
if self.__won and not bool(self.__maybeMahjongg()):
- if Debug.hand:
- self.debug(fmt(
- 'exclusive rule {exclusive} does not win: {self}'))
- raise Hand.__NotWon
+ raise Hand.__NotWon(fmt('exclusive rule {exclusive} does not win'))
def __setLastMeld(self):
"""sets the shortest possible last meld. This is