Skip to content

Commit

Permalink
Fix Three Peaks scoring
Browse files Browse the repository at this point in the history
Score is correctly updated after moving a card to the waste stack or
after winning a game. Double counting is prevented by the score_counted
variable.

see #111
  • Loading branch information
Programator2 committed Apr 22, 2019
1 parent 961634e commit 9bf8f47
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions pysollib/games/threepeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ def basicIsBlocked(self):
return True
return False

clickHandler = OpenStack.doubleclickHandler
def clickHandler(self, event):
result = OpenStack.doubleclickHandler(self, event)
if result == 1 and not self.game.score_counted:
self.game.sequence += 1
self.game.computeHandScore()
self.game.updateText()
elif self.game.score_counted:
self.game.score_counted = False
return result


# ************************************************************************
Expand Down Expand Up @@ -115,8 +123,9 @@ def createGame(self):
self.setSize(w, h)

# Extra settings
self.game_score = 52
self.game_score = 0
self.hand_score = self.sequence = 0
self.score_counted = False
self.peaks = [0] * 3

# Create rows
Expand Down Expand Up @@ -166,7 +175,7 @@ def createGame(self):

def startGame(self):
assert len(self.s.talon.cards) == self.gameinfo.ncards
self.game_score = self.game_score + self.hand_score - 52
self.game_score = self.game_score + self.hand_score
self.hand_score = -52
self.peaks = [0] * 3
self.startDealSample()
Expand All @@ -180,14 +189,16 @@ def isGameWon(self):
return False
if self.sequence:
self.hand_score = self.hand_score + len(self.s.talon.cards) * 10
self.computeHandScore()
self.score_counted = True
self.updateText()
self.sequence = 0
return True

def updateText(self):
if self.preview > 1 or not self.texts.info or not self.SCORING:
return
t = _('Score:\011This hand: ') + str(self.getHandScore())
t = _('Score:\011This hand: ') + str(self.hand_score)
t = t + _('\011This game: ') + str(self.game_score)
self.texts.info.config(text=t)

Expand All @@ -197,11 +208,8 @@ def shallHighlightMatch(self, stack1, card1, stack2, card2):
(card1.rank - 1) % 13 == card2.rank)
return False

def getHandScore(self):
# FIXME: bug #2937253
def computeHandScore(self):
score, i = self.hand_score, 1
if 0: # self.busy:
return score
# First count the empty peaks
for r in self.s.rows[:3]:
if not r.cards:
Expand All @@ -215,7 +223,6 @@ def getHandScore(self):
score = score + i * 2 ** int((self.sequence - 1) / 4)
self.hand_score = score
# print 'getHandScore: score:', score
return score

def canUndo(self):
return False
Expand Down

0 comments on commit 9bf8f47

Please sign in to comment.