mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Merge pull request #241 from cardset/master
changes because of slow loading of bottoms
This commit is contained in:
commit
41ff8873e5
3 changed files with 69 additions and 30 deletions
|
@ -214,12 +214,20 @@ class Cruel_Talon(TalonStack):
|
||||||
num_cards = 0
|
num_cards = 0
|
||||||
assert len(self.cards) == 0
|
assert len(self.cards) == 0
|
||||||
rows = list(self.game.s.rows)[:]
|
rows = list(self.game.s.rows)[:]
|
||||||
rows.reverse()
|
# rows.reverse()
|
||||||
for r in rows:
|
for r in rows:
|
||||||
for i in range(len(r.cards)):
|
for i in range(len(r.cards)):
|
||||||
num_cards = num_cards + 1
|
num_cards = num_cards + 1
|
||||||
self.game.moveMove(1, r, self, frames=0)
|
self.game.moveMove(1, r, self, frames=0)
|
||||||
assert len(self.cards) == num_cards
|
assert len(self.cards) == num_cards
|
||||||
|
|
||||||
|
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 num_cards == 0: # game already finished
|
if num_cards == 0: # game already finished
|
||||||
return 0
|
return 0
|
||||||
# redeal in packs of 4 cards
|
# redeal in packs of 4 cards
|
||||||
|
@ -250,7 +258,9 @@ class Cruel_Talon(TalonStack):
|
||||||
|
|
||||||
class Cruel(CastlesInSpain):
|
class Cruel(CastlesInSpain):
|
||||||
Talon_Class = StackWrapper(Cruel_Talon, max_rounds=-1)
|
Talon_Class = StackWrapper(Cruel_Talon, max_rounds=-1)
|
||||||
RowStack_Class = StackWrapper(SS_RowStack, base_rank=NO_RANK)
|
RowStack_Class = StackWrapper(SS_RowStack,
|
||||||
|
max_move=1, max_accept=1, base_rank=NO_RANK)
|
||||||
|
|
||||||
# Solver_Class = FreeCellSolverWrapper(preset='cruel')
|
# Solver_Class = FreeCellSolverWrapper(preset='cruel')
|
||||||
Solver_Class = None
|
Solver_Class = None
|
||||||
|
|
||||||
|
|
|
@ -188,34 +188,37 @@ class Images:
|
||||||
cs_dir=self.cs.dir, fname=name))
|
cs_dir=self.cs.dir, fname=name))
|
||||||
if progress:
|
if progress:
|
||||||
progress.update(step=1)
|
progress.update(step=1)
|
||||||
# load bottoms
|
|
||||||
for i in range(self.cs.nbottoms):
|
if not USE_PIL:
|
||||||
name = "bottom%02d" % (i + 1)
|
# load bottoms
|
||||||
bottom = self.__loadBottom(name, color='black')
|
for i in range(self.cs.nbottoms):
|
||||||
if bottom is not None:
|
name = "bottom%02d" % (i + 1)
|
||||||
self._bottom_positive.append(bottom)
|
bottom = self.__loadBottom(name, color='black')
|
||||||
if progress:
|
if bottom is not None:
|
||||||
progress.update(step=pstep)
|
self._bottom_positive.append(bottom)
|
||||||
# load negative bottoms
|
if progress:
|
||||||
name = "bottom%02d-n" % (i + 1)
|
progress.update(step=pstep)
|
||||||
bottom = self.__loadBottom(name, color='white')
|
# load negative bottoms
|
||||||
if bottom is not None:
|
name = "bottom%02d-n" % (i + 1)
|
||||||
self._bottom_negative.append(bottom)
|
bottom = self.__loadBottom(name, color='white')
|
||||||
if progress:
|
if bottom is not None:
|
||||||
progress.update(step=pstep)
|
self._bottom_negative.append(bottom)
|
||||||
# load letters
|
if progress:
|
||||||
for rank in range(self.cs.nletters):
|
progress.update(step=pstep)
|
||||||
name = "l%02d" % (rank + 1)
|
# load letters
|
||||||
self._letter_positive.append(
|
for rank in range(self.cs.nletters):
|
||||||
self.__loadBottom(name, color='black'))
|
name = "l%02d" % (rank + 1)
|
||||||
if progress:
|
self._letter_positive.append(
|
||||||
progress.update(step=pstep)
|
self.__loadBottom(name, color='black'))
|
||||||
# load negative letters
|
if progress:
|
||||||
name = "l%02d-n" % (rank + 1)
|
progress.update(step=pstep)
|
||||||
self._letter_negative.append(
|
# load negative letters
|
||||||
self.__loadBottom(name, color='white'))
|
name = "l%02d-n" % (rank + 1)
|
||||||
if progress:
|
self._letter_negative.append(
|
||||||
progress.update(step=pstep)
|
self.__loadBottom(name, color='white'))
|
||||||
|
if progress:
|
||||||
|
progress.update(step=pstep)
|
||||||
|
|
||||||
# shadow
|
# shadow
|
||||||
if not USE_PIL:
|
if not USE_PIL:
|
||||||
for i in range(self.cs.nshadows):
|
for i in range(self.cs.nshadows):
|
||||||
|
|
|
@ -248,8 +248,13 @@ def after_cancel(t):
|
||||||
if Image:
|
if Image:
|
||||||
class PIL_Image(ImageTk.PhotoImage):
|
class PIL_Image(ImageTk.PhotoImage):
|
||||||
def __init__(self, file=None, image=None, pil_image_orig=None):
|
def __init__(self, file=None, image=None, pil_image_orig=None):
|
||||||
|
|
||||||
if file:
|
if file:
|
||||||
image = Image.open(file).convert('RGBA')
|
image = Image.open(file).convert('RGBA')
|
||||||
|
|
||||||
|
# eliminates the 0 in alphachannel
|
||||||
|
image = masking(image)
|
||||||
|
|
||||||
ImageTk.PhotoImage.__init__(self, image)
|
ImageTk.PhotoImage.__init__(self, image)
|
||||||
self._pil_image = image
|
self._pil_image = image
|
||||||
if pil_image_orig:
|
if pil_image_orig:
|
||||||
|
@ -266,12 +271,32 @@ if Image:
|
||||||
return im
|
return im
|
||||||
|
|
||||||
def resize(self, xf, yf):
|
def resize(self, xf, yf):
|
||||||
|
|
||||||
w, h = self._pil_image_orig.size
|
w, h = self._pil_image_orig.size
|
||||||
w0, h0 = int(w*xf), int(h*yf)
|
w0, h0 = int(w*xf), int(h*yf)
|
||||||
im = self._pil_image_orig.resize((w0, h0), Image.ANTIALIAS)
|
im = self._pil_image_orig.resize((w0, h0), Image.ANTIALIAS)
|
||||||
|
|
||||||
|
im = masking(im)
|
||||||
|
|
||||||
return PIL_Image(image=im, pil_image_orig=self._pil_image_orig)
|
return PIL_Image(image=im, pil_image_orig=self._pil_image_orig)
|
||||||
|
|
||||||
|
|
||||||
|
def masking(image):
|
||||||
|
|
||||||
|
# eliminates the 0 in alphachannel
|
||||||
|
# because PhotoImage and Rezising
|
||||||
|
# have problems with it
|
||||||
|
|
||||||
|
image = image.convert("RGBA") # make sure it has alphachannel
|
||||||
|
mask = image.copy()
|
||||||
|
# important alpha must be bigger than 0
|
||||||
|
mask.putalpha(1)
|
||||||
|
mask.paste(image, (0, 0), image)
|
||||||
|
image = mask.copy()
|
||||||
|
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
def makeImage(file=None, data=None, dither=None, alpha=None):
|
def makeImage(file=None, data=None, dither=None, alpha=None):
|
||||||
kw = {}
|
kw = {}
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -401,6 +426,7 @@ def createBottom(maskimage, color='white', backfile=None):
|
||||||
return None
|
return None
|
||||||
maskimage = maskimage._pil_image
|
maskimage = maskimage._pil_image
|
||||||
out = _createBottomImage(maskimage, color, backfile)
|
out = _createBottomImage(maskimage, color, backfile)
|
||||||
|
|
||||||
return PIL_Image(image=out)
|
return PIL_Image(image=out)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue