Slashdot Mirror


Play Blackjack with PHP

Zack Coburn writes "The latest Codewalkers PHP Coding Contest invites PHP programmers to compete by creating a PHP script that interfaces with a special PHP library to play the game of Blackjack. Judging will happen as follows: 'A number of random decks will be generated, for each random rules will be used. Each script will then play all these decks, so each script will play under exactly the same conditions. In the end, the sum of all the money gained will determine the winner. In case of a tie, the running time will be the tie-breaker.' Some of the sixteen prizes include Cerberus Encoder, PHPEd, Macromedia Studio MX, SourceGuardian Pro, and Zend Studio." Here's a hint: count cards. :)

6 of 28 comments (clear)

  1. Warning to those who will enter by vslashg · · Score: 5, Informative
    From the contest rules:
    If both you and the dealer bust, the hand is a tie.
    I don't know what game that is, but it's not casino blackjack. If your plan is to quickly translate some blackjack code you've already written into PHP, you're going to have to compensate for their misunderstanding of the real rules.
    1. Re:Warning to those who will enter by karnal · · Score: 2, Informative

      Most blackjack rules I've seen have a "dealer must hit to 17", which means the dealer can't just sit there with a 2 showing and not hit, unless the whole table (players) are bust...

      --
      Karnal
    2. Re:Warning to those who will enter by notsoclever · · Score: 2, Informative

      That's only if the player hasn't busted already. If the player busts, it's an automatic win for the house.

      --
      There are 10 kinds of people: ones who understand ternary, ones who don't, and ones who think this joke is about binary
  2. Re:Things to ponder by T-Ranger · · Score: 2, Informative
    The vast majority of counting strategies are based on adjusting your bet. As a counting player, you always play the 'basic strategy', and adjust your bet according to your count.

    Well, almost 'always', anyway. If your in third base, holding a 12 against a dealers 3, and the last 7 cards have been faces, then a hit would be a good thing, even though it is against basic strategy.

    The other exception is if you are keeping a side count of faces, you can use that information to choose to take insurance. Playing basic strategy, insurance (or even money on a BJ) is always a bad idea.

    On your second to last point, I wounder how well a program : "sitdown(); bed(0); leave(); " would do ....

  3. Re:Things to ponder by allstarska · · Score: 2, Informative

    I don't know about the math behind it - but I have read and heard that shuffling is not truely random.

  4. Re:not a good test by Anonymous Coward · · Score: 1, Informative

    I'm sorry to say that your idea is great, but not correct. The best way to play any card game is to play in the statistically best way possible. The way you determine what your odds are is by collecting information. i.e. counting cards is blackjack is the way a good player collects information. In a game like Hold'em, you watch the cards, but you also try to watch the players and collect information that way too.

    Once you know the odds on the best play to make, in the end if you play that best way every time you come out ahead. There really is nothing more involved than that in a game like blackjack where you don't try to read other people. So, given that card counting strategies have been well established some time now, since these programs will have a perfect memory and perfect set of math functions, if everyone programs theirs correctly they will all come out with the same amount of money in the end.

    The way to do best in a game like this where the opponent follows a strict set of rules is to play optimally all the time. This is something you learn if you start reading in the AI of games at all. Only if your opponent is playing suboptimally can you reap greater reward by varying your strategy. Of course the casino would not be letting blackjack dealers play suboptimally, otherwise their return wouldn't be garaunteed. This is why dealers don't participate in games like Hold'em where they cannot follow a strict set of rules.