473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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_down:︎ ,instead of the dictionary, the code runs without a flaw.

unconverted_deck=[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_deck = {'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(unconverted_deck)
random.shuffle(oedokn)

computer_primary = oedokn[1::2]
player_primary = oedokn[0::2]
random.shuffle(player_primary)
random.shuffle(computer_primary)
player_secondary = []
computer_secondary = []
turns = 5
play_card_index = 0
# ---------------------------------
print(player_primary)
print(computer_primary)
comp_card_index = 0
play_war_at_risk = []
comp_war_at_risk = []

while winner := ' ':
play_win_round = False
comp_win_round = False
play_len = len(player_primary) + len(player_secondary)
comp_len = len(computer_primary) + len(computer_secondary)
print(' ')
print(' ')
ready = input("Ready?: ")
try:
if ready.lower() == "":
print("your card is: " + str(player_primary[play_card_index]))
print("your opponent's is: " + str(computer_primary[comp_card_index]))
# ------------------------------------
if player_primary[play_card_index] > computer_primary[comp_card_index]:
player_secondary.append(player_primary[play_card_index])
player_secondary.append(computer_primary[comp_card_index])
player_primary.remove(player_primary[play_card_index])
computer_primary.remove(computer_primary[comp_card_index])
print('player discard: '+str(player_secondary))
play_win_round = True
print('computer discard: [?,?,?...]')
elif player_primary[play_card_index] < computer_primary[comp_card_index]:
computer_secondary.append(player_primary[play_card_index])
computer_secondary.append(computer_primary[comp_card_index])
player_primary.remove(player_primary[play_card_index])
computer_primary.remove(computer_primary[comp_card_index])
print('player discard: '+str(player_secondary))
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_risk.append(player_primary[play_card_index])
player_primary.remove(player_primary[play_card_index])
comp_war_at_risk.append(computer_primary[comp_card_index])
computer_primary.remove(computer_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_primary[play_card_index]))
print("your opponent's is: " + str(computer_primary[comp_card_index]))
# ------------------------------------
if player_primary[play_card_index] > computer_primary[comp_card_index]:
player_secondary.append(player_primary[play_card_index])
player_secondary.append(computer_primary[comp_card_index])
player_primary.remove(player_primary[play_card_index])

# ------------------------------------------
player_secondary.append(play_war_at_risk[0])
player_secondary.append(play_war_at_risk[1])
player_secondary.append(play_war_at_risk[2])
player_secondary.append(play_war_at_risk[3])
# -------------------------------------------
player_secondary.append(comp_war_at_risk[0])
player_secondary.append(comp_war_at_risk[1])
player_secondary.append(comp_war_at_risk[2])
player_secondary.append(comp_war_at_risk[3])
# -------------------------------------------
play_war_at_risk.clear()
comp_war_at_risk.clear()
# -------------------------------------------
computer_primary.remove(computer_primary[comp_card_index])
print('player discard: ' + str(player_secondary))
print('computer discard: [?,?,?...]')
# -------------------------------------------
elif player_primary[play_card_index] < computer_primary[comp_card_index]:
computer_secondary.append(player_primary[play_card_index])
computer_secondary.append(computer_primary[comp_card_index])
player_primary.remove(player_primary[play_card_index])
computer_primary.remove(computer_primary[comp_card_index])
# --------------------------------------------
computer_secondary.append(play_war_at_risk[0])
computer_secondary.append(play_war_at_risk[1])
computer_secondary.append(play_war_at_risk[2])
computer_secondary.append(play_war_at_risk[3])
# -------------------------------------------
computer_secondary.append(comp_war_at_risk[0])
computer_secondary.append(comp_war_at_risk[1])
computer_secondary.append(comp_war_at_risk[2])
computer_secondary.append(comp_war_at_risk[3])
# -------------------------------------------
play_war_at_risk.clear()
comp_war_at_risk.clear()
print('player discard: ' + str(player_secondary))
print('computer discard: [?,?,?...]')
elif player_primary[play_card_index] == computer_primary[comp_card_index]:
while len(comp_war_at_risk) < 4:
play_war_at_risk.append(player_primary[play_card_index])
player_primary.remove(player_primary[play_card_index])
comp_war_at_risk.append(computer_primary[comp_card_index])
computer_primary.remove(computer_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_secondary:
computer_primary.append(u)
random.shuffle(computer_primary)
for i in player_secondary:
player_primary.append(i)
random.shuffle(player_primary)
computer_secondary.clear()
player_secondary.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_secondary:
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_secondary:
computer_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('💥💥 computer 💥💥')
break
Sep 19 '22 #1
1 10731
dev7060
636 Expert 512MB
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_down:︎ ,instead of the dictionary, the code runs without a flaw.

unconverted_deck=[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]
Post the code with proper indentations and use [code] tags.
Oct 4 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
3
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.