Skip to content

Commit

Permalink
Refactoring / code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed May 31, 2019
1 parent 9acc97b commit a073d20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pysollib/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def mSelectRandomGame(self, type='all'):
elif type == 'not played' and won+lost == 0:
games.append(gi.id)
if games:
game_id = self.app.getRandomGameId(games)
game_id = self.app.chooseRandomOutOfGames(games)
if game_id and game_id != self.game.id:
self.game.endGame()
self.game.quitGame(game_id)
Expand Down
12 changes: 8 additions & 4 deletions pysollib/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,14 @@ def getGameSaveName(self, id):
return None
return re.sub(r"[\s]", "_", latin1_normalize(n))

def getRandomGameId(self, games=None):
if games is None:
return self.miscrandom.choice(self.gdb.getGamesIdSortedById())
return self.miscrandom.choice(games)
def _choice(self, lst):
return self.miscrandom.choice(lst)

def chooseRandomOutOfGames(self, games):
return self._choice(games)

def getRandomGameId(self):
return self._choice(self.gdb.getGamesIdSortedById())

def getAllUserNames(self):
names = []
Expand Down

0 comments on commit a073d20

Please sign in to comment.