Blackjack game implementation on Choicescript

l am starting coding a Blackjack against a crupier i am starting with a loop until reach 16 to crupier. But Has anyone any advice as I am starting to panic

1 Like

I wish you good luck, I think it is a really difficult programming Quest without an Array. I guess the most difficult thing will be the part where No number could come Up more than four, maybe eight Times, based in the number of participants. I will try to think about that while at Work.

2 Likes

what I am doing quite unpractical is randomize each card throw only allowing each value use 4 times when goes 4 make it false…
Online all is java and python programming. Thing I have no idea but strangely have very logical commands to randomize and sort of stuff.

1 Like

I actually did a blackjack implementation on CS. I can post it here later when I get back from work, should help you out.

3 Likes

When checking for the four don’t forget the picture cards, do you Count them as ten or as 2,3 and 4?

1 Like

You could be a life saver… :hugs: As for now is working the two first cards. BUT MY CODE IS 1,000 WORDS ALREADY… so it is inefficiently as hell. And I can end with the Bible
I count 4 as 4.
And let player choose ace be 11 or 1

2 Likes

@Carlos.R would be a good one to chime in here, given his skill at coding CS versions of real life games like this.

2 Likes

Sincerely. I think should be a base code for classic games as blackjack and similar used games that writers could use as template. Sadly my levels of coding aren’t stellar but if I end something is working I would make it public and hope others as well.

Imagine if Any wip writer could check in wiki for templates to code no copyrighted games. That could by itself made authors adding mini games that could as well helping rich games for players.

I am also planning to do a tarot reading because is a party what I planning right now where player could choose some stuff like dices blackjack and tarot.

1 Like

Sounds like an interesting project. I’ve never tried anything quite as complex as that in CS. Not something I can really help with, I have no idea of the rules of that game.

What I would say though is, if you’re doing this from scratch, get it all plotted out on a flowchart first. I use yEd for that, it’s a completely free diagramming program. Trying to do this sort of thing on the fly, or by the seat of the pants, is likely to result in a war and peace size chunk of difficult to debug spaghetti code.

Anyway, good luck :wink:

2 Likes

What I am doing is planning code totally separated from anything else with no other variable or scene and only focus in achieve cards mechanics work as intended.

Is the basic calculus and proper planning.

If the basic dynamic of scene doesn’t work … I can’t even dream add anything more complex.

I had already code a battle system with HP critical hits. But the fact several values can’t be repeated is making my head explode.

Except using long code totally inefficiently. So that’s why I asked as I really think a template of games could be so practical for Wips

1 Like

@Elena_H has a pretty solid blackjack game in Donor. Maybe they can provide some pointers?

3 Likes

The version I did is quite simple, I only intended it to be a short minigame the player could play with the companion characters and they would sometimes say random comments during the game. There might still be some bugs around since I did this while I had free time at work a long time ago.

All it does is randomize a card between 1 and 9 for the player and AI each turn. At any point the player or AI can decide to “stand” with their values (I think I set the AI to stand only from 17 and up, unless the player has a higher number). If anyone reaches 21 they automatically stand. If anyone goes past 21 they will lose.

After that the game ends and it can be played again. Just create a new CS project and copy and paste the entire code below as the startup.txt:

Code
*title Blackjack
*author GS

*create implicit_control_flow true

*temp wins_player 0
*temp wins_opponent 0
*temp ties 0
*temp player_total 0
*temp player_draw 0
*temp player_21 false
*temp opponent_21 false
*temp opponent_total 0
*temp opponent_draw 0
*temp player_lock false
*temp opponent_lock false
*temp game_over false
*temp game_over_type ""

*label start

*choice
	#Blackjack.
		*gosub blackjackGame
		*goto start
	#Quit.
		*finish

*comment --------------Blackjack--------------
*label blackjackGame
*page_break
*rand player_draw 1 8
*rand opponent_draw 1 8

@{player_lock As you stand, you wait for the opponent to pick his next card...|You click to pick up your next card...}
*page_break
*gosub blackjackTotalScore
*if (player_21)
	Since you are at [b]21[/b] you hold and wait for your opponent's turn.
	*line_break
*elseif (player_lock)
	Having stood at [b]${player_total}[/b], you wait for your opponent's move.
	*line_break
*else
	*set player_total +player_draw
	You drew [b]${player_draw}[/b] in this round.
	*line_break
Your current amount: [b]${player_total}[/b].
*gosub blackjackGameChecks
*if (game_over)
	*goto jackover


====================================================


*if (((opponent_lock) and (player_lock = false)) and ((player_total > opponent_total) and (player_total <= 21)))
	*set game_over true
	*set game_over_type "won"
	*goto jackover
*elseif ((opponent_21) and (player_lock = false))
	The opponent reached [b]21[/b] so they wait for your turn.
	*line_break
*elseif (((opponent_total <= 21) and (opponent_total > player_total)) and (player_lock))
	*set game_over true
	*set game_over_type "lost"
	*goto jackover
*elseif (((opponent_total >= 17) and (opponent_total < 21)) and (player_total <= opponent_total))
	*set opponent_lock true
	Your opponent decides to stand.
	*line_break
*elseif (opponent_lock)
	Your opponent waits your next move.
	*line_break
*else
	*set opponent_total +opponent_draw
	Your opponent drew [b]${opponent_draw}[/b] in this round.
*line_break
Your opponent's amount: [b]${opponent_total}[/b].
*line_break
*gosub blackjackGameChecks
*if (game_over)
	*goto jackover
*elseif ((player_21) or (player_lock))
	*goto blackjackGame
*else
	*choice
		#Draw card.
			*goto blackjackGame
		#Stand.
			*if (player_total < opponent_total)
				*set game_over true
				*set game_over_type "lost"
				*goto jackover
			*else
				*set player_lock true
				*goto blackjackGame
*label jackover
*line_break
The game is over. You ${game_over_type}.
*if (game_over_type = "lost")
	*set wins_opponent +1
*elseif (game_over_type = "won")
	*set wins_player +1
*else
	*set ties +1
*choice
	#Play again.
		*set opponent_total 0
		*set player_total 0
		*set player_21 false
		*set player_lock false
		*set opponent_21 false
		*set opponent_lock false
		*set game_over false
		*set game_over_type ""
		*goto blackjackGame
	#Leave.
		*return

*comment ---------Blackjack checks-------
*label blackjackGameChecks
*if (player_total > 21)
	*line_break
	*set game_over true
	*set game_over_type "lost"
	*return
*elseif (opponent_total > 21)
	*line_break
	*set game_over true
	*set game_over_type "won"
	*return
*elseif (((player_lock) and (opponent_lock)) and (player_total = opponent_total))
	*set game_over true
	*set game_over_type "tied"
	*return
*elseif ((player_21) and (opponent_21))
	*set game_over true
	*set game_over_type "tied"
	*return
*elseif (player_total = 21)
	*set player_21 true
	*return
*elseif (opponent_total = 21)
	*set opponent_21 true
	*return
*else
	*return

*comment ------------Show total score----------
*label blackjackTotalScore
[b]Total score[/b]

You: [b]${wins_player}[/b].
*line_break
Opponent: [b]${wins_opponent}[/b].
*line_break
Ties: [b]${ties}[/b].


====================================================


*return

*comment ajustar quando ambos chegam ao 21, oponente ainda ta jogando - Incerto
*comment inimigo sempre parando entre 17 e 21 - Corrigido
*comment empate com problema - Corrigido
3 Likes

I ended with something similar but rather clunky due I added too much variants with suits and stuff that makes my head ache… But yours is really helpful. I will put mine when is totally done in case later someone wants see codes for games and have a look to others code is really valuable.

2 Likes