been extensively studied (Wong, 1994). Generally,
Game theory gives ideal frameworks that can be used
to provide guidance on the allocation of limited
resources and can be applicable such as solving
transportation problems (Hughes and Chen, 2021). It
can also be used to develop pricing models aimed at
balancing loads in the grid (Ghosh et al, 2004).
Therefore, game theory and optimal strategy
research are considered broadly applicable and
meaningful.
This paper will introduce a method of using an
open-source programming language and software
environment: R language to solve the Blackjack
strategy problem. That is, R language will be used to
give expectations for selecting hit or stand under
different player versus dealer cards situations to give
players a reference for decision-making.
2. METHODOLOGY
2.1. Game Description
Specifically, the process of the Blackjack is as
follows: the dealer first deals two cards to each
player, and then deals one card to himself. These
cards are all shown publicly, which means that
players also have the information of the two cards of
other players. After that, players make decisions in
order from right to left. The player can choose to
“stand”, for which the sum of the two cards in hand
will become the final points; or choose to “hit”, for
which the dealer will deal one more card to the player
to increase the sum, and players are allowed to hit
multiple times. Mentionable, players aim to not
exceed 21 points, or they will be eliminated
immediately. The dealer will take action after all
players have ended their action round. Unlike the
players, the dealer's actions do not depend on
subjective will, but on a fixed rule: the dealer must
hit if the dealer’s card sum is less than or equal to 16
points and must stand if greater than or equal to 17
points. At this moment, all surviving players will
compare their points with the dealer and whose
points are not as high as the dealer's will lose all bets.
With a bigger card sum, the player will win the game,
and the payout varies according to the odds specified
by the table and casino. If the dealer's hand exceeds
21, then all players who survived, which means those
who did not lose at the player action, win. If the
points are equal, it is a tie, with no profit or loss for
the players.
There will be different rules according to
different casino regulations. For example, if the
player believes that his two initial cards are very
favourable compared to the dealer's one initial card,
then the player can choose to double in his round,
that is, double his original bet. In this case, the dealer
gives the player one card only, which means there are
no multiple hits. Therefore, players need to consider
whether their winning odds are worth doubling down
on, as either gains or losses are doubled. Some
casinos allow betting on flushes, straights, or triple
7s. Although the probability might be extremely low,
the payment could be very impressive, with some
odds can reach 1: 500.
2.2. Simulate Process and Convert to
Code
In summary, it is crucial for players to correctly
analyse both sides' initial cards and take action. This
article will use R to produce an answer of whether
the player should choose to hit or stand in terms of
probability by various player points and dealer points
in the situation of one deck of cards and one player
playing. First, an environment with one deck of cards
is needed to be created. The code shown in Table 1
will create a vector: numbers from 2 to 10 represent
the number cards, three 10s represent the face cards,
and an 11 represents the ace card. This vector is then
repeated 4 times to form an environment of 52
standard playing cards. The user could simply
change the variable in the repeat code to a multiple
of 4 in simulation of multiple decks of cards. In
theory, using multiple decks will slightly increase the
dealer's winning rate, which is tiny enough to be
ignorable.
Table 1. R code Function call for one standard deck.
Algorithm 1
Step 1 Import the dplyr librar