Computer Science Canada help with my blackjack game |
Author: | Biohazzrd [ Wed Apr 05, 2006 6:09 pm ] |
Post subject: | help with my blackjack game |
ok you know in blackjack ach card can only be dealt once but on the computr with random integers it picks the same one over and over. I know I need a boolean variable for each card do decide wether they have been use. But I don't know how to set it up to record that. |
Author: | Clayton [ Wed Apr 05, 2006 6:18 pm ] | ||
Post subject: | |||
you could make a seperate array of booleans to match the one im assuming you are using for your cards, it could look something like this
|
Author: | Clayton [ Wed Apr 05, 2006 6:19 pm ] |
Post subject: | |
oops got a little happy with the submit button, but anyways, use something like that and put it into your code and see if it works good luck |
Author: | Cervantes [ Wed Apr 05, 2006 7:35 pm ] | ||
Post subject: | |||
Arrgh! It's contagious! Parallel arrays are not the way to go here. The next step up from parallel arrays is to use an array of a user defined data type. It's the same thing, in that you get both your int variable and your boolean variable, but the corresponding values are bound together. You don't have to trust that each of your two arrays stays in the same order for your data to be correct.
Alternatively, you can make a stack of cards. Dealing them out is as simple as popping a card off the top of the stack. Doing so removes it from the stack. Edit: spelling. |
Author: | TokenHerbz [ Wed Apr 05, 2006 7:43 pm ] | ||
Post subject: | |||
i like cervantes way, but if im sure this would work too :S its more sloppy, and probable more confusing, but i want to post it anyways:
i recommend doing it like cervantes said. |
Author: | Biohazzrd [ Wed Apr 05, 2006 7:51 pm ] | ||
Post subject: | |||
thanks but i'm just wondering if this would work
|
Author: | Biohazzrd [ Wed Apr 05, 2006 7:55 pm ] |
Post subject: | |
and the cardDeal variablee is part of my randint part and that works |
Author: | Cervantes [ Wed Apr 05, 2006 8:16 pm ] | ||||
Post subject: | |||||
Biohazzrd wrote:
Oh my... You didn't. How about replacing those 104 lines with 1:
|
Author: | Clayton [ Thu Apr 06, 2006 5:26 pm ] |
Post subject: | |
ok i only gave him the idea for parallel arrays because it seemed like a simpler idea for a newer person at Turing |
Author: | Biohazzrd [ Sun Apr 09, 2006 10:00 pm ] |
Post subject: | |
so cervantes ur saying that if i replace the code i showed u with that one lime then when ever a card gets played its corresponding boolean will turn to true |
Author: | [Gandalf] [ Sun Apr 09, 2006 10:10 pm ] |
Post subject: | |
Yes. Think about how the program would progress, step by step. If cardDeal is 4, then you want cardFind (4) to equal true. So therefore you need cardFind (cardDeal) to be true. |
Author: | Biohazzrd [ Sun Apr 09, 2006 10:26 pm ] | ||
Post subject: | |||
ok thanks and i have some hting else that doesnt seem to work
|
Author: | Biohazzrd [ Sun Apr 09, 2006 10:29 pm ] |
Post subject: | |
this is supposed to make it hit until it picks a card that has not been played (or = true) |
Author: | Clayton [ Mon Apr 10, 2006 12:59 pm ] | ||||
Post subject: | |||||
Biohazzrd wrote: ok thanks
and i have some hting else that doesnt seem to work
omg u didnt do that again, shorten it to something like this
|
Author: | codemage [ Mon Apr 10, 2006 1:34 pm ] |
Post subject: | |
You know, that actually hurts, physically, when you use redundant code like that. Like how it hurts, physically, when you redundantly punch someone in the face. It's the same pain. ![]() |
Author: | Andy [ Mon Apr 10, 2006 1:35 pm ] |
Post subject: | |
lol.. i'd love to see the face his teacher makes after he hands in this code... |
Author: | Delos [ Mon Apr 10, 2006 4:10 pm ] | ||
Post subject: | |||
Cervantes wrote: Oh my... You didn't. How about replacing those 104 lines with 1: Code: cardFind (cardDeal) := true SuperFreak82 wrote: omg u didnt do that again, shorten it to something like this
Doesn't seem to listen very well, does he? |
Author: | MysticVegeta [ Mon Apr 10, 2006 6:00 pm ] |
Post subject: | |
Andy wrote: lol.. i'd love to see the face his teacher makes after he hands in this code...
Dont worry he wont hand that in, yu guys are too good to let him hand in redundant code ![]() |
Author: | Cervantes [ Mon Apr 10, 2006 6:11 pm ] | ||||
Post subject: | |||||
Is this some sort of joke? Should we move it to the Evidence forum? Really: I can understand how someone might start down that path, but I can't believe that someone would type out over a hundred lines of the same thing and not see a pattern. Oh, and by the way: SuperFreak82 wrote:
That's equivalent to the following:
If it was not true when the initial condition was evaluated, it has to be false. |
Author: | Clayton [ Mon Apr 10, 2006 6:11 pm ] |
Post subject: | |
Biohazzard, the whole point we are trying to help you with is condensing your code. not only would your code have taken forever, but it is pointless, why hardcode everything when you can make something much more dynamic. if you are having trouble with condensing your code, look through the Turing Walkthrough to check some things out. remember, if you are copying or pasting more than 2 times(and only a couple lines of code), find a shorter way to code it. |
Author: | Clayton [ Mon Apr 10, 2006 6:13 pm ] | ||||
Post subject: | |||||
Cervantes wrote: Is this some sort of joke? Should we move it to the Evidence forum? Really: I can understand how someone might start down that path, but I can't believe that someone would type out over a hundred lines of the same thing and not see a pattern.
Oh, and by the way: SuperFreak82 wrote:
That's equivalent to the following:
If it was not true when the initial condition was evaluated, it has to be false. ya i know i was just kind of in a hurry when i typed that up (it was a 10 minute break at school lol) btw the double post happened cuz u posted while i was posting |
Author: | Biohazzrd [ Mon Apr 10, 2006 6:26 pm ] |
Post subject: | |
ya ok i've learned i got like 300 lines into 16 lines it pulls out a random card, puts that random card if it hasent been played and adds the cards value to the player total |