本文整理汇总了Python中Deck.pop方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.pop方法的具体用法?Python Deck.pop怎么用?Python Deck.pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deck
的用法示例。
在下文中一共展示了Deck.pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TriPeaks
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import pop [as 别名]
class TriPeaks(object):
#Smidur
def __init__(self):
self.isPlaying = True
self.boardRows = 4
self.boardCols = 10
#Stokkur leiksins
self.deck = Deck(52)
self.deck.shuffleCards()
#2D array of cards in the board, initialized as None
self.board = self.initBoard()
self.dealToBoard()
#Cards in the heap
self.heap = [self.deck.cards.pop()]
#Breyta sem heldur utan um stig
self.score = 0
#Breyta sem byrjar ad taka tima
self.start_time = time.time()
#Lokatimi leiks
self.finaltime = 0.0
#Breyta sem heldur utanum 'moves'
self.moves = 0
def initBoard(self):
board = []
for i in range(self.boardRows):
board.append([None for _ in range(self.boardCols)])
return board
# Pre: self.deck contains a deck of cards
# Post: 28 cards from the deck have been dealt to the board
# Run: TriPeaks.dealToBoard()
def dealToBoard(self):
''' Deals cards from the deck to the board '''
# board is a 4x10 list with None values in gaps
# Row 0:
for col in range(0,self.boardCols-1,3):
self.board[0][col] = self.deck.cards.pop()
self.board[0][col].col = col
self.board[0][col].row = 0
# Row 1:
for col in range(self.boardCols-1):
if (col%3 != 2): # TODO: haegt ad gera i einni linu?
self.board[1][col] = self.deck.cards.pop()
self.board[1][col].col = col
self.board[1][col].row = 1
# Row 2:
for col in range(self.boardCols-1):
self.board[2][col] = self.deck.cards.pop()
self.board[2][col].col = col
self.board[2][col].row = 2
# Row 3:
for col in range(self.boardCols):
self.board[3][col] = self.deck.cards.pop()
self.board[3][col].col = col
self.board[3][col].row = 3
# Post: returns how many cards are left in the deck
# Run: TriPeaks.deckSize()
def deckSize(self):
return len(self.deck.cards)
# Pre: row and col are integers
# Post: returns true if the card at self.board[row][col] is movable
# Run: TriPeaks.isMovable(row,col)
def isMovable(self, row, col):
''' Checks if a card in the board is movable '''
if self.board[row][col] is None:
return False
if (row == self.boardRows-1):
return True
return (self.board[row+1][col] is None and self.board[row+1][col+1] is None)
# Pre: card is a Card object
# Post: returns True if card has a value one higher or lower than the
# top card on the heap
# Run: TriPeaks.isLegal(card)
def isLegal(self, card):
''' Checks if a card move is legal '''
if card is None:
return False
return abs(self.heap[-1].value - card.value)%11 == 1
# Pre: row and col are integers
# Post: card no. col in row no. row has been printed to the console
# Run: TriPeaks.printCard(row, col)
def printCard(self, row, col):
#.........这里部分代码省略.........