summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-13 06:46:02 (GMT)
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2016-08-24 11:47:04 (GMT)
commit8e5a993794e34097104bfb9810a162c34f2044e9 (patch)
tree1fd147f921473a0cec92b65f0f10a9bb32e38575
parent2709f4e802770af4b2182dcb67ee275e00011c0a (diff)
change most "in set" to "in sorted(set", for better comparisons between test runs (Py2/Py3)
-rw-r--r--src/deferredutil.py4
-rw-r--r--src/intelligence.py2
-rw-r--r--src/permutations.py2
-rw-r--r--src/player.py4
-rw-r--r--src/rulecode.py9
5 files changed, 11 insertions, 10 deletions
diff --git a/src/deferredutil.py b/src/deferredutil.py
index 3a5a05a..6a246c8 100644
--- a/src/deferredutil.py
+++ b/src/deferredutil.py
@@ -309,10 +309,10 @@ class DeferredBlock(StrMixin):
str(self))
if Debug.deferredBlock:
commandText = []
- for command in set(x.deferred.command for x in self.requests):
+ for command in sorted(set(x.deferred.command for x in self.requests)):
text = u'%s:' % command
answerList = []
- for answer in set(x.prettyAnswer() for x in self.requests if x.deferred.command == command):
+ for answer in sorted(set(x.prettyAnswer() for x in self.requests if x.deferred.command == command)):
answerList.append((answer, list(x for x in self.requests
if x.deferred.command == command and answer == x.prettyAnswer())))
answerList = sorted(answerList, key=lambda x: len(x[1]))
diff --git a/src/intelligence.py b/src/intelligence.py
index a39b38a..271ec42 100644
--- a/src/intelligence.py
+++ b/src/intelligence.py
@@ -212,7 +212,7 @@ class AIDefault(object):
newHand = candidates.hand - candidate.tile.concealed
winningTiles = newHand.chancesToWin()
if winningTiles:
- for winnerTile in set(winningTiles):
+ for winnerTile in sorted(set(winningTiles)):
winnerHand = newHand + winnerTile.concealed
if Debug.robotAI:
aiInstance.player.game.debug('weighCallingHand %s cand %s winnerTile %s winnerHand %s: %s' % (
diff --git a/src/permutations.py b/src/permutations.py
index 6aa27de..1f57fb4 100644
--- a/src/permutations.py
+++ b/src/permutations.py
@@ -51,7 +51,7 @@ class Permutations(object):
def _variants(self):
"""full Meld lists"""
honors = []
- for tile in set(self.tiles):
+ for tile in sorted(set(self.tiles)):
if tile.isHonor:
count = self.tiles.count(tile)
if count == 4:
diff --git a/src/player.py b/src/player.py
index 57aaddb..dbc7dc3 100644
--- a/src/player.py
+++ b/src/player.py
@@ -521,7 +521,7 @@ class PlayingPlayer(Player):
kongs = []
if self == self.game.activePlayer:
# declaring a kong
- for tileName in set([x for x in self._concealedTiles if not x.isBonus]):
+ for tileName in sorted(set([x for x in self._concealedTiles if not x.isBonus])):
if self._concealedTiles.count(tileName) == 4:
kongs.append(tileName.kong)
elif self._concealedTiles.count(tileName) == 1 and \
@@ -579,7 +579,7 @@ class PlayingPlayer(Player):
def __maySayOriginalCall(self):
"""returns True if Original Call is possible"""
- for tileName in set(self.concealedTiles):
+ for tileName in sorted(set(self.concealedTiles)):
newHand = self.hand - tileName
if newHand.callingHands:
if Debug.originalCall:
diff --git a/src/rulecode.py b/src/rulecode.py
index c06e7fd..207ec36 100644
--- a/src/rulecode.py
+++ b/src/rulecode.py
@@ -371,7 +371,7 @@ class StandardMahJongg(RuleCode):
if maxChows == 0:
return set(result)
melds = []
- for group in hand.suits & set(Tile.colors):
+ for group in sorted(hand.suits & set(Tile.colors)):
values = sorted(x.value for x in result if x.group == group)
changed = True
while (changed and len(values) > 2
@@ -599,7 +599,8 @@ class TripleKnitting(RuleCode):
rest.remove(triple[1])
rest.remove(triple[2])
while len(rest) >= 2:
- for value in set(x.value for x in rest):
+ for tile in sorted(set(rest)):
+ value = tile.value
suits = set(x.group for x in rest if x.value == value)
if len(suits) < 2:
yield tuple(melds), tuple(rest)
@@ -765,7 +766,7 @@ class Knitting(RuleCode):
def pairSuits(hand):
"""returns a lowercase string with two suit characters. If no prevalence, returns None"""
suitCounts = list(len([x for x in hand.tiles if x.lowerGroup == y])
- for y in set(Tile.colors))
+ for y in Tile.colors)
minSuit = min(suitCounts)
result = ''.join(
x for idx,
@@ -827,7 +828,7 @@ class AllPairHonors(RuleCode):
def rearrange(hand, rest):
melds = []
- for pair in set(rest) & elements.mAJORS:
+ for pair in sorted(set(rest) & elements.mAJORS):
while rest.count(pair) >= 2:
melds.append(pair.pair)
rest.remove(pair)