Can Python’s Minimax Reveal the Winning Strategy in Doudizhu?

This article explains how to use a Python implementation of the minimax algorithm to analyze a Doudizhu end‑game scenario, detailing the core logic, recursive hand simulation, caching optimizations, and the final result that the farmer side has no guaranteed winning strategy.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Can Python’s Minimax Reveal the Winning Strategy in Doudizhu?

Minimax

The core idea is the minimax algorithm, which splits decision making into a minimizing player and a maximizing player, similar to two opponents playing chess where each tries to maximize their own score while minimizing the opponent's.

Core Logic

A function hand_out simulates a player's move. It receives the player's hand ( me_pokers), the opponent's hand ( enemy_pokers), and the last played hand ( last_hand). The function returns true if the current player can force a win from this position, otherwise false .

Construction

Cards are represented by numbers (e.g., 3 for three, 11 for J, 12 for Q, etc.). All possible hand combinations are generated with a get_all_hands function. A comparator can_comb2_beat_comb1 checks whether one combination can beat another, respecting Doudizhu rules where only identical types are comparable except for bombs.

Efficiency

The search space grows factorially, leading to O(N!) time complexity. To mitigate repeated calculations, a cache dictionary stores results keyed by the string representation of the current hands and the last hand, reducing the effective complexity to exponential O(C^N).

Result

Running the solver shows that the farmer (the side that plays first) does not have a forced winning strategy; the landlord can always win if they play optimally. The code is released on GitHub under the MIT license for anyone to experiment with.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

algorithmPythonRecursiongame AIMiniMaxDoudizhu
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.