pc1 checks for a little card... if not goes into the briscole... if not he is obliged to play a high card... so we covered almost all decision making in the first hand of the game for pc1.
After that the pc2 plays his cards... for now, he is able to answer only to cards with low values... but next time we will complete the first match at least... then I think we will stop and go forward with other pythonic coding style.
# briscola 3
from random import shuffle
def val(card):
'gives the value of the card as return value'
valore = pcval[int(card[:-1])]
return valore
def num(card):
'gives the value of the card as return value'
valore = int(card[:-1])
return valore
def listcol(cards=[]):
'returns a list of col from a list of cards'
cardscol = []
for i in cards:
cardscol += [i[-1]]
return cardscol
def start():
'Create cards, shuffle them, pick pc1 (3 cards) and briscola, then choose the card to play'
global cards,pc1,pc2,briscola,cardschoice,pc1_tbl,pcval,dictworst,otherseed
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} # points of cards
shuffle(cards)
briscola = cards.pop()
pc1 = [cards.pop() for x in range(3)]
pc2 = [cards.pop() for x in range(3)]
print(briscola,"BRISCOLA")
print()
print("[PC1]")
print("His cards",pc1)
for c in pc1_match1():
print("Looking for a...",c)
if c in pc1:
pc1_tbl = c
print("********* found! ************")
if pc1_tbl[-1]==briscola[-1]:
print("It is a briscola!")
else:
pass
break
def isScart(cs):
scartine = 2,4,5,6,7
if num(cs) in scartine:
return True
else:
return False
def isCarico(cs):
carico = 1,3
if num(cs) in carico:
return True
else:
return False
def isFig(cs):
figure = 8,9,10
if num(cs) in figure:
return True
else:
return False
def isBrisc(cs):
if cs[-1] == briscola[-1]:
return True
else:
return False
def pc1_match1():
'Card sequence for pc2 playing decision'
scartine = [2,4,5,6,7,8,9,10]
briscole = [2,4,5,6,7,8,9,10,3,1]
carichi = [3,1]
colori = ['♥','♦','♣','♠']
colori.pop(colori.index(briscola[-1]))
l_scartine = [str(x)+color for x in scartine for color in colori]
l_briscole = [str(x)+briscola[-1] for x in briscole]
l_carichi = [str(x)+color for x in carichi for color in colori]
pc1_seq = l_scartine + l_briscole + l_carichi
return pc1_seq
def pc2_match1():
'Card sequence for pc2 playing decision'
cardscolors = ['♥','♦','♣','♠']
cardscolors.pop(cardscolors.index(briscola[-1])) # Erase briscola
cardswithpoints = [str(x)+pc1_tbl[-1] for x in [1,3,10,9,8]] # List victory n points
two_ten = [str(x)+cc for x in [2,4,5,6,7,8,9,10] for cc in cardscolors] # List with no points
briscole = [str(x)+briscola[-1] for x in [2,4,5,6,8,7,9,10,3,1]] # goodbye briscole
cardscolors.pop(cardscolors.index(pc1_tbl[-1])) # Erase briscola
carichi = [str(x)+cc for x in [3,1] for cc in cardscolors]
pc2_seq = cardswithpoints + two_ten + briscole + carichi
return pc2_seq
def pc2AI():
'the answer of pc2'
global pc2_tbl
if isBrisc(pc1_tbl):
print("I need code for this...")
elif isScart(pc1_tbl):
print("[PC2]\nHis cards",pc2)
for c in pc2_match1():
print("Looking for a",c)
if c in pc2:
print("********* found! ************")
pc2_tbl=c
print(c)
break
else:
pass
print("[PC1]",pc1_tbl,"[PC2]",pc2_tbl)
print("Now we need code to see who wins")
else:
print("Code missing...")
def main():
start()
pc2AI()
if __name__=='__main__':
main()
Comments
Post a Comment