本文整理匯總了Python中Deck.shuffleCards方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.shuffleCards方法的具體用法?Python Deck.shuffleCards怎麽用?Python Deck.shuffleCards使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Deck
的用法示例。
在下文中一共展示了Deck.shuffleCards方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TriPeaks
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import shuffleCards [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):
#.........這裏部分代碼省略.........
示例2: Test
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import shuffleCards [as 別名]
class Test(unittest.TestCase):
def setUp(self):
self.testCard1a = Card('H',10, 0, 0, None)
self.testCard1b = Card('H',10, 0, 0, None)
self.testCard2a = Card('S',5, 0, 0, None)
self.testCard2b = Card('S',5, 0, 0, None)
self.testCard3 = Card('T',3, 0, 0, None)
self.initialDeck = Deck(52)
self.sortedDeck = Deck(52)
self.sortedDeck.cards.sort()
self.shuffledDeck = Deck(52)
self.shuffledDeck.shuffleCards()
self.game1 = TriPeaks()
self.game2 = TriPeaks()
self.deckCard = self.game1.deck.cards[-1]
self.heapCard = self.game1.heap[-1]
self.legalCard = Card('H', (self.heapCard.value)%13+1, 3,3,None)
self.illegalCard = Card('H', (self.heapCard.value)%13+5, 0,0,None)
def test_Card1(self):
#make sure that the cards are different
self.assertNotEqual(self.testCard2a,self.testCard3)
def test_Card2(self):
#make sure that that the cards are equal
self.assertEqual(self.testCard1a,self.testCard1b)
def test_Card3(self):
#make sure that that the cards are equal
self.assertEqual(self.testCard2a,self.testCard2b)
def test_shuffleCards(self):
# make sure that shuffle maintains the same cards
self.shuffledDeck.cards.sort()
self.assertTrue(self.shuffledDeck.cards == self.sortedDeck.cards)
def test_deckSize(self):
#make sure that decksize is the same
self.assertEqual(self.game1.deckSize(),self.game2.deckSize())
def test_initBoard(self):
#make sure that initboard makes same size board each time
self.assertEqual(self.game1.initBoard(), self.game2.initBoard())
def test_addScore(self):
#make sure that addScore adds to the score
self.game1.addScore(500)
self.assertEqual(self.game1.score, 500)
def test_Moves(self):
#makes sure that moves starts at 0
self.assertEqual(self.game1.moves,0)
def test_isMovable1(self):
#make sure that card is movable
self.assertTrue(self.game1.isMovable(3,3))
def test_isMovable2(self):
#make sure that card is not movable
self.assertFalse(self.game1.isMovable(1,1))
def test_isLegal1(self):
# make sure that card is legal
self.assertTrue(self.game1.isLegal(self.legalCard))
def test_isLegal2(self):
# make sure that card is illegal
self.assertFalse(self.game1.isLegal(self.illegalCard))
def test_moveToHeap(self):
# make sure that card is added to heap
movedCard = self.game1.moveToHeap(self.legalCard)
self.assertEqual(movedCard, self.legalCard)
self.assertIn(self.legalCard, self.game1.heap)
def test_toHeap(self):
# make sure that card is removed from deck and added to heap
self.game1.toHeap()
self.assertIn(self.deckCard, self.game1.heap)
self.assertNotIn(self.deckCard, self.game1.deck.cards)