summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2015-11-24 15:33:47 (GMT)
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-25 06:41:32 (GMT)
commit56b71b6ed55a3e89efea4bf2c6727d5c9e7ae760 (patch)
tree3efcc5c234d05bb81d4dd221d5752e0ddbf8fa38
parented8540571c267f0b034bf8b8384463822f85b238 (diff)
Hand.announcements now is a set
-rw-r--r--src/hand.py40
-rw-r--r--src/player.py2
-rw-r--r--src/rulecode.py4
-rw-r--r--src/scoring.py6
4 files changed, 23 insertions, 29 deletions
diff --git a/src/hand.py b/src/hand.py
index 9195933..24f1e0c 100644
--- a/src/hand.py
+++ b/src/hand.py
@@ -112,7 +112,7 @@ class Hand(object):
self.ruleCache = {}
self.__lastTile = None
self.__lastSource = None
- self.__announcements = ''
+ self.__announcements = set()
self.__lastMeld = 0
self.__lastMelds = MeldList()
self.tiles = None
@@ -154,7 +154,7 @@ class Hand(object):
if len(part) > 1:
self.__lastSource = part[1]
if len(part) > 2:
- self.__announcements = part[2]
+ self.__announcements = set(part[2])
elif partId == 'L':
if len(part[1:]) > 8:
raise Exception(
@@ -424,7 +424,7 @@ class Hand(object):
parts.append('R' + ''.join(str(x) for x in sorted(
self.tilesInHand + [addTile])))
if self.announcements:
- parts.append('m.' + self.announcements)
+ parts.append('m.' + ''.join(sorted(self.announcements)))
parts.append('L' + addTile)
return Hand(self.player, ' '.join(parts).strip(), prevHand=self)
@@ -459,28 +459,22 @@ class Hand(object):
if len(meld) < 3:
declaredMelds.remove(meld)
tilesInHand.extend(meld.concealed)
- newParts = []
- for idx, part in enumerate(self.mjStr.split()):
- oldPart = part
- if part[0] == 'm':
- part = part[:2] + part[2:].replace('k','')
- # TODO: remove debug output again
- if part != oldPart:
- self.debug('Hand.__sub__ changes m part from {} to {}'.format(oldPart,part))
- if len(part)<3:
- # no announcement left
- continue
- elif part[0] == 'L':
- if (self.lastTile.isExposed
- and self.lastTile.concealed in tilesInHand):
- part = 'L' + self.lastTile.concealed
- else:
- continue
- newParts.append(part)
- mjStr = ' '.join(newParts)
+ # if we robbed a kong, remove that announcement
+ mjParts = []
+ announcements = self.announcements - set('k')
+ if announcements:
+ mjParts.append('m.' + ''.join(announcements))
+ if (self.lastTile and self.lastTile.isExposed
+ and self.lastTile.concealed in tilesInHand):
+ # undo exposing lastMeld
+# msgx = '{}-{}: new L:{}'.format(self, subtractTile, self.lastTile.concealed)
+# self.debug(msgx)
+# self.player.game.addCsvTag('sublasttile')
+ mjParts.append('L' + self.lastTile.concealed)
+ mjPart = ' '.join(mjParts)
rest = 'R' + str(tilesInHand)
newString = ' '.join(str(x) for x in (
- declaredMelds, rest, boni, mjStr))
+ declaredMelds, rest, boni, mjPart))
return Hand(self.player, newString, prevHand=self)
def manualRuleMayApply(self, rule):
diff --git a/src/player.py b/src/player.py
index 07fb85a..bc20c3e 100644
--- a/src/player.py
+++ b/src/player.py
@@ -380,7 +380,7 @@ class Player(StrMixin):
def mjString(self):
"""compile hand info into a string as needed by the scoring engine"""
announcements = 'a' if self.originalCall else ''
- return ''.join(['m', self.lastSource, announcements])
+ return ''.join(['m', self.lastSource, ''.join(announcements)])
def makeTileKnown(self, tileName):
"""used when somebody else discards a tile"""
diff --git a/src/rulecode.py b/src/rulecode.py
index c8f31d0..6735a66 100644
--- a/src/rulecode.py
+++ b/src/rulecode.py
@@ -1263,7 +1263,7 @@ class BlessingOfHeaven(RuleCode):
"""for scoring game"""
return (hand.ownWind == Tile.east
and hand.lastSource and hand.lastSource in 'wd'
- and not set(hand.announcements) - {'a'})
+ and not hand.announcements - {'a'})
class BlessingOfEarth(RuleCode):
@@ -1275,7 +1275,7 @@ class BlessingOfEarth(RuleCode):
"""for scoring game"""
return (hand.ownWind != Tile.east
and hand.lastSource and hand.lastSource in 'wd'
- and not set(hand.announcements) - {'a'})
+ and not hand.announcements - {'a'})
class LongHand(RuleCode):
diff --git a/src/scoring.py b/src/scoring.py
index 56a1cc6..171056b 100644
--- a/src/scoring.py
+++ b/src/scoring.py
@@ -401,7 +401,7 @@ class ScoringPlayer(VisiblePlayer, Player):
lastSource = 'w'
else:
lastSource = 'd'
- announcements = ''
+ announcements = set()
rules = [x.rule for x in self.manualRuleBoxes if x.isChecked()]
for rule in rules:
options = rule.options
@@ -410,8 +410,8 @@ class ScoringPlayer(VisiblePlayer, Player):
# this defines precedences for source of last tile
lastSource = options['lastsource']
if 'announcements' in options:
- announcements += options['announcements']
- return ''.join(['m', lastSource, announcements])
+ announcements |= set(options['announcements'])
+ return ''.join(['m', lastSource, ''.join(sorted(announcements))])
def __lastString(self):
"""compile hand info into a string as needed by the scoring engine"""