Pregunta

I want to create some sort of algorithm to make a computer win more than it loses at a modified game of blackjack.

Red cards will be negative, black cards were positive.

I will write it in pseudo code I want sure about the probability part in making the computer win more games (last line).

Here is my attempt:

//Hand out 2 random cards for each person selection of 2,3,4,5,6,7,8,9,J,Q,K,A. 
//Store these in an array with their equivalent value. 
Card =[2,3,4,5,6,7,8,9,J,Q,K,A]
Also, colour of card is random red or black.
Value_AI=0
Value_Human=0
Bust_Human=0
Bust_ AI=0

All of the below is in a big loop that loops each time a player is bust

Do this for both players, until Value_AI or Value_Human>21
If colour==red then
Value=value – card
Else
    Value=value+card

If Value_AI >21 then
    Bust_ AI+=1
    Print “Computer has bust”
    Break 

If Value_Human >21
        Bust_ human+=1
        Print “You have bust”
        Break

    Else
        Hand out another card for both

If Bust_ AI> Bust_ human then
**//Increase the probability of getting an ace and a card with a value of 10 for the computer**
¿Fue útil?

Solución 2

Right now, your pseudocode doesn't seem to include an option for either player to choose to stop receiving cards, which is the central choice to be made in Blackjack. After the newest card is received, you need to have the AI make a choice as to whether it wants another. This is probably the best point in the algorithm at which to build actual intelligence into your AI, so you can increase its probability of winning without just hard-coding wins like you suggest in your pseudocode. The simplest option is to have your AI calculate the probability that the next card will send its value over 21. Here's some pseudocode for that (it doesn't look like you remove cards from the deck after you draw them, so I'm not taking that into account):

highest_safe = 21 - value_AI
n_safe_cards = highest_safe - 1 + 13 //the second 13 is for all of the red cards and the - 1 is because 1 is not a card
prob_safe = n_safe_cards/26 //since there are 28 possible cards (I'm assuming you didn't mean to leave 10 off your list)
if prob_safe < .5:
    stop taking cards

This should result in your AI winning more often than not, as it will result in it playing optimally. If you want it to be a little easier to beat, you can add some noise to the threshold at which it decides to stop taking cards.

Otros consejos

You can make the human go before the computer. Then when they both would have busted, it will be a computer win by default because the computer won't need to go. That should change a fair game into one favoring the computer.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top