03/04/2022 - Present

Pineapple Solver

Project Type - Simulation

Visit Website

Purpose of the project

Open Face Chinese Poker is a poker derived card game. The game is played against one or two opponents and the aim of the game is to score more points than your opponents.

A standard round consists of each player being dealt 5 cards, each of which will need to be placed in one of three rows. After this players take it in turns to be dealt 3 cards, 2 need to be played and 1 discarded. Play continues until every player has 3 cards in their top row and 5 cards in both their middle and bottom rows.

This results in a 3/5/5 board pattern.

If certain requirements are met then a player can enter Fantasy Land on the next round, resulting in them being dealt all 14 of their cards straight away. It is then their job to determine the best way to make their hand.

Seeing all of your cards straight away is obviously a massive advantage but can be overwhelming as the different possibilities are insanely high, the purpose of this program is to find the best combination of those cards.

Technologies used

Node JS Logo

Node JS

Express JS Logo

Express JS

HTML5 Logo


CSS3 Logo


JavaScript Logo


Key Features

Permutation Culling

Given 14 cards there are 87,178,791,200 different permuations. That is, how many different ways those 14 cards can be arranged.

Fortunately, the method for finding out the best combination of cards can effectively disregard one of the cards, that card becomes a discard and doesn't lend itself to the final hand therefore it can be forgotten about.

This leaves us this P(13) = 6,227,020,800 A reduction of more than a factor of ten but still more than a billion, which would result in some very slow simulations.

The final reduction we made was to know that a lot of the permutations contained duplicates when applied to the logic of the game.

For example, in the image below, consider the cards at position 5, 6, 7, 8 and 9. If the permutation that starts with occurs then that would result in a flush. However the permutation that starts with would also result in exactly the same flush. This is true for any permutation of those exact 5 numbers.

Using this logic we were able to reduce the number of permutations that needed to be inspected to just 1,009,008

The setup of a simulation

Speedy Outcomes

Coupled with the logic above some early exit programming was implemented. This meant that as soon as it was found that the permutation that was being checked was no longer a viable option for the best outcome the program would stop working on it and move immediately to the next.

This helped shave off a few more seconds per simulation, resulting in an average time of around 5s per simulation.

A loading screen that is shown while the simulation is in progress

Alternative Possibilites

Most of the time there is a single best outcome, the hand that scores the most points. There is, however, around a 10% chance that a hand will fulfill certain criteria and allow the player to repeat fantasy, allowing them to again receive all 14 cards on their next turn.

If this does happen then it is possible that the hand that allows the repeat does not score as high as the best outcome. When this does happen both possibilities are shown to the player to give them the most information to guide their decisions.

The simulation has completed, showing two possible outcomes

Other Projects

Master Of Tournaments

Master Of Tournaments Logo

Casino Tutor

Casino Tutor Logo

Accountants DR

Accountants DR Logo