PDA

View Full Version : Blackjack


OddOstrich
05-11-2014, 08:41 PM
Ignore the blurry image, here's a link to the image: http://i.imgur.com/5hJuG7M.png

I am trying to make an interactive Blackjack game in Alice 3.

The top picture shows the code that is able to deal cards to the two players, however it cannot identify the value of each cards.

In the bottom picture, I try to fix this by putting each set of cards into different arrays, but can't find a way to put all the arrays into another array so I could just use that array to deal...

I also am having trouble understanding how the eventlisteners work. I added an event that states if H is pressed to run the procedure called "hitMe" which will deal a new card to the next thingMarker. However, the variables keep resetting every time H is pressed so the cards keep moving to the same thingMarker.

My questions:
Is there anyway to put an array of objects(Billboards) into an array of whole numbers?
How can I assign numerical values to objects?
Is there a way to assign global variables?

jrrTolkien
05-12-2014, 09:37 AM
Could you please post your Alice world? It makes it much easier to fix it when you have the whole program. Also, what do you want fixed , exactly?

chickentree
05-12-2014, 02:10 PM
Ignore the blurry image, here's a link to the image: http://i.imgur.com/5hJuG7M.png

The top picture shows the code that is able to deal cards to the two players, however it cannot identify the value of each cards.

In the bottom picture, I try to fix this by putting each set of cards into different arrays, but can't find a way to put all the arrays into another array so I could just use that array to deal...

Been trying to figure this out for the better part of a weekend. Any help is appreciated.

The easiest way to do this is to just use numbers 0 - 51 and then define you suites as being Hearts 0-12, Clubs 13-25, Diamonds 26-38 and Spades as 39-51. So your sorted deck starts out as value = index. This lets you just work with the numbers 0 to 51 for most of the program while being able to convert the number to the card name string when needed.
To do that I would use an array of strings and use the cards value as an index. So if you had the card 23 you could get the string in your name array at index 23 and it would (hopefully) be the Jack of Clubs. To determine what suite a card is you can just divide by 13 and take the integer part of the result, 0 for hearts, 1 for clubs ...

Hope this helps
Mark

OddOstrich
05-12-2014, 02:23 PM
Could you please post your Alice world? It makes it much easier to fix it when you have the whole program. Also, what do you want fixed , exactly?

Using my library's computer to post here, I'll post the image of my world when I get home. But really it's just a table with a deck of cards and thingMarkers where the cards will be dealt to for each player.

I have been thinking more and more about my problem, and everything could be solved if I knew how to assign values to objects. In this case, how do I, for example, assign the value 2 to all the twos(clubs, diamonds, hearts, spades) in the deck and so on for all the other cards.

The easiest way to do this is to just use numbers 0 - 51 and then define you suites as being Hearts 0-12, Clubs 13-25, Diamonds 26-38 and Spades as 39-51. So your sorted deck starts out as value = index. This lets you just work with the numbers 0 to 51 for most of the program while being able to convert the number to the card name string when needed.
To do that I would use an array of strings and use the cards value as an index. So if you had the card 23 you could get the string in your name array at index 23 and it would (hopefully) be the Jack of Clubs. To determine what suite a card is you can just divide by 13 and take the integer part of the result, 0 for hearts, 1 for clubs ...

Hope this helps
Mark

I am sorry, I should have elaborated on what I was trying to do. I am making an interactive game of Blackjack in Alice 3. So I need to find a way for the computer to identify the value of each card. In Blackjack, card suites are irrelevant. Thank you for answering anyway, it's something helpful to know if I decide to remake Spades.