The Hearts Project

hearts

The challenge of the Hearts project was to create an algorithm to play against. First, a wireframe had to be created as a vehicle to play a game of hearts. In the first wireframe, a simple interface was created that allowed me to play a game manually for all 4 players which included the ability to complete one hand of hearts without the initial 3 card pass.

Initially I had imagined that I could use some kind of node analysis similar to a chess engine. I quickly realized that this would be a problem. Chess begins with one node. Hearts on the other hand begins with approx. 5.3645 X 10 28 possible nodes. To give this some perspective, that is the equivalent to the number of stars in 10 17 milky way galaxies or 100,000 Tera-galaxies. I decided it would be simpler to create a few probability tables and make the algorithm choose cards based on that. I also soon realized that a real advantage would lie in being able to remember all the cards that had been played, which I programmed the algorithm to do.

The next step was the passing algorithm. A similar kind of 'probability table' approach was used for this as well. A considerable problem with the purely mathematical approach to decision making is trying to predict what the human players will do. This can be an important factor. In the future I will hopefully add the ability for application to start collecting statistical data when it comes to human player tendencies which I can then use in the algorithm once there is a big enough sample.

After I had a functioning wireframe with a half decent algorithm I began turning that into nice looking user interface.

Once that was working I added an automatic game saving feature which allowed a visitor to return to the site at a later date and pick up where he left off. This prevents a visitor from losing their game if they accidentally leave the page. This was accomplished using browser cookies. So if they return to the site using a different browser their last game will not be loaded. If they were playing a game at one time with the different browser, that game would be loaded instead.

Visit the Hearts Website