
-----------------------------------
Dllsys32
Tue Jan 09, 2007 5:51 pm

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.

-----------------------------------
Tony
Tue Jan 09, 2007 6:10 pm

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
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 :)

-----------------------------------
Dllsys32
Tue Jan 09, 2007 6:30 pm

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
Tue Jan 09, 2007 6:49 pm

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:
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)
end fcn

When complete, you can use that function like this:

f getChoice ("yes", "no") then
put "Let's Begin!"
else
put "hope to play with you soon!"
end if

-----------------------------------
Clayton
Tue Jan 09, 2007 6:52 pm

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
Tue Jan 09, 2007 7:00 pm

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
Tue Jan 09, 2007 7:04 pm

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
Tue Jan 09, 2007 7:09 pm

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.

-----------------------------------
Dllsys32
Tue Jan 09, 2007 7:19 pm

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
Tue Jan 09, 2007 10:42 pm

Re: 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?
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
Tue Jan 09, 2007 11:44 pm

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...

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

randint (num, 1, 13) %randomly picks a card
randint (suit, 1, 4)

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

likefor 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
Wed Jan 10, 2007 12:21 am

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------

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

randint (num, 1, 13) %randomly picks a card
randint (suit, 1, 4)

if cards (num, suit) = 1 then % if it's available then
    cards (num, suit) := 0 %make it 'unavailable' to draw again
end if


your 2D array would be better suited to using booleans instead of integers (as you only have two options, available and unavailable)


var cards : array 1 .. 13, 1 .. 4 of boolean

for i : 1 .. 13
    for j : 1 .. 4
        cards (i, j) := true
    end for
end for

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:


var cards : array 1 .. 52 of
    record :
        value : int
        suit : int
        picked : boolean
    end record

for i : 1 .. 4
    for j : 1 .. 13
        cards(i * j).value := j
        cards(i * j).suit := i 
        cards(i * j).picked := false
    end for
end for

cards(Rand.Int(1, 52)).picked := true


:D
[/syntax]

and work from there

-----------------------------------
Dllsys32
Wed Jan 10, 2007 8:14 am

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
Wed Jan 10, 2007 3:16 pm

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
Wed Jan 10, 2007 4:42 pm

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:
if true then
    put "This will appear on the screen."
end if

if false then
    put "Obviously, this will not appear on the screen."
end if

Now apply that knowledge to boolean variables. Since they contain either true or false you can use them in if statements:

var somethingChanged : boolean

if somethingChanged then

end if

%Instead of:
if somethingChanged = true then

end if

Boolean variables also increase the readability of your code:

fcn collision (object1, object2 : ObjectType) : boolean
    result %collision conditions
end collision

if collision (object1, object2) then

end if

As compared to integers, setting there value based on a condition is a lot easier and shorter as well:

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
end if

You can look into [url=http://www.compsci.ca/v3/viewtopic.php?t=9893]zylum's tutorial on Bitwise Operators for more information about how this works on a machine level.

-----------------------------------
Dllsys32
Wed Jan 10, 2007 7:45 pm

RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
-----------------------------------
Alright new problem, how do I import pictures into my program (I need to do that in order to use the array stuff).

-----------------------------------
ericfourfour
Wed Jan 10, 2007 8:00 pm

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------
Look up the Pic module in Turing help. Specifically look up Pic.FileNew and Pic.Draw. If you have any trouble with it just ask. :)

-----------------------------------
Dllsys32
Wed Jan 10, 2007 8:07 pm

RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
-----------------------------------
I looked it up and it doesn't make any sense at all (Bare with me I haven't learned how to do this yet).

EDIT: Ok it makes sense now, but I have to make four arrays one for each suit right?

-----------------------------------
ericfourfour
Wed Jan 10, 2007 9:07 pm

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------
Yes an array of each suit (4X13) will work well.

This is just another way of doing it using enums:
type suit : enum (hearts, diamonds, clubs, spades)
type value : enum (ace, one, two, three, four, five, six, seven, eight, nine,
    ten, jack, queen, king)

type card :
    record
        picked : boolean
    end record

type deck : array value, suit of card

fcn fillDeck (picked : boolean) : deck
    var cards : deck

    var currentValue : value := value.ace
    var currentSuit : suit := suit.hearts
    loop
        cards (currentValue, currentSuit).picked := picked

        if currentValue = value.king then

            exit when currentSuit = suit.spades

            currentValue := value.ace
            currentSuit := succ (currentSuit)

        else
            currentValue := succ (currentValue)
        end if
    end loop

    result cards
end fillDeck

var cards : deck

cards := fillDeck (false)

-----------------------------------
Dllsys32
Wed Jan 10, 2007 10:18 pm

RE:Really need help with this blackjack program I\'m trying to make (I\'m a nub ;_;)
-----------------------------------
Never heard of enums XD

-----------------------------------
ericfourfour
Wed Jan 10, 2007 10:49 pm

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------
Don't worry about it, stick to arrays for this one. It should be easier.

-----------------------------------
Dllsys32
Thu Jan 11, 2007 6:38 pm

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------
I have a new problem (finally got back to this) when I try to run the program it says "Too few subscripts of 'card_array'" What does that mean?


card_array (1) := Pic.FileNew ("c1.bmp")
card_array (2) := Pic.FileNew ("c2.bmp")
card_array (3) := Pic.FileNew ("c3.bmp")
card_array (4) := Pic.FileNew ("c4.bmp")
card_array (5) := Pic.FileNew ("c5.bmp")
card_array (6) := Pic.FileNew ("c6.bmp")
card_array (7) := Pic.FileNew ("c7.bmp")
card_array (8) := Pic.FileNew ("c8.bmp")
card_array (9) := Pic.FileNew ("c9.bmp")
card_array (10) := Pic.FileNew ("c10.bmp")
card_array (10) := Pic.FileNew ("c11.bmp")
card_array (10) := Pic.FileNew ("c12.bmp")
card_array (10) := Pic.FileNew ("c13.bmp") 

Also I understand how to make the rand.int I just don't know why it doesn't show up when I try to run (it doesn't pick a number or even run at all).

-----------------------------------
ericfourfour
Thu Jan 11, 2007 9:20 pm

Re: Really need help with this blackjack program I'm trying to make (I'm a nub ;_;)
-----------------------------------
Look at where you declare the card array. Does it range from 1 - 13?

Two more things.

You assign the a different picture id to the same card 3 times here. That is a quick fix. :)
card_array (10) := Pic.FileNew ("c11.bmp")
card_array (10) := Pic.FileNew ("c12.bmp")
card_array (10) := Pic.FileNew ("c13.bmp")

Also, I'm sure you have noticed, both the index and the card share the same number: card_array (1) := Pic.FileNew ("c1.bmp"). Don't you wish there was a way you could convert an integer to a string so you could assign all of these cards in 3 lines using a for loop? Well there is actually. It is called intstr. I'll give you an example of it being used:
for i : 1 .. 10
    put "This is number " + intstr (i) + "."
end for
instr converts an integer to a string so you can use it in calculations that require strings.
