Share via


Video Poker System – By Robert Cross

When I was given the task of leading a group in a University group module to create a Video Poker system with AI that could not only play the game, but beat you, I was slightly dumbfounded.

The decisions that needed to be made were quite daunting. I made a quick decision to go with C#; this was due to its high level approach, simple memory management and its vast collection of pre-written code in the .Net framework. I also decided to use Microsoft’s XNA Framework which had recently been released. This was mainly because it creates a good and simple GUI without the hassle of DirectX. XNA was a technology that had real potential, and I was really excited to be using it. I had not used either C# or XNA before starting this project. If you have basic program skills in Java, and you read a few simple tutorials on XNA then you can produce games. Both XNA and C# have a vast set of documentation by Microsoft and on personal tutorial pages. A really good set of video tutorials are located here. These are enough to get anyone started on their own game and realise how fun and easy it is. They cover most aspects of XNA and C# from a basic introduction to using models and sprites to create 3D animation.

clip_image002

Winner screen shot

Due to our limited time scale and large task ahead we went straight into coding. I delegated some tasks to other members of the group. There were some obvious key points that needed to be sorted. There was a large AI system that needed to be created. The AI system needed to take the players move, decide what type of player they were, and then play the correct tactic. There needed to be random elements in order to keep the human guessing. This would involve creating tactics, working out when to bluff and using statistics to assess when to call, fold or raise. There also needs to be some user input, how much to bet, raise, fold, help function and quit game. These can all be handled inside one method.

clip_image004

Game Over Screen Shot

Just in case you haven’t looked into XNA, which I highly recommend you do, here are the basics. There is a Game object which is created from the initial program class. Inside the Game there are object variables, the constructor, initialise method, and LoadGraphicsContent method which are all ran initially. Then there is the update and draw methods which are recursively called, there is also the UnloadGraphicsContent function which is executed on exit. All calculations are done in the update method and all the graphical methods are called in the draw method. One thing to note is that the update and draw method both execute as fast as possible, which means they are not necessarily in sync with each other. This introduces problems with concurrency; however this is a simple case of the update method writes to memory, and the draw method reads memory.

Now for the fun bits. I needed an image object to show an image at a certain position. This class takes a position Vector, a name of the image, and quite a few more parameters to show exactly what is needed. The object has similar methods to the main program, initialise, LoadGraphicsContent and draw. The program just creates an instance of the image object with the parameters needed and then in the draw method of the main program calls the objects draw method.

There are many ways to create animation using a moving image. I decided the way I wanted to do it was use a number of frames per second, and use a List to store the correct positions, and iterate through them to draw the image at different positions.

There are set times the computer player makes a decision on what action to take. This happens 4 times per hand of poker. There is a function for each one of these, which is called from the update method. Each function is slightly different. From these functions comes a decision on what do, e.g. bluffing, folding, raising and calling. More functions can be created, for example making a character blink, or the character could even make comments on the game. These are the kind of things that make a program come to life and make it not only fun to play, but to create. How far you take the game is up to you, but the further you take it the more you, and other people, will get out of it.

clip_image006

Screen shot of a prototype during development. The joker card at the top of the screen is the mouse cursor, which was really easy to create using the built in mouse functions.

XNA gives the programmer the ability to give the user a game of real quality and a really involved feel. The games that you produce can be rich, complex and involved, you just need to have a go.