Another refresh to the cards code:
from random import shuffle
def val(card):
'gives the value of the card as return value'
valore = pcval[int(card[:-1])]
return valore
def start():
'Create cards, shuffle them, pick pc1 (3 cards) and briscola, then choose the card to play'
global cards,pc1,briscola,cardschoice,cartascelta,pcval
cards = [str(num)+color for num in range(1,11) for color in ['♥','♦','♣','♠']]
pcval = {1:11,2:0,3:10,4:0,5:0,6:0,7:0,8:2,9:3,10:4}
shuffle(cards)
briscola = cards.pop()
pc1 = [cards.pop() for x in range(3)]
cardschoice = []
for c in pc1:
card_color = c[-1]
briscola_color = briscola[-1]
match = card_color == briscola_color
if not match:
cardschoice += [c]
pc1v = []
for i in cardschoice:
pc1v += [val(i)]
pcmin = min(pc1v)
cartascelta = cardschoice[pc1v.index(pcmin)]
def main():
start() # cards,pc1,briscola
print("PC1 has:", pc1,"\nbrisc:(",briscola,")")
print("No brisc", cardschoice,"\npc1 throws=>", cartascelta)
if __name__=='__main__':
main()
Comments
Post a Comment