jeudi 27 février 2020

Why does my python code think that this character is bigger than another?

I'm trying to create a robot that plays "Big 2" card game.

My goal was to start off with making it only play 1 card plays. I am trying to test it out, returning True if number 1 is bigger than number 2 and False if it is not.

RANK_ORDER = '34567890JQKA2'
SUIT_ORDER = 'DCHS'

def is_higher(card1, card2):
  a = list(card1)
  b = list(card2)
  if a[0] == b[0]:
    if a[1] > b[1] in SUIT_ORDER:
      return True
    elif a[1] < b[1] in SUIT_ORDER:
      return False
  elif a[1] > b[1] in SUIT_ORDER:
    return True
  elif a[1] < b[1] in SUIT_ORDER:
    return False
  elif a[1] == b[1]: #problem may be from here downwards
    if a[0] > b[0] in RANK_ORDER:
      return True
    elif a[0] < b[0] in RANK_ORDER:
      return False

if __name__ == '__main__':
  print(is_higher('8D', '9S'))
  print(is_higher('2S', '2D'))
  print(is_higher('3H', '2H')) #this has a problem
  print(is_higher('QS', 'JS'))
  print(is_higher('AD', '2S'))

I have somewhat succeeded in my goal, however, why does it return True for third example even though 3 is higher than 2 in RANK_ORDER?

Aucun commentaire:

Enregistrer un commentaire