Javascript Texas Holdem

A Texas Hold'em Poker game written in Javascript. Download js-css-poker For the impatient Play it What is this about really? I just wanted to make a 'program' using javascript, CSS and HTML. A No-limit Texas Hold'em poker tournament for Javascript bots played via pull requests with Travis CI as the dealer. JsPoker is an automated poker competition, where your opponents are bots written in Javascript.

Before we launch into this assignment, let’s take a look at the solution for assignment 5:

Assignment #6 – Fun with Enums

In this assignment we are going to use our knowledge of Enums to create a Texas holdem poker game!

If you aren’t familiar with Texas holdem poker, you can become acquainted with the generic rules of poker here.

This particular assignment won’t be to implement the entire breadth of the game, but rather, to implement the key elements of the game of poker so that we can expand on it later. So let’s talk about the elements that you’ll need to implement for this assignment.

You are required to create a Deck of Cards that can be used in our poker game. The deck should be a standard deck of cards consisting of 52 cards made up of 4 different Suits (diamonds, clubs, hearts, spades) with Values ranging from TWO to ACE.

Once you have your Deck of cards setup, the next thing you need to do is be able to:

  • Shuffle your deck
  • Deal cards to Players

Having said that, you will also need to create Players, these players will have one Hand of cards. Each hand will consist of two distinct cards from the deck.

Not only do you need to deal cards to players, but you also need to deal the “community cards”. For this iteration of the assignment, let’s just deal five community cards right away. I don’t want to put the “betting” aspect into this assignment just yet.

Once you have dealt all players their hands (two cards each), and you have dealt the five community cards, then you’ll need to figure out which player has the best hand. To do this, you’ll need to know which type of hand beats another, so here’s the list:

Javascript Texas Holdem


(picture credit goes to www.betshoot.com)

You’ll need to output each players’ hand in the console window, as well as the community cards. Once you determine which player is the winner, you should output which player won and with what hand. In the event that there is a tie (i.e. two players hold the same winning hand), you’ll need to determine which of the winning hands has the higher value cards. So if both players have three of a kind, then the player with the three higher value cards wins (i.e. Player 1 has three jacks, but Player 2 has three aces… aces > jacks therefore Player 2 wins).

A draw will occur only if the values of the winning hands are exactly the same (i.e. two players have three of a kind with kings and identical ‘non-winning’ cards)… In the event that two players each have the same winning cards, but different non-winning cards (i.e. Player1 has three aces a king and a jack, Player2 has three aces, a jack and a four), then the player with the higher “kicker” card wins (i.e. Player1 wins because their king kicker beats Player2’s jack kicker).

Note: This assignment is more difficult than most other assignments I have posted on this blog. It took me roughly 12 hours of coding to complete this assignment. The good news for you is that I have included a good chunk of the coding in the assignment source files that you can download below.

What You’ll Learn

This assignment should make heavy use of Data Structures, namely Lists and Maps. Everybody’s solution will be different, so if you don’t use these data structures, then no worries… However, I do believe you will need to use them to make your life a little easier.

You will also learn how to Sort Collections, this will be mandatory, as it will be very difficult to determine which player has won without being able to sort the cards.

My solution even uses a little Recursion, now whether or not you choose to do this is up to you, but I believe it made my solution simpler.

Click Here to View the Assignment Files on GitHub

Texas Hold'em Rules

Also, here’s the GitHub Clone URI: https://github.com/tp02ga/JavaPracticeAssignment6.git

Poker can be a fun card game for the family, or a serious competitive game in which the steaks can be so enormous, even selling your house wouldn’t cover the costs.

There are many variations of poker, with Texas Hold ‘Em being the most popular worldwide.

Below are a whole bunch of poker facts and statistics which help you understand the chances of wining and the odds of getting the cards you want.

Did You Know?

A pocket pair is cards of the same rank, which means if your two cards have the same number, from 2-2 all the way up to A-A, this is called a pocket pair.

Free Texas Hold'em

  • The odds of receiving any pocket pair is 5.9% which is 16 to 1. These are also the same odds of receiving a pocket pair of 2’s.
  • The odds of receiving a specific pocket pair: 0.45% or 220 to 1 These are the same odds for receiving a pocket pair of A’s.
  • The odds of receiving a pocket pair of A’s twice in a row is 0.002047% or 48,840 to 1.
  • The odds of receiving a pocket pair of K’s is 0.9% which is 220 to 1.
  • The odds of receiving a pocket pair of Q’s is 1.4% which is 73 to 1.
  • The odds of receiving a pocket pair of J’s is 1.8% which is 54 to 1.
  • The odds of receiving a pocket pair of 10’s is 2.3% which is 43 to 1.
  • The odds of receiving a pocket pair of 9’s is 2.7% which is 36 to 1.
  • The odds of receiving a pocket pair of 8’s is 3.2 which is 31 to 1.
  • The odds of receiving a pocket pair of 7’s is 3.6% which is 27 to 1.
  • The odds of receiving a pocket pair of 6’s is 4.1% which is 24 to 1.
  • The odds of receiving a pocket pair of 5’s is 4.5% which is 21 to 1.
  • The odds of receiving a pocket pair of 4’s is 5.0% which is 19 to 1.
  • The odds of receiving a pocket pair of 3’s is 5.4% which is 17 to 1.

Poker Fast Facts

The total number of possible royal flush hands in a standard 52 card deck is 4.

And the odds of making a royal flush is 649,739 to 1.

This is correct assuming that every game plays to the river.

In poker terms, the river is the name for the fifth card dealt, face-up on the board.

In total, there are 2,598,960 possible poker hands with 52 cards.

The odds of getting four of a kind in Texas Hold ‘Em is 4164 to 1.

Casinos normally change decks after 15 minutes of steady play, so that the cards can always be fresh and unmarked, as many professional players would be able to remember the certain markings on cards and use that to their advantage.

This is only a basic overview of poker odds, there are many calculators online that can help solve the odds of getting certain hands, depending on what stage of the game you’re at, what cards you currently hold and how many people are playing.

Now you are familiar with these odds, you can use them to your advantage for a better poker strategy when you finally decided to play a tournament.

Javascript Texas Holdem Rules

In Texas Hold-Em Poker the odds of making a royal flush hand is only 649,739 to 1.