def dealRow(self, rows=None, flip=1, reverse=0, frames=-1, sound=False): if rows is not None: return DealRowTalonStack.dealRowAvail(self, rows=rows, flip=flip, reverse=reverse, frames=frames, sound=sound) rows = self.game.s.rows for r in rows[:10]: if not r.cards: return self._fillRow(frames=frames, sound=sound) column_ncards = [] for i in range(10): column = [r for r in rows[i::10] if r.cards] column_ncards.append(len(column)) max_col = max(column_ncards) if max(column_ncards) != min(column_ncards): return self._fillRow(frames=frames, sound=sound) r = rows[max_col * 10:max_col * 10 + 10] return DealRowTalonStack.dealRowAvail(self, rows=r, flip=flip, reverse=reverse, frames=frames, sound=sound)
def _fillRow(self, frames=-1, sound=False): rows = self.game.s.rows column_ncards = [] for i in range(10): column = [r for r in rows[i::10] if r.cards] column_ncards.append(len(column)) max_col = max(column_ncards) max_col = max(max_col, 1) n = 0 rr = self.game.s.rows[:max_col * 10] while True: filled = False for i in range(10): prev_s = None for s in rr[i::10]: if not self.cards: filled = False break if s.cards: if prev_s: DealRowTalonStack.dealRow(self, rows=[prev_s], frames=frames, sound=sound) n += 1 filled = True break prev_s = s if not filled: break while True: filled = False for i in range(10): for s in rr[i::10]: if not self.cards: filled = False break if not s.cards: DealRowTalonStack.dealRow(self, rows=[s], frames=frames, sound=sound) n += 1 filled = True break if not filled: break return n
def createGame(self): l, s = Layout(self), self.s self.setSize(l.XM+9.5*l.XS, l.YM+4*l.YS) x, y = l.XM+l.XS, l.YM for i in range(8): s.foundations.append(SS_FoundationStack(x, y, self, suit=i % 4, base_rank=JACK, dir=-1, max_cards=11)) x += l.XS x, y = l.XM+l.XS, l.YM+l.YS for i in range(8): s.foundations.append(Adela_Foundation(x, y, self, suit=i % 4, base_rank=QUEEN, max_cards=1)) x += l.XS x, y = l.XM+l.XS, l.YM+2*l.YS for i in range(8): s.foundations.append(Adela_Foundation(x, y, self, suit=i % 4, base_rank=KING, max_cards=1)) x += l.XS x, y = l.XM, l.YM+l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 'n') x, y = l.XM+l.XS//2, l.YM+3*l.YS for i in range(9): stack = SS_RowStack(x, y, self, max_move=1, dir=1) s.rows.append(stack) stack.CARD_YOFFSET = 0 x += l.XS l.defaultStackGroups()
def canDealCards(self): if not DealRowTalonStack.canDealCards(self): return False for r in self.game.s.reserves: if r.cards: return False return True
def createGame(self): # create layout l, s = Layout(self), self.s # set window w, h = l.XM + 12 * l.XS, l.YM + l.YS + 16 * l.YOFFSET self.setSize(w, h) # create stacks x, y = l.XM, l.YM s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, "s") x += l.XS for i in range(10): stack = self.RowStack_Class(x, y, self, base_rank=ANY_RANK, max_move=UNLIMITED_MOVES, max_accept=UNLIMITED_ACCEPTS) s.rows.append(stack) x += l.XS s.foundations.append( AbstractFoundationStack(x, y, self, suit=ANY_SUIT, max_accept=0, max_cards=104)) l.createText(s.foundations[0], "s") # define stack-groups l.defaultStackGroups()
def createGame(self): rows = 8 l, s = Layout(self), self.s self.setSize(l.XM + rows * l.XS, l.YM + 2 * l.YS + 20 * l.YOFFSET) x, y = l.XM, l.YM for i in range(rows): s.rows.append(RK_RowStack(x, y, self)) x += l.XS x, y = l.XM + (rows - 1) * l.XS // 2, self.height - l.YS s.foundations.append( Waterfall_Foundation(x, y, self, suit=ANY_SUIT, max_cards=104)) stack = s.foundations[0] tx, ty, ta, tf = l.getTextAttr(stack, 'se') font = self.app.getFont('canvas_default') stack.texts.misc = MfxCanvasText(self.canvas, tx, ty, anchor=ta, font=font) x, y = self.width - l.XS, self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 'sw') l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s # set window self.setSize(l.XM + 10 * l.XS, l.YM + 3 * l.YS + 10 * l.YOFFSET) # create stacks x, y = l.XM, l.YM s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 'se') x += 2 * l.XS for i in range(4): s.foundations.append(SS_FoundationStack(x, y, self, suit=i)) x += l.XS for i in range(4): s.foundations.append( SS_FoundationStack(x, y, self, suit=i, base_rank=KING, dir=-1)) x += l.XS for y in (l.YM + l.YS, l.YM + 2 * l.YS + 5 * l.YOFFSET): x = l.XM for i in range(10): s.rows.append( Twenty_RowStack(x, y, self, base_rank=ANY_RANK, max_accept=1)) x += l.XS # define stack-groups l.defaultStackGroups()
def canDealCards(self): if not DealRowTalonStack.canDealCards(self): return False for s in self.game.s.tableaux: if not s.cards: return False return True
def createGame(self): l, s = Layout(self), self.s self.setSize(l.XM + 9 * l.XS, l.YM + 5 * l.YS) x, y = l.XM, l.YM for i in range(4): s.foundations.append(SS_FoundationStack(x, y, self, suit=i)) y += l.YS x, y = self.width - l.XS, l.YM for i in range(4): s.foundations.append( SS_FoundationStack(x, y, self, suit=i, base_rank=KING, dir=-1)) y += l.YS x, y = (self.width - l.XS) // 2, self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 'se') y = l.YM for i in range(4): x = l.XM + l.XS * 3 // 2 for j in range(6): stack = UD_SS_RowStack(x, y, self, base_rank=NO_RANK) s.rows.append(stack) stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, 0 x += l.XS y += l.YS l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s # set window self.setSize(l.XM + (l.XS * 1.5) + self.Foundations * l.XS, l.YM + 5 * l.YS) # create stacks for j in range(self.Foundations): for i in range(4): x, y, = l.XM + (l.XS * (j + 1.5)), (l.YM + i * l.YS) + l.YS s.foundations.append( Moojub_Foundation(x, y, self, ANY_SUIT, mod=13, max_move=0)) for i in range(4): x, y, = l.XM, (l.YM + i * l.YS) + l.YS s.rows.append(OpenStack(x, y, self)) x, y, = l.XM, l.YM s.talon = DealRowTalonStack(x, y, self, max_rounds=1) l.createText(s.talon, 'se') # define stack-groups l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s # set window self.setSize(l.XM + 8 * l.XS, l.YM + 5 * l.YS) # create stacks x, y = l.XM, l.YM for i in range(8): s.foundations.append( SS_FoundationStack(x, y, self, suit=i // 2, max_cards=10)) x += l.XS y = l.YM + l.YS for i in range(3): x = l.XM for j in range(8): # stack = SS_RowStack(x, y, self, max_move=1) stack = ReserveStack(x, y, self) stack.CARD_YOFFSET = 0 s.rows.append(stack) x += l.XS y += l.YS x, y = self.width - l.XS, self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 'sw') # define stack-groups l.defaultStackGroups()
def createGame(self): l, s = Layout(self), self.s # Set window size w, h = l.XM + l.XS * 10, l.YM + l.YS * 6 self.setSize(w, h) # Create row stacks x, y = l.XM, l.YM for i in range(10): s.rows.append( AppachansWaterfall_RowStack(x, y, self, base_rank=ANY_RANK, max_move=12, max_cards=99)) x = x + l.XS self.setRegion(s.rows, (-999, -999, 999999, l.YM + l.YS * 5)) # Create foundation x, y = w // 2 - l.CW // 2, h - l.YS s.foundations.append(AppachansWaterfall_Foundation(x, y, self, -1)) # Create reserves s.reserves.append(ReserveStack(x - l.XS * 2, y, self)) s.reserves.append(ReserveStack(x + l.XS * 2, y, self)) # Create talon s.talon = DealRowTalonStack(l.XM, y, self) l.createText(s.talon, "n") # Define stack groups l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s # set window self.setSize(l.XM + 9.5 * l.XS, l.YM + 3 * l.YS + l.TEXT_HEIGHT + 12 * l.YOFFSET) # create stacks x, y = l.XM + 1.5 * l.XS, l.TEXT_HEIGHT for i in range(8): stack = Leprechaun_Reserve(x, y, self) s.reserves.append(stack) l.createText(stack, 'n') x += l.XS x, y = l.XM + 1.5 * l.XS, l.YS + l.TEXT_HEIGHT for i in range(8): s.foundations.append(SS_FoundationStack(x, y, self, suit=i // 2)) x += l.XS x, y = l.XM + 1.5 * l.XS, 2 * l.YS + l.TEXT_HEIGHT for i in range(8): s.rows.append(AC_RowStack(x, y, self)) x += l.XS s.talon = DealRowTalonStack(l.XM, l.YM, self) l.createText(s.talon, 's') # define stack-groups l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s # set window self.setSize(l.XM+9*l.XS, l.YM+3*l.YS+12*l.YOFFSET) # create stacks x, y = l.XM+l.XS, l.YM for i in range(8): s.foundations.append( MountOlympus_Foundation( x, y, self, suit=i//2, base_rank=ACE, dir=2, max_move=0, max_cards=7)) x += l.XS x, y = l.XM+l.XS, l.YM+l.YS for i in range(8): s.foundations.append( MountOlympus_Foundation( x, y, self, suit=i//2, base_rank=1, dir=2, max_move=0, max_cards=6)) x += l.XS x, y = l.XM, l.YM+2*l.YS for i in range(9): s.rows.append(self.RowStack_Class(x, y, self, dir=-2)) x += l.XS s.talon = DealRowTalonStack(l.XM, l.YM, self) l.createText(s.talon, 's') # define stack-groups l.defaultStackGroups()
def _fillRow(self, frames=-1, sound=False): rows = self.game.s.rows column_ncards = [] for i in range(10): column = [r for r in rows[i::10] if r.cards] column_ncards.append(len(column)) max_col = max(column_ncards) max_col = max(max_col, 1) n = 0 rr = self.game.s.rows[:max_col*10] while True: filled = False for i in range(10): prev_s = None for s in rr[i::10]: if not self.cards: filled = False break if s.cards: if prev_s: DealRowTalonStack.dealRow( self, rows=[prev_s], frames=frames, sound=sound) n += 1 filled = True break prev_s = s if not filled: break while True: filled = False for i in range(10): for s in rr[i::10]: if not self.cards: filled = False break if not s.cards: DealRowTalonStack.dealRow( self, rows=[s], frames=frames, sound=sound) n += 1 filled = True break if not filled: break return n
def canDealCards(self): if not DealRowTalonStack.canDealCards(self): return False if len(self.cards) == 4: return True for r in self.game.s.rows: if not r.cards: return False return True
def dealCards(self, sound=False): if self.cards: return DealRowTalonStack.dealCards(self, sound=sound) if sound: self.game.startDealSample() game, num_cards = self.game, len(self.cards) rows = list(game.s.rows)[:] rows.reverse() for r in rows: while r.cards: num_cards = num_cards + 1 game.moveMove(1, r, self, frames=4) if self.cards[-1].face_up: game.flipMove(self) assert len(self.cards) == num_cards n = DealRowTalonStack.dealCards(self, sound=False) if sound: self.game.stopSamples() return n
def createGame(self): l, s = Layout(self), self.s self.setSize(l.XM + 8 * l.XS, l.YM + 5 * l.YS) for i, j in ((0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (5, 4), (4, 4), (3, 4), (2, 4), (1, 4), (0, 4), (0, 3), (0, 2), (0, 1)): x, y = l.XM + l.XS + i * l.XS, l.YM + j * l.YS stack = RegalFamily_RowStack(x, y, self, max_move=1, base_rank=NO_RANK) s.rows.append(stack) stack.CARD_YOFFSET = 0 x, y = l.XM + 3 * l.XS, l.YM + l.YS for i in range(3): s.foundations.append( SS_FoundationStack(x, y, self, suit=i, base_rank=9, mod=13, dir=-1)) s.foundations.append( SS_FoundationStack(x, y + 2 * l.YS, self, suit=i, base_rank=9, mod=13, dir=-1)) x += l.XS x, y = l.XM + 3 * l.XS, l.YM + 2 * l.YS s.foundations.append( SS_FoundationStack(x, y, self, suit=3, base_rank=ACE, mod=13)) x += 2 * l.XS s.foundations.append( SS_FoundationStack(x, y, self, suit=3, base_rank=JACK, mod=13, dir=-1)) x, y = l.XM, l.YM + 2 * l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, 's') l.defaultStackGroups()
def dealRow(self, rows=None, flip=1, reverse=0, frames=-1, sound=False): if rows is not None: return DealRowTalonStack.dealRowAvail( self, rows=rows, flip=flip, reverse=reverse, frames=frames, sound=sound) rows = self.game.s.rows for r in rows[:10]: if not r.cards: return self._fillRow(frames=frames, sound=sound) column_ncards = [] for i in range(10): column = [r for r in rows[i::10] if r.cards] column_ncards.append(len(column)) max_col = max(column_ncards) if max(column_ncards) != min(column_ncards): return self._fillRow(frames=frames, sound=sound) r = rows[max_col*10:max_col*10+10] return DealRowTalonStack.dealRowAvail( self, rows=r, flip=flip, reverse=reverse, frames=frames, sound=sound)
def dealCards(self, sound=False): game = self.game if game.cards_dealt == game.DEALS_BEFORE_SHUFFLE: if self.round < self.max_rounds: old_state = game.enterState(game.S_FILL) game.saveStateMove(2 | 16) # for undo self.game.cards_dealt = 0 game.saveStateMove(1 | 16) # for redo game.leaveState(old_state) self.redealCards() else: return False old_state = game.enterState(game.S_FILL) game.saveStateMove(2 | 16) # for undo self.game.cards_dealt += 1 game.saveStateMove(1 | 16) # for redo game.leaveState(old_state) return DealRowTalonStack.dealCards(self, sound)
def createGame(self): # create layout l, s = Layout(self), self.s TABLEAU_YOFFSET = min(9, max(3, l.YOFFSET / 3)) # set window th = l.YS + 3 * TABLEAU_YOFFSET # (set piles so that at least 2/3 of a card is visible with 10 cards) h = (10 - 1) * l.YOFFSET + l.CH * 2 / 3 self.setSize(10 * l.XS + l.XM, l.YM + 3 * th + l.YM + h) # create stacks s.addattr(tableaux=[]) # register extra stack variable x = l.XM + 8 * l.XS + l.XS / 2 y = l.YM for i in range(3): x = l.XM for j in range(8): s.tableaux.append( FlowerArrangement_TableauStack(x, y, self, TABLEAU_YOFFSET, mod=i * 4)) x = x + l.XS y = y + th x, y = l.XM, y + l.YM for i in range(8): s.rows.append(FlowerArrangement_RowStack(x, y, self, max_accept=1)) x = x + l.XS x = l.XM + 8 * l.XS + l.XS / 2 y = self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, "se") # define stack-groups self.sg.openstacks = s.tableaux + s.rows self.sg.talonstacks = [s.talon] self.sg.dropstacks = s.tableaux + s.rows
def createGame(self): l, s = Layout(self), self.s # Set window size self.setSize(l.XM * 3 + l.XS * 9, l.YM + l.YS * 6) # Create row stacks x = l.XM y = l.YM for i in range(8): s.rows.append( RK_RowStack(x, y, self, base_rank=11, max_move=12, max_cards=99)) x = x + l.XS # Create reserve stacks x = self.width - l.XS y = l.YM for i in range(6): s.reserves.append(ReserveStack(x, y, self)) y = y + l.YS y = y - l.YS for i in range(4): x = x - l.XS s.reserves.append(ReserveStack(x, y, self)) self.setRegion(s.rows, (0, 0, l.XM + l.XS * 8, l.YS * 5)) # Create talon s.talon = DealRowTalonStack(l.XM, self.height - l.YS, self) l.createText(s.talon, "n") # Define stack groups l.defaultStackGroups()
def createGame(self): # create layout l, s = Layout(self), self.s TABLEAU_YOFFSET = min(9, max(3, l.YOFFSET // 3)) # set window th = l.YS + 3 * TABLEAU_YOFFSET # (set piles so that at least 2/3 of a card is visible with 10 cards) h = 10 * l.YOFFSET + l.CH * 2 // 3 self.setSize(11 * l.XS + l.XM * 2, l.YM + 3 * th + l.YM + h) # create stacks s.addattr(tableaux=[]) # register extra stack variable x = l.XM + 8 * l.XS + l.XS // 2 y = l.YM for i in range(3, 0, -1): x = l.XM for j in range(10): s.tableaux.append( Dashavatara_TableauStack(x, y, self, i - 1, TABLEAU_YOFFSET)) x = x + l.XS x = x + l.XM s.reserves.append(Dashavatara_ReserveStack(x, y, self)) y = y + th x, y = l.XM, y + l.YM for i in range(10): s.rows.append(Dashavatara_RowStack(x, y, self, max_accept=1)) x = x + l.XS x = self.width - l.XS y = self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, "sw") # define stack-groups self.sg.openstacks = s.tableaux + s.rows + s.reserves self.sg.talonstacks = [s.talon] self.sg.dropstacks = s.tableaux + s.rows
def createGame(self): l, s = Layout(self), self.s self.setSize(l.XM + 9 * l.XS, max(l.YM + l.YS + 20 * l.YOFFSET, l.YM + 6 * l.YS)) x, y, = l.XM + 1.5 * l.XS, l.YM for i in range(6): s.rows.append(LadiesBattle_RowStack(x, y, self, max_move=1, mod=13)) x = x + l.XS x, y = l.XM, l.YM + l.YS / 2 for i in range(4): s.reserves.append(OpenStack(x, y, self, max_accept=0)) y += l.YS x, y = self.width - l.XS, l.YM + l.YS / 2 for i in range(4): s.foundations.append( SS_FoundationStack(x, y, self, suit=i, base_rank=QUEEN, mod=13)) y += l.YS x, y = self.width - l.XS, self.height - l.YS s.talon = DealRowTalonStack(x, y, self) l.createText(s.talon, "sw") l.defaultStackGroups()
def canDealCards(self): if not DealRowTalonStack.canDealCards(self): return False if self.cards and self.cards[-1].face_up: return False return True
def getHelp(self): return DealRowTalonStack.getHelp(self)