Posted: Tue Jan 09, 2007 5:51 pm Post subject: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
OK so i'm in Gr.10 and this is my first year of turing and we just got a huge assignment on making a blackjack program. I'm making the flowchart for it right now using the rules of blackjack with the doubledown and stuff but I am really having trouble starting it off.
Some stuff I need help with ;
how many variables will I need? (I'm guessing one for every card plus your current score, one for the dealer's cards and the dealer (when he is allowed to hit and so on), one for when you surrender, doubledown, stand or hit and some other's)
How do I get pictures into the program?
How will I use the randint statement?
How will I get a variable to be represented by a card on screen?
I have so many other questions but I just want to know if someone can help me with these few questions as random as they are. I'm not asking anyone to do my homework or something like that but I really need help.
Sponsor Sponsor
Tony
Posted: Tue Jan 09, 2007 6:10 pm Post subject: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
You could always add more variables as needed, don't limit yourself to a set number.
Though it will probably make your life much easier to represent the cards involved as elements of an array. This way you can access cards as card[1], card[2], card[x]
For pictures you use the Pic. module
randint assigns a random value to a variable, although it's depressiated and the prefered method is
code:
value := Rand.Int(low,high)
If you know the value of the card, you can then load a picture by the same name and use that on screen.
Otherwise check out the Turing Walkthrough, Tutorials, and continue asking specific questions. You're doing well so far, welcome
Posted: Tue Jan 09, 2007 6:30 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
if answer = "yes" then
put "Let's Begin!"
elsif answer = "no" then
put "hope to play with you soon!"
end if
I read the if elsif and else tutorial over on the tutorial board and I thought that this would work (just started an already an error) and it says "Operands of comparison must be of the same type". What does that mean?
Also thank you for the help I'm going to check out the walkthrough and array tutorial now.
ericfourfour
Posted: Tue Jan 09, 2007 6:49 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
That means answer is not a string.
One (rhetorical) question, how many times will you be in a situation that needs a "yes" or "no" answer, or a "true" or "false" answer? Many times obviously. Because of this I recommend making a function to deal with this situation. I'll get you started:
Turing:
fcn getChoice (trueChoice, falseChoice :string):boolean %(get input make sure it is valid) result%(if the user entered the true choice make it return true, if the user entered the false choice make it return false) endfcn
When complete, you can use that function like this:
Turing:
f getChoice ("yes", "no")then put"Let's Begin!" else put"hope to play with you soon!" endif
Clayton
Posted: Tue Jan 09, 2007 6:52 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
it means that answer is not the same type as your comparison, in this case, answer is not a string, like the comparison is.
Dllsys32
Posted: Tue Jan 09, 2007 7:00 pm Post subject: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
Thank you ericfourfour and freakman for your help on that problem.
Unfortunately ericfourfour I have no clue what "fcn" is I don't really have that great of a teacher, also we haven't learned arrays yet so I don't think I will use them.
Also I how do you get it to go to a new page (make the same one blank again only this time with 2 cards for you 2 for the computer one facing up other facing down and a put statement)?
Dllsys32
Posted: Tue Jan 09, 2007 7:04 pm Post subject: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
One last thing (sorry for the double post) if I wanted to use array how would I make it so it would be a random element?
ericfourfour
Posted: Tue Jan 09, 2007 7:09 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
Blackjack can be made without arrays. It will just be overly difficult to do. I recommend looking up the arrays tutorial. Functions ("fcn" or "function") are also a very important concept and looking into them will greatly benefit you.
Sponsor Sponsor
Dllsys32
Posted: Tue Jan 09, 2007 7:19 pm Post subject: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
Well I looked at the tutorials just in case you said that and was hoping you can answer that question (thank you in advance).
(How come you appear offline?)
ericfourfour
Posted: Tue Jan 09, 2007 10:42 pm Post subject: Re: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
Dllsys32 @ Tue Jan 09, 2007 7:04 pm wrote:
One last thing (sorry for the double post) if I wanted to use array how would I make it so it would be a random element?
Do you mean you want to select a random element? If that is the case combine your knowledge of selecting an array's element and getting a random number.
Piro24
Posted: Tue Jan 09, 2007 11:44 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
I'm in my first year of Turing as well and I was actually just thinking of making a blackJack game myself. I started but I found it way too hard (or I was lazy - or a mix).
What I thought of for my game was to make a 2d array which held all of the cards and you could choose from randomly.
Ex. 1 - 13 is value of card, 1-4 is suit...
code:
var cards : array 1 .. 13, 1 .. 4 of int
var num, suit : int := 0
for i : 1 .. 13 %1 represents an 'available card'
for j : 1 .. 4
cards (i, j) := 1
end for
end for
if cards (num, suit) = 1 then % if it's available then
cards (num, suit) := 0 %make it 'unavailable' to draw again
end if
You should make the random card chooser and eliminator a function you can repeat. Since suit has no relavence in Blackjack, you could add another variable (to make things easier to understand) like 'cardValue'. It would be = to your randint (num). 1 being an ace...13 a king.
If you want to draw cards, I thought make you could make a case in a for loop
like
code:
for i : 1 .. 4
if suit = i then
case card of
label 1 :
Pic.Draw ("Ace" + i + ".JPG")
label 2 :
Pic.Draw ("Two" + i + ".JPG")
end if
end case
end for
You would just have to name your pictures to like "Two3". Two representing the value, 3 representing the suit. Those are just really basic basic concepts I thought 'might' work...But again I'm new as hell to Turing or programming for that matter, so I doubt this holds much validity...But I gave it a shot.
Clayton
Posted: Wed Jan 10, 2007 12:21 am Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
Turing:
var cards :array1.. 13, 1.. 4ofint var num, suit :int:=0
for i :1.. 13%1 represents an 'available card' for j :1.. 4
cards (i, j):=1 endfor endfor
randint(num, 1, 13)%randomly picks a card randint(suit, 1, 4)
if cards (num, suit)=1then% if it's available then
cards (num, suit):=0%make it 'unavailable' to draw again endif
your 2D array would be better suited to using booleans instead of integers (as you only have two options, available and unavailable)
Turing:
var cards :array1.. 13, 1.. 4ofboolean
for i :1.. 13 for j :1.. 4
cards (i, j):=true endfor endfor
cards (Rand.Int (1, 13), Rand.Int (1, 4)):=false%card has been picked randomly
or even better, you can make that a record of cards:
Turing:
var cards :array1.. 52of record:
value :int
suit :int
picked :boolean endrecord
for i :1.. 4 for j :1.. 13
cards(i * j).value := j
cards(i * j).suit := i
cards(i * j).picked :=false endfor endfor
cards(Rand.Int(1, 52)).picked :=true
[/syntax]
and work from there
Dllsys32
Posted: Wed Jan 10, 2007 8:14 am Post subject: RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
You guys are amazing thank you for your help! (I have more questions but I am going to school now)
Piro24
Posted: Wed Jan 10, 2007 3:16 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
Just out of curiosity, what's the benefit of using boolean anyways?
ericfourfour
Posted: Wed Jan 10, 2007 4:42 pm Post subject: Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
A boolean is a variable that is either true or false, 1 or 0. It only occupies 1 bit and is therefore more efficient to use. If you have ever used an if statement, you would have realized that it code only executes if the condition is true.
Try this:
Turing:
iftruethen put"This will appear on the screen." endif
iffalsethen put"Obviously, this will not appear on the screen." endif
Now apply that knowledge to boolean variables. Since they contain either true or false you can use them in if statements:
Turing:
var somethingChanged :boolean
if somethingChanged then
endif
%Instead of: if somethingChanged =truethen
endif
Boolean variables also increase the readability of your code:
Turing:
fcn collision (object1, object2 : ObjectType):boolean result%collision conditions end collision
if collision (object1, object2)then
endif
As compared to integers, setting there value based on a condition is a lot easier and shorter as well:
Turing:
var oldSpeed, newSpeed :real var speedChanged :boolean ...
speedChanged = oldSpeed not= newSpeed
%As compared to: var oldSpeed, newSpeed :real var speedChanged :int ... if oldSpeed not= newSpeed then
speedChanged :=1 else
speedChanged :=0 endif