How can i make a 1 count as 11 if its best in blackjack

2 visualizzazioni (ultimi 30 giorni)
i want to create a function that optimally calculates a hand of cards according to blackjack rules
this is what i have so far, but it doesnt seem to be able to count ace as 11
does any1 know why the if sentence doesnt work or what i could do instead?
function score = blackjack(hand)
hand = [10 1]
score = sum(hand);
if score <= 11 & hand==1
score = score + 10;
end
if (score > 21)
score = 0;
end

Risposta accettata

Walter Roberson
Walter Roberson il 24 Gen 2020
if score <= 11 && ismember(1, hand)

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by