代码拉取完成,页面将自动刷新
同步操作将从 jack2583/PythonExamples 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import random
import time
SUITS = ('C', 'S', 'H', 'D')
RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K')
VALUES = {'A': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'T': 10, 'J': 10, 'Q': 10, 'K': 10}
class card:
def __init__(self, suit, rank):
if (suit in SUITS) and (rank in RANKS):
self.suit = suit
self.rank = rank
else:
self.suit = None
self.rank = None
print("Invalid card: ", suit, rank)
def __str__(self):
return self.suit + self.rank
def getRank(self):
return self.rank
def getSuit(self):
return self.suit
class deck:
def __init__(self):
self.deck = [card(suit, rank) for suit in SUITS for rank in RANKS]
def shuffle(self):
random.shuffle(self.deck)
def dealCard(self):
return random.choice(self.deck)
def __str__(self):
print(self.deck)
# Begin play
# create two decks, one for each player.
print("Gathering brand new two decks of cards............\n")
deck1 = deck()
deck2 = deck()
time.sleep(5)
print('..........decks ready!!!\n')
print('Combining and shuffling both the decks..')
time.sleep(10)
# Shuffle the decks
deck1.shuffle()
deck2.shuffle()
# combine both the shuffled decks
combinedDeck = deck1.deck + deck2.deck
# ReShuffle the combined deck, cut it and distribute to two players.
random.shuffle(combinedDeck)
print("....decks have been combined and shuffled...\n")
print("------------------------------------------\n")
input("Enter a key to cut the deck..\n")
player1 = combinedDeck[0:52]
player2 = combinedDeck[52:]
print("Deck has been split into two and Human get a half and computer gets the other...\n")
# Begin play:
print("------------------------------------------\n")
print("player1 == Human\n")
print("player2 == Computer\n")
print("------------------------------------------\n")
print("player1 goes first...hit any key to place the card on the pile..\n")
centerPile = []
currentPlayer2Card = None
while len(player1) != 0 and len(player2) != 0: # this needs a fix as it goes on an infinite loop on a success.
switchPlayer = True
while switchPlayer == True:
for card in range(len(player1)):
input("Enter any key to place a card!!!\n")
currentPlayer1Card = player1[card].rank
print("Your current card's rank: {}".format(currentPlayer1Card))
centerPile.append(player1[card])
player1.pop(card)
switchPlayer = False
if currentPlayer2Card == currentPlayer1Card:
player1 = player1 + centerPile
print("The human got a match and takes all the cards from center pile..")
break
while switchPlayer == False:
for card in range(len(player2)):
currentPlayer2Card = player2[card].rank
print("Computer's current card's rank: {}".format(currentPlayer2Card))
centerPile.append(player2[card])
player2.pop(card)
switchPlayer = True
if currentPlayer1Card == currentPlayer2Card:
player2 = player2 + centerPile
print("Computer got a match and takes all the cards from center pile..")
break
print("GAME OVER!!!\n")
print("Human has {} cards and computer has {}..".format(len(player1), len(player2)))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。