I am trying to create a simple version of the card game WAR, thus far everything functions as it should.. except when I compare the two randomly generated cards. I've researched it a bit and I think I have to use the
method but I do not know how to implement it into what I have. Another solution I know of, but seems extremely ugly and doesn't seem like the best way to go about doing this is create a function that compares every instance a word is generated then create a value from it.
if card == ('ace'): blah = 1 elif etc.. etc..
This is what I have so far, I need help on the comparisons.
import random def name1(): name = input('Player one please enter your name -> ') return name def name2(): name = input('Player two please enter your name -> ') return name def cardName(): card = ['ace','two','three','four','five','six','seven','eight','nine','ten','jack','queen','king'] cardChoice =(random.randint(1,13)) return card[cardChoice-1] def suiteName(): suite = ['Clubs','Diamonds','Hearts','Spades'] suiteChoice=(random.randint(1,4)) return suite[suiteChoice-1] ###Main### player1 = name1() player2 = name2() print('') print('Here we go ...') print('') play = ('y') while play ==('y'): p1card = cardName() p1suite = suiteName() p2card = cardName() p2suite = suiteName() p1win = 0 p2win = 0 tie = 0 print(player1 +',' +' Your card is: ' +(p1card) +' of ' + (p1suite)) print(player2 +',' +' Your card is: ' +(p2card) +' of ' + (p2suite)) print('') ###############This is where I am getting messed up, how do I get the value of the random word in the list to compare? if p1card > p2card: print(player1 + ' has won this round.') print('') p1win = p1win + 1 elif p2card > p1card: print(player2 + ' has won this round.') print('') p2win = p2win + 1 elif p1card == p2card and p1suite > p2suite: print(player1 + ' has won this round.') print('') p1win = p1win + 1 elif p2card == p1card and p2suite > p1suite: print(player2 + ' has won this round.') print('') p2win = p2win + 1 else: print('it was a tie') print('') tie = tie + 1 play = input('Do you want to play again - (y or n)? ') print('')