Hearts with HTML5 is a browser-based Hearts card game implemented in vanilla HTML5 and JavaScript, designed to serve as a platform for testing AI decision-making algorithms through its pluggable Brain system.
What is Hearts with HTML5?
Hearts with HTML5 is a fully playable card game run in the browser, with a live instance hosted at http://hearts.yjyao.com/. The project's core is an Ai.js class that makes decisions by delegating to one of several Brain implementations. The game is written in HTML5 and JavaScript, and the source code is publicly available in a GitHub repository. It is primarily an educational and experimental project for implementing and comparing AI strategies in a classic trick-taking card game.
Key Features
- Pluggable AI brains — The
Ai.jsclass accepts differentBrainimplementations:SimpleBrainfor simple greedy heuristics,McBrainfor one-step look-ahead with sample generation and deterministic rollouts, andPomDPBrainfor a Partially Observable Markov Decision Process (POMDP) solved with the POMCP algorithm. - Web worker support —
AsyncBrainwraps more time-consuming brains so they run in a web worker, keeping the browser UI responsive. - Multiple AI difficulty levels — By choosing different brains, players can face opponents ranging from greedy heuristics to a POMCP-based solver.
- Live demo — The game is playable at http://hearts.yjyao.com/ without any local setup.
- Clear AI architecture — The separation of
Ai.js,Brain.js, and its subclasses provides a template for adding new decision-making strategies. - Open source — The entire source code, including the AI modules, is available in the repository for study and modification.
Who is it for?
This project is useful for AI researchers and students who want to see POMCP applied to a real game, for JavaScript developers interested in web-worker integration and modular AI design, and for anyone who enjoys playing Hearts online against an AI opponent.
What can you do with Hearts with HTML5?
- AI researchers: Compare the performance of
SimpleBrain,McBrain, andPomDPBrainwithin the same game environment to study decision-making quality and computational cost. - Game developers: Use the repository as a reference for structuring a browser-based card game with pluggable AI logic.
- Hearts fans: Play a game of Hearts in the browser at the live demo, choosing from opponents that use different strategies.
- JavaScript developers: Experiment with the
AsyncBrainwrapper to understand how to move heavy computations off the main thread using web workers.
How does Hearts with HTML5 work?
The game's decision-making is handled by the Ai.js class, which can be fed any Brain that extends the base Brain.js. AsyncBrain runs these brains inside a web worker when they become too slow. McBrain performs one-step look-ahead with sample generation and rollouts, assuming all players use the simple greedy strategy. PomDPBrain instead models the full game as a POMDP and solves it with the POMCP algorithm, also under the assumption that opponents use greedy play.
FAQ
Is Hearts with HTML5 free to play?
The game can be played online for free at http://hearts.yjyao.com/. The source code is publicly available in a GitHub repository for learning and modification.
What AI algorithms are implemented?
The project implements three decision-making strategies: SimpleBrain (greedy heuristics), McBrain (one-step look-ahead with rollouts), and PomDPBrain (POMCP algorithm for POMDP solving). AsyncBrain wraps these for web-worker execution.
Does the game support multiplayer?
Currently the project is single-player against AI. The repository's TODO list notes that multi-player support is planned.
How can I run this locally?
Since it is an HTML5/JavaScript project, you can download the repository and open the main HTML file in a browser, or serve the directory with any static file server. The live version is also available online.








