ARTICLE
How the Hazari Computer Opponent Chooses Its Cards
The computer in a Hazari game makes only one decision, how to arrange 13 cards. Here is how it searches 200,200 splits, scores them and plays at three levels.
Tags
- Hazari
- Game AI
- TypeScript
- Search
- Algorithms
Published November 24, 2026.
Building a computer opponent for Hazari turned out to be a neat small problem. After the cards are dealt, the game contains exactly one decision: how to arrange 13 cards into groups of 3, 3, 3 and 4. Everything after that, comparing groups and awarding cards, is mechanical. So the entire intelligence of the computer is how it arranges its hand.
Step 1: rank every three-card hand
A pure function classifies three cards as Troy, Colour Run, Run, Colour, Pair or Indi, with tie-break values for comparing two hands of the same type. Aces count high in A-K-Q and low in A-2-3, and a four-card group is judged by its best three cards. This part is unit-tested against the rules, including the awkward cases such as 2-A-K not being a run.
Step 2: turn a hand into a score
The computer needs to know how good a group is. It sorts all 22,100 possible three-card hands from weakest to strongest once, and the score of a group is the share of those hands it beats, with ties counting half. A Pair scores about 0.83. A Run scores about 0.98. The odds of each hand explain why the numbers look like that.
An arrangement is worth the sum of its four group scores, weighted by how many cards each round holds: 12, 12, 12 and 16. The last group is weighted more because its round holds 16 cards.
Step 3: search
The hardest level checks every split. There are 715 ways to choose the four-card group and 280 ways to divide the other nine cards into three groups, which makes 200,200 splits. About a tenth of them are legal, because the four-card group must not beat any of the others. The search keeps the legal split with the highest weighted score. Results for each group of cards are cached by which cards it holds, so the same group is never evaluated twice.
Three levels from one function
- Easy: one random legal arrangement.
- Medium: the best of 40 random legal arrangements.
- Hard: the best arrangement found by the full search.
The three levels share the scoring code and differ only in how many arrangements they look at. That also made them easy to test: the Hard level must beat the Easy level over a run of deals, and every level must always return a legal arrangement.
How strong are they?
Against three Easy players, a Medium player won all 200 simulated games, and a Hard player won all 60. Among four Easy players, no seat had an advantage: the four seats won 95, 92, 107 and 106 of 400 games.
In the arrangements the Hard search chose across 400 random hands, all four groups were a Pair or better every time. A random legal arrangement manages that in under 2% of hands.
What the model ignores
- It values a group by how it fares against random hands. It does not try to read what opponents hold.
- It does not adjust for the score. A player who is far ahead or behind plays the same.
- Nobody bluffs. Arrangements are hidden until the reveal, but there is no information to bluff with.
A deeper opponent could model other players' likely arrangements and choose a split to beat them. That is a harder problem with no obvious answer, and a good one for later.
Reproducible deals
Deals come from a seeded random number generator, so the app only needs to save a seed and the scores to rebuild the exact hands after a page reload. The pure game logic has its own unit tests, including a check that the points collected in any deal always add up to 360.
You can play against these opponents in the scorekeeper.
Play it or score it
Play Hazari alone against the computer, or keep score and share the banter with your friends. It is free and works offline.
More Hazari guides
Odds and numbers
- How Rare Is a Troy? The Odds of Every Three-Card Hand in Hazari
- Why Every Hazari Deal Is Worth Exactly 360 Points
- How Many Deals Does a Game of Hazari to 1,000 Take?
- 200,200 Ways to Arrange 13 Cards: Why Hazari Is Harder Than It Looks
Strategy
- How to Arrange Your Cards in Hazari: A Practical Guide to 3-3-3-4
- The Four-Card Group in Hazari: Weakest by Rule, Biggest Prize in the Deal
- 7 Mistakes New Hazari Players Make When Arranging Cards
- One Hazari Deal, Round by Round: A Worked Example with Real Cards
Scoring and house rules
- Scoring Hazari Round by Round: One Full Game to 1,000, Worked Through
- How to Settle a Hazari Scoring Argument in Two Minutes
- Hazari House Rules Checklist: Agree These 8 Things Before the First Deal
- Paper or App? How to Keep Hazari Score Without Arguments
Playing with friends
- Roasting Your Friends at the Hazari Table: Funny Leaderboard Tags
- Let Friends Watch Your Hazari Game Live: How to Share a Scoreboard
- Play Hazari Alone: Practise Against Three Computer Players
Behind the app
- How I Built an Offline Hazari Scoring App Friends Can Watch Live
- Building an Offline-First Scorekeeper: IndexedDB, a Service Worker and No Backend
- Designing a Read-Only Live Scoreboard With Guest Sharing
- টেক্কা, সাহেব, বিবি, গোলাম: Making a Card Game App Natural in Bangla
- Making a React App Findable: Real HTML Pages Before JavaScript Runs