-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackjack.bat
118 lines (84 loc) · 2.41 KB
/
blackjack.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@echo off
title Blackjack Game
set /a deck[1]=11, deck[2]=2, deck[3]=3, deck[4]=4, deck[5]=5, deck[6]=6, deck[7]=7, deck[8]=8, deck[9]=9, deck[10]=10, deck[11]=10, deck[12]=10, deck[13]=10
set /a player_total=0
set /a dealer_total=0
:shuffle
cls
echo Shuffling the deck...
for /l %%i in (1,1,5) do (
set /a rnd1=%random% %% 13 + 1
set /a rnd2=%random% %% 13 + 1
set /a temp=deck[%rnd1%]
set deck[%rnd1%]=deck[%rnd2%]
set deck[%rnd2%]=%temp%
)
pause
:deal
cls
echo Dealing the cards...
set /a player_total=0
set /a dealer_total=0
set /a rnd1=%random% %% 13 + 1
set /a rnd2=%random% %% 13 + 1
set /a player_card1=deck[%rnd1%]
set /a player_card2=deck[%rnd2%]
set /a player_total=%player_card1% + %player_card2%
echo Your cards: %player_card1% %player_card2% (Total: %player_total%)
set /a rnd1=%random% %% 13 + 1
set /a rnd2=%random% %% 13 + 1
set /a dealer_card1=deck[%rnd1%]
set /a dealer_card2=deck[%rnd2%]
set /a dealer_total=%dealer_card1% + %dealer_card2%
echo Dealer's cards: %dealer_card1% ? (Total: ?)
pause
:player_turn
cls
echo Your turn...
if %player_total% equ 21 (
echo Blackjack! You win!
goto end_game
)
echo Your cards: %player_card1% %player_card2% (Total: %player_total%)
set /p choice=Do you want to hit or stand?
if "%choice%" equ "hit" (
set /a rnd1=%random% %% 13 + 1
set /a player_card3=deck[%rnd1%]
set /a player_total=%player_total% + %player_card3%
echo Your card: %player_card3% (Total: %player_total%)
if %player_total% gtr 21 (
echo Busted! You lose!
goto end_game
)
goto player_turn
)
:dealer_turn
cls
echo Dealer's turn...
if %dealer_total% geq 17 goto compare_totals
set /a rnd1=%random% %% 13 + 1
set /a dealer_card3=deck[%rnd1%]
set /a dealer_total=%dealer_total% + %dealer_card3%
echo Dealer's card: %dealer_card3% (Total: %dealer_total%)
goto dealer_turn
:compare_totals
cls
echo Comparing totals...
echo Your cards: %player_card1% %player_card2% %player_card3% (Total: %player_total%)
echo Dealer's cards: %dealer_card1% %dealer_card2% %dealer_card3% (Total: %dealer_total%)
if %dealer_total% gtr 21 (
echo Dealer busts! You win!
goto end_game
)
if %dealer_total% eq %player_total% (
echo It's a tie!
goto end_game
)
if %dealer_total% gtr %player_total% (
echo Dealer wins!
goto end_game
)
echo You win!
:end_game
set /p choice=Do you want to play again?
if "%choice%" equ "yes" goto shuffle