I went dictionary and function crazy.

K.V.

BLACKJACK

(not quite ready for Game Announcements and Feedback)


http://textadventures.co.uk/games/view/eyq1aez-s0kwdisyvm2_iw/blackjack

https://gist.github.com/KVonGit/baf7f01ac3302268623d08f6ced23b2c


If it's not too buggy, I'll add the betting functions to it.


I got a little crazy with dictionaries and functions, but this seems to be fairly functional.

I'm halfway done with VERSION 2, and I'm using objects for the hands this go-round. (I just wanted to see what all I could pull off with dictionaries.)

As far as all the functions go, there are just too many being called in some of the scripts sometimes, and sometimes things go haywire when my scripts get ahead of each other. (Version 2 is much better in this regard already. This was the first time I really got function happy, and I'm surprised it works at all!)


The library with all of the images for the cards is here:
https://gist.github.com/KVonGit/5e7ada71cdf6f66504438b6abcaa2c99

Everything says the card images are in the public domain.

It's all been converted to base64.

Feel free to use it.


If you want to display, say... the 10 of clubs, you could do something like this:

nm = StringDictionaryItem(card_images.img_dict, "10C")
pic = "data:image/png;base64,"+nm
msg("<image src='"+pic+"'  id='10C'  alt='the ten of clubs'  title='the ten of clubs' />")

the ten of clubs


image


K.V.

Hmm...

That Base64 image shows up in the preview of the post, but not in the actual post. (That's not fair.)


K.V.

PS

There are many flaws in this rough draft. (It's the first draft that worked.)

There are also many redundancies (I'm sure), and I rarely called FlipDowncard() at the right time.

I also just realized that it was silly of me to put the cards in the player's hand in the player's inventory, seeming how they're on the table and we're not allowed to pick them up. (Whoops. I said it wasn't even ready for Game Announcements and Feedback! (But the library with card images is pretty cool, right? ))


Me likey!


K.V.

Thank you, sir!


I dig your avatar, by the way.


Looks good, can always improve code, of course, but good 1st working version. Unfortunately, I don't know many card games, so I was only able to loosely look at the coding itself, and in the brevity, it looks really good. Lots of complexity/system, that you were able to code and get it working! That's the most important thing, it works, getting all the code to work together correctly, hehe.


K.V.

Thanks, HK!

(It works together most of the time. Ha-ha!)


K.V.

The thing that kicked my butt for the longest time:

  • The screen clears after every card is dealt in the blackjack game room.
  • (The screen also clears after a few functions, such as TallyBlackjackHand.)
  • I had a ShowMenu the player couldn't ignore set up after a deck shuffle (which was called automatically when the deck ran out of shuffled cards), asking the player to cut the cards.
  • The screen cleared after showing the menu, so you never even saw it. So, you'd never get a chance to select an option from it.
  • The game: Frozen.

It took me hours to figure out what was causing the game to freeze up.

I had the ShowMenu set up before I set the ClearScreen up, and I added quite a few functions at the same time I decided to add all the screen clearing.

Lessons learned (or re-learned):

  • Make a backup before editing.
  • Add one thing at a time, then test it out. If it works, save a backup, then add the next thing.
  • Rinse and repeat.

Just some thoughts. I know you are just getting a working copy together and you may know these things already but I am a long time casino blackjack player and could not resist piping in. These are just suggestions to keep in mind at this point.

  • A blackjack is 2 cards, an ace and a ten or face. When more than two cards are shown equaling 21, it is just a "21" not called a blackjack.
  • Needs double down feature? Didn't see one.
  • Doesn't need to ask if you want to play every time. It's why you're there, if I want to stop, I will. Just have a "Deal" button.
  • You can split any two cards that are the same value. An equal bet is placed on the other hand. You then get only one card on the first hand and offered any options available(split again or double down) other than that you can't hit again. Then you are given one card on the second hand and offered any options available, if none, that is the only card you get. (I never got two of the same when playing so I don't know if you had this.)
  • Have a permanent note at the top stating whether the dealer stays or hits a soft 17, maybe giving an option for either at start.

Again these are just reminders so you don't get to far into scripting and have to go back and rewrite. I have spent an easy million dollars over the years learning the game. I learned you always lose if you leave the casino down. Then, I spent several years living 5 minutes from a casino 6 years ago and earned enough to live on. Up until automatic shufflers came along. Plus they break up play by changing dealers, cards, or adding chips. Anything to cause a card to be pulled from the deck and put in the dead pile, changing the Shoe. Of course, this is using multiple decks, but it still changes things in a single deck game. Mainly my demeanor.

Love the game. This script will make a great "Magic, the gathering", D&D, card game. Or any other game for that matter.


K.V.

Hey, thanks!

I've only won a few hundred bucks a few different times, and I was just about to ask if anyone had any suggestions.


So a blackjack is only on a soft handthe initial deal (or a split)... That's easy to fix.


I've got a double-down script written. I just haven't updated what I've got online yet.

(Plus, it's screwy. It doesn't show up sometimes. I'm whittling away at some functions right now, too.)


I've got it asking if you want to play again because I'm planning on dropping this into my Gambling Hall game, which has a craps game that's set up much like this one.

Initially, I was going to have it where you always had access to a slot machine, craps, blackjack, or poker, but I've got it set up so a table is a room right now (which would make it easier to keep up with the players if NPCs were thrown in).

Now the plan is to throw you back into the main room of the casino after each hand is over, and you can just throw another chip on the table, or enter DEAL or PLAY #whatever#, or just talk to whatever dealer to initiate another hand (or game, or what have you).


I've got the split set up, but I didn't know you couldn't hit after you split. That is very useful information!

You can only split four times. (I may have made that rule up. Is that a thing?)


I was thinking of adding a soft_seventeen attribute on the blackjack_game object, so that could be toggled, but the dealer stays at the moment.


I also need to add a script to allow the player to cut the cards after they're shuffled. (And can't a shuffle be requested?)


There's a string list that keeps track of wins. I plan to have a dealer switch every so often. It might not effect play, though. Simply cosmetic, so to speak.


I wanted to have at least two decks, but I'm scared to mess with that right now.


This is what version 2 looks like right now:

image


I do appreciate suggestions!

Keep 'em coming, if you've got 'em!


K.V.

I am not 100% on the dealer's aces...

If it doesn't make him bust, it must be counted as 11, I think. (At least for the first two cards, right?)

Then...

Ugh...

Doesn't it work pretty much like the player's hand, except the dealer doesn't get to pick?

Like:

if (hand_value < 17) 
  all_aces = 11
  if (hand_value>21) 
    reduce one ace to 1
    if (hand_value>21)
      reduce the next ace to 1
... 

  • If you split aces you only get one card, period.
  • Normally, in a split, if the player hand equals 21 on the second card, it is considered a 21 not a blackjack. However, house rules can vary. If player gets an ace added to a 10 that he split, it is a 21, but technically can double down if he wants to. Not advisable but he can. If he gets a ten on a split ace that's the end of play on that hand.
  • You can only split four times. However, house rules can vary.
  • In the dealer's hand, the ace will count as 11 until dealer hand at least equals 17. Then house rule on soft, if 17.
  • Dealer will hit under 17. Even if you stand on 14, he has to hit until he hand at least equals 17, either soft or hard. Then house rule on soft, if 17.
  • Double down can only be called on first two cards only.

Having buttons for hit, stand, split or double down or any of player options like leave table (taking you to casino floor with other gaming options) would look nice.


something that you can do instead of having it ask every time if you want to continue or quit:

ask at the very beginning (thus only once) of a playing 'session' (choosing to play the blackjack game), for the players/users to enter how many games they want to play, and have scripting to handle it, of course. When the number of games entered, have been played, the 'session' ends. They can, then of course play again, being asked how many games they want to play, for this new 'session' of playing.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums