Blog

A DSL for Poker – On Achieving Your Dreams

Six years ago, I saw some source code that has stayed with me ever since. It was a piece of Erlang code that described the game of Texas Hold’em poker. What struck me was the beautiful simplicity in that it described exactly the rules of poker and nothing else. This was very different from the legacy poker system I wrestled with at the time. I decided then and there to set a goal to create “a card rules engine”. I even added this goal to a website which kept sending me emails nagging about this goal.

I tried some different things over the years, first I toyed with the idea of describing card games as a state machine. I even implemented the basics of Texas Hold’em in UniMod. That quickly got very messy, mostly because of all the special cases but also because it’s actually quite hard to reuse a sub state machine from the outer state machine.

I also considered modelling poker as rules with a rules engine (Drools to be specific). It seems to make sense, poker is a set of rules and a rules engine takes a set of rules and a set of facts and applies these rules. However, these rules engines are meant for “business” rules, meaning they will help you apply the right insurance premium or offer the correct rebate on your order. Having a system where “any” matching rule will fire does not make for very predictable gameplay. In other words, it’s just a bad match.

For a while it seemed like my dream to create “a card rules engine” would remain just that (it was also a case of the goal not being SMART, but I digress). During the last year and a bit, I have found myself writing poker code from scratch again, this time working on Cubeia’s social poker network. As always, there were deadlines and requirements, so I could not sit around and polish on this ivory tower dream of mine. I did however apply a lot of the good design principles I had picked up over the years, mostly from my man crush Miško Hevery.

The key principles in this case were “design for testability” (with the help of TDD) and “composition over inheritance“. And so one evening it hit me that going from where I was to a DSL for poker would not even be a lot of work. So I sat down and spent just over one day before my new and shiny DSL for poker saw the light. Here’s what the definition of Texas Hold’em looks like with this DSL:

    public static GameType createTexasHoldem() {
        return new PokerGameBuilder().withRounds(
                        blinds(),
                        dealFaceDownCards(2),
                        bettingRound(PRE_FLOP, fromBigBlind()),
                        dealCommunityCards(3),
                        bettingRound(FLOP),
                        dealCommunityCards(1),
                        bettingRound(TURN),
                        dealCommunityCards(1),
                        bettingRound(RIVER)).build();
    }

and here’s what Omaha would look like:

    public static GameType createOmaha() {
        return new PokerGameBuilder().withRounds(
                        blinds(),
                        dealFaceDownCards(4),
                        bettingRound(PRE_FLOP, fromBigBlind()),
                        dealCommunityCards(3),
                        bettingRound(FLOP),
                        dealCommunityCards(1),
                        bettingRound(TURN),
                        dealCommunityCards(1),
                        bettingRound(RIVER)).
                        withHandEvaluator(new OmahaHandEvaluator()).build();
    }

You get the idea (the entire code is available from Cubeia’s open source poker repo on BitBucket). Having now achieved this goal of mine I felt very proud and slightly embarrassed that it took me so long to get there.

My takeaway from this and the message I want impress on you is to never give up on your goal and most of all to not get stuck searching for the “one grand unified model” as I did which easily gets you stuck in “analysis paralysis“, but rather break the problem down into pieces and apply adequate design principles to each part.

I hope this gets you motivated to achieve your goal!

Viktor Nordling

Try our Social Poker

Our social poker network is now up and running in beta mode. We have been hard at work the last couple of weeks to react to the feedback we have been getting from our players and operators. If you are interested in running your own Social Poker network as an operator you can get more information at http://www.cubeiasocial.com/ and if you want to try the game out you can play through our example integration at http://www.cubeiapoker.com/.

Cubeia Social update

We have been releasing a lot of new things for our on Cubeia Social, check it out if you are interested in a social poker network. We are getting closer to an open beta and are really looking forward to put the product in Your hands!

MySQL Authentication

We have added default support for integration between Cubeia Network’s user-service and legacy MySQL database. This might be useful if you already have an existing user base stored in a MySQL database and want to use that for authentication but still want to take advantage of Cubeia Network.

Read more here: MySQL Migration Adapter

Note: This will be included in Cubeia Network as of version 1.4.0

Poker Demo updated

A new version of the poker network demo is now available for download. Grab it while its hot!

Cubeia Poker Cloud Scalability

Introduction

Would you want some cloud with your game server?

Cubeia Firebase was initially build for real money gambling and for deployment on dedicated hardware. It makes sense to control your hardware when you’re dealing with monetary systems but as gambling focus has shifted the last couple of years towards social gaming cloud based deployments makes much more sense. In this article we’ll present Cubeia Poker running on Amazon AWS and our initial load tests and evaluation.

Cubeia + NDA = No Go

Frequently we’re asked to sign Non-Disclosure Agreements (NDA). Either they’re presented at an exploratory stage or when agreements or licenses are to be written. Generally we say no to them, and here’s why.

Debugging Class Loading with AOP

In this article I’ll briefly discuss how Aspect Oriented Programming (AOP) using AspectJ can be used to debug class loading, in particular in instances where a system have multiple class loaders. I’ll assume a basic understanding of Java class loading and AOP.

Web Socket Performance

We’re gearing up for the 1.8 release of Cubeia Firebase which will include native server-side support for HTML5 in the form of WebSockets and Comet, and naturally we want to make sure the performance is up to our normal standard. In this article we’l compare the standard Firebase binary socket communication with web sockets.

Singleton Scalability

This article looks at a simple scalability scenario using so called “singleton” configurations of Cubeia Firebase 1.7 Enterprise Edition. It is looking at high load scenarios on limited hardware, and will discuss the implications of the test result.