Let's give another closer look to the code we could use to make the computer decide what to play.
We have two players:
pc1 and pc2
let's say that pc1 has thrown 2♥
pc2 has ['4♥', '10♥', '3♣']
if we were pc2 we should play 10♥
How we can make it happen that the computer throws 10♥ ... we could check for the highest value with the same seed ♥... but if we have a 1♥ we should look for the points that 1 can make me earn (11) and not at the number (1). Same thing for 3... and there could be also 7♥ that is higher than 2♥, but this won't give me points as 7 gives 0 points... so I should write code do avoid this... it's a bit too long... so I decide to do another thing... wich is the best card I wish I have if pc1 plays a card of seed ♥? It is 1♥ and after that? 3♥ and so on until 8♥... after the 8♥ we have no points, so I stop the wishcards there.... so I make a list taking the seed ♥ (or any other seed that will come with the card that I pass as argument) and attaching to the seed the 1,3,10,9,8 values in this order. After that I check if pc2 has one of this iterating the list in that order. The first card I find is the best one and I break the code and return this value.
What if pc2 has no good card... we figure it out lately.
def checkpoints(scart,mycards):
global mycard
mycard = mycards
'returns a card that can make you earn points'
print("If pc1 throws this card:",scart)
print("And pc2 has this cards:",mycards)
print("We look at the seed, that is, ", scart[-1])
colore = scart[-1] # here we take the seed of the card
wishcards = [x+colore for x in ["1","3","10","9","8"]] # here we creare a list with cards from highest point to lower
print("This are the cards that can make pc2 earn points:",wishcards)
print("So... after chasing in the list of wishcards from best to last...")
for card in wishcards:
if card in mycards:
break
return "This is what pc2 must play:" + card
print(checkpoints("2♥",["4♥","10♥","3♣"]))
[to be continued ...]
Comments
Post a Comment