![]() |
|
#1
|
|||
|
|||
Black Jack gameI have a Black Jack game but it's not working properly. It keeps repeating the same numbers. Does any one know how to make it not repeat the numbers?
Python Code:
Last edited by admin : 12-Jan-2009 at 02:48.
Reason: Please insert your Python code between [py] & [/py] tags
|
|||
|
#2
|
|||
|
|||
Re: Black jack gameCan't you focus rand on range of like 1-52 and it will select subsequent values without repeating?
If not , what if you used an array of [1 thu 52] Use rand to choose an indice, get that value into a separate variable, and change the value at that indice to zero. Then take that variable value and divide by 13 to detemine suit and then %13 to determine value (I think) Like if rand chooses indice 35: 35 / 13 = 2 , , 35 % 13 = 9 , , so you have a 9 of suit 2. (suits are 0 thru 3) I think there will need to be an adjustment where if( (x%13) == 0 ) suit = suit-1 or something? Like: 54 % 13 = 0 and 54 / 13 = 4 hmmm need to think about that some... On subsequent rand selects, if you get a zero, increment up (or down ) until you get a value. Guess you'll need a counter in there to count 52. To re-shuffle just load the array with 1 thru 52 again. Seems like a lot to go thu though doesn't it. Maybe there's a better way. I made this Cprog to see how the values break out: (sorry about C No time to figure it out in py right now) CPP / C++ / C Code:
Last edited by Howard_L : 12-Jan-2009 at 02:05.
|
|
#3
|
|||
|
|||
Re: Black jack gameWow, check this out:
Python Code:
|
|
#4
|
|||
|
|||
Re: Black jack gameits not working its givin me an error..av you got your own version of a black jack game...this pytho is killin me head
|
|
#5
|
|||
|
|||
Re: Black jack gameNo , I haven't made a blackjack game. Good project though. Is this for a class?
What's not working? Where is the error occuring? What does it say? Post the your exact code so I can see where the problem is and help you. |
|
#6
|
|||
|
|||
Re: Black jack gamePython Code:
ITS GIVIN ME AN ERROR MESG..SEE BELOW: the computer is showing a 10 your hand totals: 18 ([8, 10]) [D]ealt [S]tick [Q]uit: d computer Busts! Traceback (most recent call last): File "C:/Python26/testn", line 30, in <module> showHand() File "C:/Python26/testn", line 17, in showHand print "the computer is showing a %d" % computer[0] IndexError: list index out of range >>> Last edited by LuciWiz : 16-Jan-2009 at 11:49.
Reason: Please insert your Python code between [py] & [/py] tags
|
|
#7
|
|||
|
|||
Re: Black jack gamedude, it is EXTREMELY important to show you indents in python.
That is how python understands scope. Please read the guidelines to learn how to enclose your code in the code tags next time (as LuciWiz has done for you above) so that the indents will show. What OS are you running this on? I have just done the windows install and am learning how to use it... So is that saying that computer[0] is out of range? When I first start that line prints, after I make choose [Dealt] I get the error you show... hmmm so arrays can become empty? I am new to python so it will take me a while to figure anything out and I won't be able to do that until tonight. sorry But you could try playing with an array and see if you can mimic what changes computer[] goes through during that part of the program. Just on the command line try stuff like: Python Code:
Last edited by Howard_L : 16-Jan-2009 at 14:31.
|
|
#8
|
|||
|
|||
Re: Black jack gameAnd so I see that you redefine computer and player in each of these if's:
Python Code:
Maybe you want to give them some value instead, maybe zero? also setup doesn't look quite right there does it? (there are other typo's like that) |
|
#9
|
|||
|
|||
Re: Black jack gameI Am New To Python As Well And Only Trying To Understand How To Make This Game Work....its Takin Me Looooooooooong To Understand
|
|
#10
|
|||
|
|||
Re: Black jack gamei tried is again its givin me
(12.1.09) (Cam-81288) the computer is showing a 11 your hand totals: 21 ([10, 11]) [D]eal [Q]uit [S]tick: s Youn win! Traceback (most recent call last): File "E:\test.py", line 33, in ? showHand() File "E:\test.py", line 20, in showHand print "the computer is showing a %d" % computer[0] IndexError: list index out of range |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help with a simple "dragon" game. | ddaigle | C++ Forum | 13 | 04-Dec-2007 07:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The