mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
* improved initial dealing of custom games
git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@172 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
parent
8a2616449e
commit
67bd2b8cd8
4 changed files with 47 additions and 38 deletions
|
@ -3,7 +3,7 @@
|
||||||
There is no need to compile anything since the whole program is just
|
There is no need to compile anything since the whole program is just
|
||||||
a Python script. Just run it, and that's all.
|
a Python script. Just run it, and that's all.
|
||||||
<p>
|
<p>
|
||||||
PySol requires Python 1.5.2 and Tcl/Tk 8.0.5 or better. Both packages are
|
PySol requires Python 2.3 and Tcl/Tk 8.3 or better. Both packages are
|
||||||
freely available for Unix, Windows and Macintosh platforms.
|
freely available for Unix, Windows and Macintosh platforms.
|
||||||
<p>
|
<p>
|
||||||
PySol is free <i>Open Source</i> software distributed under the terms of the
|
PySol is free <i>Open Source</i> software distributed under the terms of the
|
||||||
|
|
|
@ -101,6 +101,7 @@ class Options:
|
||||||
('animations', 'int'),
|
('animations', 'int'),
|
||||||
('redeal_animation', 'bool'),
|
('redeal_animation', 'bool'),
|
||||||
('win_animation', 'bool'),
|
('win_animation', 'bool'),
|
||||||
|
('flip_animation', 'bool'),
|
||||||
('shadow', 'bool'),
|
('shadow', 'bool'),
|
||||||
('shade', 'bool'),
|
('shade', 'bool'),
|
||||||
('shrink_face_down', 'bool'),
|
('shrink_face_down', 'bool'),
|
||||||
|
@ -175,6 +176,7 @@ class Options:
|
||||||
self.animations = 2 # default to Fast
|
self.animations = 2 # default to Fast
|
||||||
self.redeal_animation = True
|
self.redeal_animation = True
|
||||||
self.win_animation = True
|
self.win_animation = True
|
||||||
|
self.flip_animation = True
|
||||||
self.shadow = True
|
self.shadow = True
|
||||||
self.shade = True
|
self.shade = True
|
||||||
self.shrink_face_down = True
|
self.shrink_face_down = True
|
||||||
|
@ -1464,11 +1466,13 @@ Please select a %s type %s.
|
||||||
opt = unpickle(self.fn.opt)
|
opt = unpickle(self.fn.opt)
|
||||||
if opt:
|
if opt:
|
||||||
self.opt.__dict__.update(opt.__dict__)
|
self.opt.__dict__.update(opt.__dict__)
|
||||||
os.remove(self.fn.opt)
|
try:
|
||||||
|
os.remove(self.fn.opt)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if not os.path.exists(self.fn.opt_cfg):
|
if os.path.exists(self.fn.opt_cfg):
|
||||||
return
|
self.opt.load(self.fn.opt_cfg)
|
||||||
self.opt.load(self.fn.opt_cfg)
|
|
||||||
self.opt.setConstants()
|
self.opt.setConstants()
|
||||||
|
|
||||||
def loadStatistics(self):
|
def loadStatistics(self):
|
||||||
|
|
|
@ -238,34 +238,39 @@ class CustomGame(Game):
|
||||||
|
|
||||||
def startGame(self):
|
def startGame(self):
|
||||||
|
|
||||||
|
min_cards = max(len(self.s.rows), 8)
|
||||||
|
anim_frames = -1
|
||||||
|
|
||||||
def deal(rows, flip, frames, max_cards):
|
def deal(rows, flip, frames, max_cards):
|
||||||
|
if frames == 0:
|
||||||
|
if len(self.s.talon.cards) <= min_cards or \
|
||||||
|
max_cards <= min_cards:
|
||||||
|
frames = anim_frames
|
||||||
|
self.startDealSample()
|
||||||
if max_cards <= 0:
|
if max_cards <= 0:
|
||||||
return 0
|
return frames, 0
|
||||||
return self.s.talon.dealRowAvail(rows=rows, flip=flip,
|
max_cards -= self.s.talon.dealRowAvail(rows=rows, flip=flip,
|
||||||
frames=frames)
|
frames=frames)
|
||||||
|
return frames, max_cards
|
||||||
|
|
||||||
|
|
||||||
frames = 0
|
frames = 0
|
||||||
s = get_settings(self.SETTINGS)
|
s = get_settings(self.SETTINGS)
|
||||||
if isinstance(self.s.talon, InitialDealTalonStack):
|
if isinstance(self.s.talon, InitialDealTalonStack):
|
||||||
max_cards = 52 * s['decks'] - len(self.s.rows)
|
max_cards = 52 * s['decks']
|
||||||
else:
|
else:
|
||||||
max_cards = s['deal_max_cards'] - len(self.s.rows)
|
max_cards = s['deal_max_cards']
|
||||||
if self.s.waste:
|
|
||||||
max_cards -= 1
|
|
||||||
anim_frames = -1
|
|
||||||
|
|
||||||
# deal to foundations
|
# deal to foundations
|
||||||
if s['deal_found']:
|
if s['deal_found']:
|
||||||
max_cards -= deal(self.s.foundations, True, frames, max_cards)
|
frames, max_cards = deal(self.s.foundations,
|
||||||
|
True, frames, max_cards)
|
||||||
|
|
||||||
# deal to reserves
|
# deal to reserves
|
||||||
n = s['deal_to_reserves']
|
n = s['deal_to_reserves']
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
max_cards -= deal(self.s.reserves[:max_cards],
|
frames, max_cards = deal(self.s.reserves[:max_cards],
|
||||||
True, frames, max_cards)
|
True, frames, max_cards)
|
||||||
if frames == 0 and len(self.s.talon.cards) < 16:
|
|
||||||
frames = anim_frames
|
|
||||||
self.startDealSample()
|
|
||||||
|
|
||||||
# deal to rows
|
# deal to rows
|
||||||
face_down = s['deal_face_down']
|
face_down = s['deal_face_down']
|
||||||
|
@ -273,37 +278,35 @@ class CustomGame(Game):
|
||||||
if s['deal_type'] == 'triangle':
|
if s['deal_type'] == 'triangle':
|
||||||
# triangle
|
# triangle
|
||||||
for i in range(1, len(self.s.rows)):
|
for i in range(1, len(self.s.rows)):
|
||||||
|
if max_rows <= 1:
|
||||||
|
break
|
||||||
flip = (face_down <= 0)
|
flip = (face_down <= 0)
|
||||||
max_cards -= deal(self.s.rows[i:i+max_cards],
|
mc = max_cards - len(self.s.rows)
|
||||||
flip, frames, max_cards)
|
frames, max_cards = deal(self.s.rows[i:i+mc],
|
||||||
|
flip, frames, max_cards)
|
||||||
face_down -= 1
|
face_down -= 1
|
||||||
max_rows -= 1
|
max_rows -= 1
|
||||||
if max_rows == 1:
|
|
||||||
break
|
|
||||||
if frames == 0 and len(self.s.talon.cards) < 16:
|
|
||||||
frames = anim_frames
|
|
||||||
self.startDealSample()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# rectangle
|
# rectangle
|
||||||
for i in range(max_rows-1):
|
for i in range(max_rows-1):
|
||||||
flip = (face_down <= 0)
|
flip = (face_down <= 0)
|
||||||
max_cards -= deal(self.s.rows[:max_cards],
|
mc = max_cards - len(self.s.rows)
|
||||||
flip, frames, max_cards)
|
frames, max_cards = deal(self.s.rows[:mc],
|
||||||
|
flip, frames, max_cards)
|
||||||
face_down -= 1
|
face_down -= 1
|
||||||
if frames == 0 and len(self.s.talon.cards) < 16:
|
|
||||||
frames = anim_frames
|
|
||||||
self.startDealSample()
|
|
||||||
if frames == 0:
|
|
||||||
self.startDealSample()
|
|
||||||
if s['deal_face_down'] + s['deal_face_up'] > 0:
|
|
||||||
self.s.talon.dealRowAvail(frames=anim_frames)
|
|
||||||
if isinstance(self.s.talon, InitialDealTalonStack):
|
if isinstance(self.s.talon, InitialDealTalonStack):
|
||||||
while self.s.talon.cards:
|
while self.s.talon.cards:
|
||||||
self.s.talon.dealRowAvail(frames=anim_frames)
|
frames, max_cards = deal(self.s.rows, True, frames, max_cards)
|
||||||
|
else:
|
||||||
|
if max_rows > 0:
|
||||||
|
deal(self.s.rows, True, frames, len(self.s.rows))
|
||||||
|
|
||||||
# deal to waste
|
# deal to waste
|
||||||
if self.s.waste:
|
if self.s.waste:
|
||||||
|
if frames == 0:
|
||||||
|
self.startDealSample()
|
||||||
self.s.talon.dealCards()
|
self.s.talon.dealCards()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1245,11 +1245,13 @@ class Game:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def animatedFlip(self, stack):
|
def animatedFlip(self, stack):
|
||||||
##return False
|
if not self.app.opt.flip_animation:
|
||||||
|
return False
|
||||||
return self.doAnimatedFlipAndMove(stack)
|
return self.doAnimatedFlipAndMove(stack)
|
||||||
|
|
||||||
def animatedFlipAndMove(self, from_stack, to_stack, frames=-1):
|
def animatedFlipAndMove(self, from_stack, to_stack, frames=-1):
|
||||||
##return False
|
if not self.app.opt.flip_animation:
|
||||||
|
return False
|
||||||
return self.doAnimatedFlipAndMove(from_stack, to_stack, frames)
|
return self.doAnimatedFlipAndMove(from_stack, to_stack, frames)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue