help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vegiebro
    New Member
    • Sep 2022
    • 1

    help

    I am a kid that is taking videos on how to code in python. I am making the card game war as a project and have been stuck on a problem for weeks. if i use a dictionary to show the card suits, or the face cards, it ignores if the cards are eaqual. i dont know where the problem is, so i’ll post the entire thing. also, I am working in pycharm. I am only a 7’th grader and dont expect you to read the whole thing. thanks!

    ps: if I use this,:arrow_dow n:︎ ,instead of the dictionary, the code runs without a flaw.

    unconverted_dec k=[1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,1,2,3,4,5,6, 7,8,9,10,11,12, 13,14,1,2,3,4,5 ,6,7,8,9,10,11, 12,13,14,1,2,3, 4,5,6,7,8,9,10, 11,12,13,14]

    here



    import random
    import time
    test_list2 = []
    test_list1 = []

    unconverted_dec k = {'2❤️' : 2,
    '3❤️' : 3,
    '4❤️' : 4,
    '5❤️' : 5,
    '6❤️' : 6,
    '7❤️' : 7,
    '8❤️' : 8,
    '9❤️' : 9,
    '10❤️' : 10,
    'J❤️' : 11,
    'Q❤️' : 12,
    'K❤️' : 13,
    'A❤️' : 15,
    '2♠️' : 2,
    '3♠️': 3,
    '4♠️': 4,
    '5♠️': 5,
    '6♠️': 6,
    '7♠️': 7,
    '8♠️': 8,
    '9♠️': 9,
    '10♠️': 10,
    'J♠️': 11,
    'Q♠️': 12,
    'K♠️️': 13,
    'A♠️️': 15,
    '2♦️': 2,
    '3♦️': 3,
    '4♦️': 4,
    '5♦️': 5,
    '6♦️': 6,
    '7♦️': 7,
    '8♦️': 8,
    '9♦️': 9,
    '10♦️': 10,
    'J♦️': 11,
    'Q♦️': 12,
    'K♦️': 13,
    'A♦️': 15,
    '2︎♣️': 2,
    '3♣️': 3,
    '4♣️': 4,
    '5♣️': 5,
    '6♣️': 6,
    '7♣️': 7,
    '8♣️': 8,
    '9♣️': 9,
    '10♣️': 10,
    'J♣️': 11,
    'Q♣️': 12,
    'K♣️': 13,
    'A♣️': 15}
    oedokn = list(unconverte d_deck)
    random.shuffle( oedokn)

    computer_primar y = oedokn[1::2]
    player_primary = oedokn[0::2]
    random.shuffle( player_primary)
    random.shuffle( computer_primar y)
    player_secondar y = []
    computer_second ary = []
    turns = 5
    play_card_index = 0
    # ---------------------------------
    print(player_pr imary)
    print(computer_ primary)
    comp_card_index = 0
    play_war_at_ris k = []
    comp_war_at_ris k = []

    while winner := ' ':
    play_win_round = False
    comp_win_round = False
    play_len = len(player_prim ary) + len(player_seco ndary)
    comp_len = len(computer_pr imary) + len(computer_se condary)
    print(' ')
    print(' ')
    ready = input("Ready?: ")
    try:
    if ready.lower() == "":
    print("your card is: " + str(player_prim ary[play_card_index]))
    print("your opponent's is: " + str(computer_pr imary[comp_card_index]))
    # ------------------------------------
    if player_primary[play_card_index] > computer_primar y[comp_card_index]:
    player_secondar y.append(player _primary[play_card_index])
    player_secondar y.append(comput er_primary[comp_card_index])
    player_primary. remove(player_p rimary[play_card_index])
    computer_primar y.remove(comput er_primary[comp_card_index])
    print('player discard: '+str(player_se condary))
    play_win_round = True
    print('computer discard: [?,?,?...]')
    elif player_primary[play_card_index] < computer_primar y[comp_card_index]:
    computer_second ary.append(play er_primary[play_card_index])
    computer_second ary.append(comp uter_primary[comp_card_index])
    player_primary. remove(player_p rimary[play_card_index])
    computer_primar y.remove(comput er_primary[comp_card_index])
    print('player discard: '+str(player_se condary))
    print('computer discard: [?,?,?...]')
    comp_win_round = True
    elif play_win_round or comp_win_round == False:
    while len(comp_war_at _risk) < 4:
    play_war_at_ris k.append(player _primary[play_card_index])
    player_primary. remove(player_p rimary[play_card_index])
    comp_war_at_ris k.append(comput er_primary[comp_card_index])
    computer_primar y.remove(comput er_primary[comp_card_index])
    # ------------------------------------
    print('player cards at risk: '+str(play_war_ at_risk))
    print('computer cards at risk: [?,?,?...]'
    print(' ')
    input("⚔️ Ready for war⚔️?: ")
    print(' ')
    print("your card is: " + str(player_prim ary[play_card_index]))
    print("your opponent's is: " + str(computer_pr imary[comp_card_index]))
    # ------------------------------------
    if player_primary[play_card_index] > computer_primar y[comp_card_index]:
    player_secondar y.append(player _primary[play_card_index])
    player_secondar y.append(comput er_primary[comp_card_index])
    player_primary. remove(player_p rimary[play_card_index])

    # ------------------------------------------
    player_secondar y.append(play_w ar_at_risk[0])
    player_secondar y.append(play_w ar_at_risk[1])
    player_secondar y.append(play_w ar_at_risk[2])
    player_secondar y.append(play_w ar_at_risk[3])
    # -------------------------------------------
    player_secondar y.append(comp_w ar_at_risk[0])
    player_secondar y.append(comp_w ar_at_risk[1])
    player_secondar y.append(comp_w ar_at_risk[2])
    player_secondar y.append(comp_w ar_at_risk[3])
    # -------------------------------------------
    play_war_at_ris k.clear()
    comp_war_at_ris k.clear()
    # -------------------------------------------
    computer_primar y.remove(comput er_primary[comp_card_index])
    print('player discard: ' + str(player_seco ndary))
    print('computer discard: [?,?,?...]')
    # -------------------------------------------
    elif player_primary[play_card_index] < computer_primar y[comp_card_index]:
    computer_second ary.append(play er_primary[play_card_index])
    computer_second ary.append(comp uter_primary[comp_card_index])
    player_primary. remove(player_p rimary[play_card_index])
    computer_primar y.remove(comput er_primary[comp_card_index])
    # --------------------------------------------
    computer_second ary.append(play _war_at_risk[0])
    computer_second ary.append(play _war_at_risk[1])
    computer_second ary.append(play _war_at_risk[2])
    computer_second ary.append(play _war_at_risk[3])
    # -------------------------------------------
    computer_second ary.append(comp _war_at_risk[0])
    computer_second ary.append(comp _war_at_risk[1])
    computer_second ary.append(comp _war_at_risk[2])
    computer_second ary.append(comp _war_at_risk[3])
    # -------------------------------------------
    play_war_at_ris k.clear()
    comp_war_at_ris k.clear()
    print('player discard: ' + str(player_seco ndary))
    print('computer discard: [?,?,?...]')
    elif player_primary[play_card_index] == computer_primar y[comp_card_index]:
    while len(comp_war_at _risk) < 4:
    play_war_at_ris k.append(player _primary[play_card_index])
    player_primary. remove(player_p rimary[play_card_index])
    comp_war_at_ris k.append(comput er_primary[comp_card_index])
    computer_primar y.remove(comput er_primary[comp_card_index])
    print(play_war_ at_risk)
    print(comp_war_ at_risk)
    print('your at risk = ' + str(play_war_at _risk))
    print('COMP at risk = '+ str(comp_war_at _risk))
    print(' ')
    print(' ')
    ready = input("⚔️ Ready for war⚔️?: ")
    except IndexError:
    for u in computer_second ary:
    computer_primar y.append(u)
    random.shuffle( computer_primar y)
    for i in player_secondar y:
    player_primary. append(i)
    random.shuffle( player_primary)
    computer_second ary.clear()
    player_secondar y.clear()
    print(' new round ')
    print(' good luck')
    print(' 👍🏻👍🏻👍🏻👍🏻 👍🏻')
    print(' 🤘🏻😁🤘🏻😁🤘🏻 ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    print(' ')
    turns=turns+1
    if play_len == 0:
    for e in player_secondar y:
    player_primary. append(e)
    print('end of the game!')
    print('the winner is...')
    print('💣🧨💣🧨')
    print(5)
    time.sleep(1)
    print(4)
    time.sleep(1)
    print(3)
    time.sleep(1)
    print(2)
    time.sleep(1)
    print(1)
    time.sleep(1)
    print('💥💥 you 💥💥')
    break
    elif comp_len == 0:
    for e in computer_second ary:
    computer_primar y.append(e)
    print('end of the game!')
    print('the winner is...')
    print('💣🧨💣🧨')
    print(5)
    time.sleep(1)
    print(4)
    time.sleep(1)
    print(3)
    time.sleep(1)
    print(2)
    time.sleep(1)
    print(1)
    time.sleep(1)
    print('💥💥 computer 💥💥')
    break
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    I am a kid that is taking videos on how to code in python. I am making the card game war as a project and have been stuck on a problem for weeks. if i use a dictionary to show the card suits, or the face cards, it ignores if the cards are eaqual. i dont know where the problem is, so i’ll post the entire thing. also, I am working in pycharm. I am only a 7’th grader and dont expect you to read the whole thing. thanks!

    ps: if I use this,:arrow_dow n:︎ ,instead of the dictionary, the code runs without a flaw.

    unconverted_dec k=[1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,1,2,3,4,5,6, 7,8,9 ,10,11,12,13,14 ,1,2,3,4,5,6,7, 8,9,10,11,12,13 ,14,1 ,2,3,4,5,6,7,8, 9,10,11,12,13,1 4]
    Post the code with proper indentations and use [code] tags.

    Comment

    Working...