Computer Science Canada basic game |
Author: | gh0stz [ Tue May 16, 2006 3:49 pm ] | ||
Post subject: | basic game | ||
I'm reallly new to turing and I'm trying to make a blackjack game, I have the basic idea of what I'm going to do down, I just need to know if I can make the following code shorter.
basically, the first part is the dealer's cards, each proc represents a value of a card. After is a randint that selects a number from 1 to 11, if say 1 is selected, then it would run the dOne process, and set the value of the first dealer card to one. Is there any way I can make this shorter? |
Author: | gh0stz [ Tue May 16, 2006 3:53 pm ] |
Post subject: | |
i forgot to the meaning of the variables.. z and y identify which card it is that is being delt, so by default z/y = 0, then when i run the program and deal 2 cards, z/y gets added by 1, then 2. z is for dealer cards, and y is for player cards. a and x is the value of the card. so in dOne, a := 1, so the value that assigns dcard would be 1. a is for dealer cards, and x is for player cards. |
Author: | Clayton [ Tue May 16, 2006 4:10 pm ] |
Post subject: | |
you could do something like this [syntax="Turing] var cards:array 1..4 of int var card:int var count:=1 for x:1..4 card:=Rand.Int(1,11) cards(x):=card end for [/syntax] something as simple as that can work and in considerably less lines ![]() |
Author: | gh0stz [ Tue May 16, 2006 4:25 pm ] | ||
Post subject: | |||
omfg that was easy.. ![]() heres another one of the same problem that'll make me look like more of an ass. this code isn't done, but the basic structure is so...
as you can see its incrediblly long and tedious just like my last one... but hey i'm new ![]() so what i'm trying to accomplish with that is when the user says no to hitting, then it begins the dealer rounds. and in between the dealer hitting rounds, i have an if statement saying if dealer's cards total 17 or over, then the dealer can't hit anymore. If I were to finish it that way, i would have to repeat the above mentioned algorithim 5 times for every card that the player gets, and that is very long and probably repetitive. I'm pretty sure there's a way to manipulate this with for loops but I don't know how, so pleaseeee help meee ![]() |
Author: | TheOneTrueGod [ Tue May 16, 2006 4:29 pm ] |
Post subject: | |
I think he's aiming for a style where you can't wind up with 5 "fives" in the deck... This quesiton has been asked many times, and there is a search buggon on the top bar that will help you find help on it. I posted an answer similar to this in a question a few posts down, but i'll sum it up here. If you have an array of numbers from 0 to 51, each number can represent a card. 0 = two, 1 = three, 2 = four, ... , 12 = Ace to get the value of the card, you do: number mod 13. This will return a value between 0 and 12 (since there are twelve unique numbers in each deck). To get the suit, you just div the number by 13. (this will get you a value between 0 and 3) 0 = Spades 1 = Hearts etc... or whatever you want them to be. So basically, to get what the card "50" is: numerical value: 50 mod 13 suit value: 50 div 13 (This will give you the numbers 11 and 3, signifying the king of whatever you chose 3 to be) Now its easy to use the numbers 0 to 51 to represent unique cards. I'm sorry if you didn't understand this, but if you use the Search button above, you'll be able to find some better help on it. |
Author: | gh0stz [ Tue May 16, 2006 5:31 pm ] |
Post subject: | |
i think you misunderstood my question cus my code is so bullshit. i'm trying to reduce the number of "if" statements used in teh code now if you answered that in your response then i'm too bullshit to understand ![]() |
Author: | TheOneTrueGod [ Tue May 16, 2006 8:39 pm ] | ||
Post subject: | |||
Its a concept. If you apply that concept, you won't have to have a shitload of variables like
eugh... All you have to do is apply the concept I gave you, and you can reduce a blackjack game to possibly 100 lines ish. |