1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Fix for preview bottoms and undo in Cruel.

This commit is contained in:
Joe R 2022-02-06 18:20:14 -05:00
parent 41ff8873e5
commit 42b97cf1ed
3 changed files with 55 additions and 37 deletions

View file

@ -31,6 +31,7 @@ from pysollib.stack import \
AC_FoundationStack, \
AC_RowStack, \
InitialDealTalonStack, \
InvisibleStack, \
RK_RowStack, \
SS_FoundationStack, \
SS_RowStack, \
@ -55,6 +56,8 @@ class CastlesInSpain(Game):
Hint_Class = CautiousDefaultHint
Solver_Class = FreeCellSolverWrapper()
GAME_VERSION = 2
#
# game layout
#
@ -73,6 +76,7 @@ class CastlesInSpain(Game):
for r in l.s.rows:
s.rows.append(self.RowStack_Class(r.x, r.y, self))
# default
self.s.internals.append(InvisibleStack(self))
l.defaultAll()
return l
@ -218,18 +222,20 @@ class Cruel_Talon(TalonStack):
for r in rows:
for i in range(len(r.cards)):
num_cards = num_cards + 1
self.game.moveMove(1, r, self, frames=0)
assert len(self.cards) == num_cards
self.game.moveMove(1, r, self.game.s.internals[0], frames=0)
temp_cards = []
while len(self.cards) > 0:
temp = self.cards[:4]
temp_cards = temp + temp_cards
del self.cards[:4]
self.cards = temp_cards.copy()
if len(self.game.s.internals[0].cards) % 4 != 0:
self.game.moveMove(len(self.game.s.internals[0].cards) % 4,
self.game.s.internals[0], self, frames=0)
while len(self.game.s.internals[0].cards) > 0:
self.game.moveMove(4, self.game.s.internals[0], self, frames=0)
assert len(self.cards) == num_cards
if num_cards == 0: # game already finished
return 0
# redeal in packs of 4 cards
self.game.nextRoundMove(self)
n, i = num_cards, 0

View file

@ -189,35 +189,35 @@ class Images:
if progress:
progress.update(step=1)
if not USE_PIL:
# load bottoms
for i in range(self.cs.nbottoms):
name = "bottom%02d" % (i + 1)
bottom = self.__loadBottom(name, color='black')
if bottom is not None:
self._bottom_positive.append(bottom)
if progress:
progress.update(step=pstep)
# load negative bottoms
name = "bottom%02d-n" % (i + 1)
bottom = self.__loadBottom(name, color='white')
if bottom is not None:
self._bottom_negative.append(bottom)
if progress:
progress.update(step=pstep)
# load letters
for rank in range(self.cs.nletters):
name = "l%02d" % (rank + 1)
self._letter_positive.append(
self.__loadBottom(name, color='black'))
if progress:
progress.update(step=pstep)
# load negative letters
name = "l%02d-n" % (rank + 1)
self._letter_negative.append(
self.__loadBottom(name, color='white'))
if progress:
progress.update(step=pstep)
# todo - fix duplication of loading bottoms
# load bottoms
for i in range(self.cs.nbottoms):
name = "bottom%02d" % (i + 1)
bottom = self.__loadBottom(name, color='black')
if bottom is not None:
self._bottom_positive.append(bottom)
if progress:
progress.update(step=pstep)
# load negative bottoms
name = "bottom%02d-n" % (i + 1)
bottom = self.__loadBottom(name, color='white')
if bottom is not None:
self._bottom_negative.append(bottom)
if progress:
progress.update(step=pstep)
# load letters
for rank in range(self.cs.nletters):
name = "l%02d" % (rank + 1)
self._letter_positive.append(
self.__loadBottom(name, color='black'))
if progress:
progress.update(step=pstep)
# load negative letters
name = "l%02d-n" % (rank + 1)
self._letter_negative.append(
self.__loadBottom(name, color='white'))
if progress:
progress.update(step=pstep)
# shadow
if not USE_PIL:

View file

@ -289,6 +289,18 @@ def masking(image):
image = image.convert("RGBA") # make sure it has alphachannel
mask = image.copy()
# calculate median transparency value
# this will determine if the masking will have a significant
# effect on performance.
transparency = [row[3] for row in image.getdata()]
n = len(transparency)
s = sorted(transparency)
median = (s[n // 2 - 1] / 2.0 + s[n // 2] / 2.0, s[n // 2])[n % 2]
if median > 0:
return image
# important alpha must be bigger than 0
mask.putalpha(1)
mask.paste(image, (0, 0), image)