Well, we want to make something different this time. We want to make the computer decide with another system... trying to see wich is the best decision for him, instead of doing lists of choices, from the best to the worst like we did before. So, to start doing this, let's create a function that is able to understand who wins among two cards... this will be the foundation of a new way of "thinking" for the pc2 in answer to the card of pc1... In the output the last card of each row is the card that wins the match.
# different way of choosing a card, making computer think what has more worth
from random import shuffle
def start():
global cards,pcval,briscola,pc1
cards = [str(num)+color for num in range(1,11) for color in ['♥','♦','♣','♠']]
pcval = {1:11,2:-4,3:10,4:-3,5:-2,6:-1,7:1,8:2,9:3,10:4} # points of cards
shuffle(cards)
briscola = cards.pop()
pc1 = [cards.pop() for x in range(3)]
def val(card):
'gives the value of the card as return value'
valore = pcval[int(card[:-1])]
return valore
def whoWins(a,b):
'who wins between card a and b'
global x
print("Briscola:"+briscola,end=',"..............')
print("[",a,b,"] ",end ='')
if a[-1]==b[-1]:
if val(a)>=val(b):
print("",a)
return a
else:
print("[*]",b)
return b
else:
if b[-1]==briscola[-1]:
print("[**]",b)
return b
else:
print("",a)
return(a)
# testiamo pc1match
def main():
start()
print(briscola)
print(pc1)
print(pc1match1())
for i in range(20):
start()
whoWins(cards.pop(), cards.pop())
print("[*] = wins PC2 with a greater card")
print("[**] = wins PC2 with a briscola card")
Comments
Post a Comment