Archive for June 2008

Making the AI, Part 1

Making the AI for Auction Poker has been one of the most tedious, albeit fun, programming tasks that I’ve done so far.

Originally, Auction Poker was going to be a multi-player game but I felt the game would be more accessible if it didn’t require other people to play it. That’s when I began to make the AI.

The very first thing I needed to do was figure out a way for the AI to determine which cards are capable of making a good hand. Given a set of ten cards such as shown in the image below, how would the AI know which cards to bid on?

In this set of cards, I would bid on the King and Queen of Clubs since I know I can possibly make a Royal Flush if the right cards come up and if not, I can settle with a plain flush or a 9-K straight. Or maybe I would go for the pair of 10’s and the pair of 9’s and hope for a Full House.

I didn’t look at each card individually, I looked to see how well it paired up with other cards in creating a good hand. Each card has little value by itself. Only when combined with other cards is their value realized. Thus, the King of Clubs is useless if all the remaining cards are low ranking Diamonds and Hearts.  To make a semi-intelligent AI, this information needs to be somehow measured and placed into a chart that the AI can look up.

To measure the affinity between pairs of cards, I used a rather large spreadsheet and figured out which hands were possible with each pair. For example, given a 9 of Hearts and a 9 of Diamonds it is not possible to make a Royal Flush, a Flush, a Straight or a Straight Flush. However, it is still possible to make a 4-of-a-Kind, a 3-of-a-Kind, a Full House, a Two Pair and a Pair hand.

This is the visual result of that spreadsheet. The brighter the color, the greater the affinity between two cards:

The white spaces in the middle of suited chart are pairs that are not possible -  same suited cards of the same rank.

As you can see, there is a big difference in behavior between two cards of the same suit and those from different suits. With suited cards, there is some affinity even with cards from very different ranks and the affinity increases as the rank of the cards gets close. At high ranks, the affinity is also influenced by the possibility of a Royal Flush.

With unsuited cards, the only cards with large affinity are pairs. There is also some minor affinity between those of close ranks since it is possible to make a straight. Everything else has no affinity.

Now that we have these charts, it should just be a simple matter for the AI to look at a set of cards and maximize the affinity.  Let’s take a look at this set of cards and pick the ones that have the maximum affinity:

If only look at two cards at a time, the AI would pick the Queen and King of Clubs but it would miss the Jack of Clubs which would go a long way towards making a Royal Flush.

However if we look at four cards at a time, the AI would pick the Jack, Queen, King of Clubs and also the Queen of Spades.  That’s not good, we wouldn’t want that extra Queen of Spades.

To refine the AI, we will have to make sure it knows what hands are still possible with each new card. Up to the third card, the Royal Flush is possible. Once we have that extra Queen, the Royal Flush is impossible and the best we can hope for is a 3-of-a-kind.

Figuring out how to do that will be the focus of Part II.




A little bit of feedback

As I was fiddling with Auction Poker earlier this week, I got the idea that the player should receive a bit more feedback throughout the game. Currently, the player’s only feedback occurs at the end of each round - which cards were lost, were cards were won and which cards had their bids go up. I decided to I wanted to let the player know what the AI was up to and display the AI’s cards. I mocked up a screenshot of how that would work and this is how it came out:

That is not pretty at all!! Yuuuuuck! Of course, it’s a mockup and the cards on the side would be of a different format, geared to their small size, but it just doesn’t look good. It’s too cluttered and there’s too much information considering each round is only 10-15 seconds. Within that time, the player has to determine which cards he will bid on and how much he will bid taking into account the AI’s decisions of the previous round.

So, we’re definitely not going in that direction. I’ll stick with the 10-card format.

P.S. : The Poker Square page is now up!

Fracking Wordpress!!

So the site was down for a long time during this weekend. It was a busy weekend for me (8-mile hike!) so I didn’t notice it too much. I spent a big portion of my free time today trying to figure out what the problem was. It wasn’t the Yahoo hosting, since I could access other images and stuff not inside the blog.

Well, after a couple of hours of messing about (turning on/off plug-ins, changing the template style, etc…), it turned out the solution was to go inside a PHP file and comment out a line of code. I was already starting to migrate everything to blogger.com but I don’t like their styles so I’m glad I got this working.

Poker Square coming along

I took some time tonight to start coding Poker Square. It’s coming along quite nicely and somewhat quickly. Depending on how much free time I have this weekend, I think Poker Square might make an appearance in Whirled early next week. Here’s a current screenshot:

The scoring for the rows and columns hasn’t been enabled, obviously.

Updating things here and there.

I’ve been updating things here and there. I’ve created two new pages. One for Paint Factory. (Yes, you can play it outside of Whirled!) The other page is for one of my Whirled Rooms where I test stuff out.

Even though I haven’t finished Auction Poker or started Poker Square, I’ve already started writing notes for a Blackjack-type game. I have notes for other games too but I’ll probably get the cards games done first, they’d certainly be easier to code than a space-based gravity game or a plant breeding game.

Working on Auction Poker

The next game that I’ve been working on is called Auction Poker. Basically you are bidding for cards against the AI. Here’s a screenshot of the current version of the game:

I originally meant to get the multi-player version of the game done first but multi-player debugging is quite tedious at the moment so I decided to focus on the solo version. Currently, I’m working on developing the AI.

However, when I was browsing a card games rule-book at the bookstore today I came upon a game called Poker Square. I immediately thought that I could make this game with minimal effort right now - I have the card artwork done and the script for processing poker hands.

I think you might see Poker Square in Whirled in the very near future. ;)

Paint Factory - We like it Normal

I’ve been watching the score distribution for Paint Factory very closely ever since a booched score (11 million points!) caused everyone to earn very little coins. Looking at early score distributions, it was clear that people liked playing the normal modes more even though the harder modes pay more Coins.

However, since I revamped Paint Factory the play frequency on the different difficulty levels has been really noticeable. Take a look at the scores distribution graph. I modified it to make it a bit clearer.

The color bars represent rough scores for each of the difficulties.



Blue is Easy. Green is Normal. Yellow is Hard. Red is Very Hard.

In reality, there is a bit of an overlap between difficulties and failing scores are spread throughout the graph, but this is a good estimation. As you can see, the Normal difficulty is the most popular by far!

Usually the difference is not this distinct but this was taken about a week after the scores were reset. As more scores are recorded and the higher end players get back to playing the difficult levels, there will more scores recorded for the higher difficulties. Stay tuned.