Hearts against the computer
Nobody around to play? Hearts Play can fill any table from three to six players with computer opponents. They range from a bot that plays at random to a neural network that learned the game by playing it more than a hundred thousand times.
The difficulties
- Beginner
- Plays a legal card at random. No strategy at all.
- Medium
- Hand-written strategy. Knows the standard plays and rarely blunders.
- Advanced
- A trained network. Beats the hand-written strategy decisively.
How the Advanced bot learned
Advanced is a deep Q-network, a neural network that looks at the state of the table and estimates how good each card it's allowed to play would be. What it sees is its own hand, the cards already played, the trick in front of it, who has run out of which suit, the scores, and a few summaries we built by hand, such as how exposed the Queen of Spades is.
Nobody told it which card to play. It learned by reinforcement learning, playing whole games one after another against random players and copies of itself (and, at four players, against earlier versions of the network too). It was rewarded trick by trick for taking fewer points than an even share, got a bonus for shooting the moon, and a final reward depending on where it finished.
It never trained against the hand-written Medium bot. We kept that one aside as the yardstick, to judge the networks and decide which one to publish.
A network trained for four players can't simply sit down at a six-player table: the deck, the number of cards and the shape of every trick are all different. So there's one network per table size, each trained separately. Each was tested against the Medium bot over hundreds of games before it went on the site, and at its own table size it wins more often and comes last less often.
What the bots are good for
- Learning. There's no turn timer when you play on your own, so you can take as long as you like over every card.
- Trying a table size before playing it with friends, like six-player Hearts with its two jokers.
- Filling a table. If three friends want to play at four, the host puts a bot in the empty seat, and a bot also takes over for anyone who leaves mid-game.
- A quick game. Go to Play now and one button deals you in against bots, with no room to set up.
Beating them
Beginner plays at random and takes points it could easily have avoided, so it's a good place to learn the rules. Medium plays the standard moves and rarely gives anything away, so to beat it you have to give nothing away either. For Advanced you'll need the habits in the strategy guide: keeping track of the suits, watching the Queen, and saving low cards for the end of the hand.
Pick a difficulty and a table size, and the bots are ready when you are.
Play Hearts now