Skip to content

Commit

Permalink
Enhancements to Eighteens game.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Feb 21, 2024
1 parent be12039 commit fe5013b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pysollib/games/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,20 +848,35 @@ def acceptsCards(self, from_stack, cards):

def clickHandler(self, event):
game = self.game
if self.cards and self.cards[0].rank == 0:
if not self.cards:
return False
if self.cards[0].rank == 0:
game.playSample("autodrop", priority=20)
self.playMoveMove(1, game.s.foundations[0], sound=False)
self.fillStack()
return True
elif self.game.s.reserves[0].acceptsCards(self, self.cards):
return self.playMoveMove(1, self.game.s.reserves[0])

return False


class Eighteens_Reserve(ReserveStack):
def acceptsCards(self, from_stack, cards):
sum = 0
numcards = 0
if len(self.cards) > 3:
return False
for c in self.cards:
if c.rank == cards[0].rank:
if ((c.rank > 9 and cards[0].rank > 9)
or (c.rank == cards[0].rank)):
return False
if cards[0].rank <= 9 and c.rank <= 9:
sum += c.rank + 1
numcards += 1
newsum = sum + cards[0].rank + 1
if newsum > 18 or (numcards == 2 and newsum < 18):
return False
return True

def updateText(self):
Expand Down Expand Up @@ -908,7 +923,8 @@ def fillStack(self, stack=None):
reserve_sum += c.rank + 1
else:
facecards += 1
if reserve_sum == 18 and facecards == 1:
if (reserve_sum == 18 and facecards == 1
and len(reserve.cards) == 4):
self._dropReserve()
self.leaveState(old_state)

Expand Down

0 comments on commit fe5013b

Please sign in to comment.