0

Think of BlackJack game... I created a method which does simple calculation whether computer should draw a card and just hard coded the rules. I would like to make this more 'intelligent' therefore making game a bit more unpredictable even for creator (me).

What could I add here? How to make my dealer draw without hard coding much of the rules?

// Compute if computer should draw a hand or not depending on hand value of player.
// Also, computer may take higher risk if player has reached BLACKJACK.
private static Deck dealerDraw(Deck deck, Hand player, Hand player2, Hand dealer)
{
    if(player.getHandTotal() <= BLACKJACK)
    {
        // Dealer takes a precaution and only draws 
        // if hand total is less than or equal to 15.
        while(dealer.getHandTotal() <= 15 && 
                (dealer.getHandTotal() <= player.getHandTotal() || 
                dealer.getHandTotal() <= player2.getHandTotal()))
            deck = drawFromDeck(deck, dealer);

        // Player has reached BLACKJACK!
        // There's no or little chance to win, 
        // dealer risks and draws even if total is high.
        if (player.getHandTotal() == BLACKJACK || 
                player2.getHandTotal() == BLACKJACK)
            while(dealer.getHandTotal() < BLACKJACK && 
                    dealer.getHandTotal() != BLACKJACK)
                deck = drawFromDeck(deck, dealer);
    } // end if()

    return deck;
} // dealerDraw()
4

2 回答 2

4

Before you spend a lot of time writing a Blackjack dealer AI, you might consider that generally the dealer doesn't get to make any choices because the statistically best play doesn't really depend all that much on what the player does.

You might pick a more interesting game to write a real AI for.

于 2012-12-07T07:21:47.267 回答
3

To implement an AI, I think you should not try to modify your non-AI code into an AI implementation. Rather an AI based computer player mostly needs a completely different design, so I would redesign the whole 'player' code. I would for example go for machine learning. With machine learning, it can learn as it plays more and more and in some time (depending upon the algorithm and its implementation) it can surprise me. For example an AI can record all its moves/plays (in a database) and draw a conclusion deciding its move the next time similar situation arises, based on statistics of successful moves.

于 2012-12-07T07:01:45.787 回答