Game Development 11 min read

Python Implementation Guide for the "Gan Zi Lao Hu Ji Chong" Game

This article provides a step‑by‑step Python programming tutorial for the traditional Chinese two‑player game "Gan Zi Lao Hu Ji Chong", detailing numeric mappings, conversion functions, round evaluation, and probability simulation to help learners build and test the game logic.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Implementation Guide for the "Gan Zi Lao Hu Ji Chong" Game

This document describes a Python programming project that implements the traditional Chinese two‑player game “Gan Zi Lao Hu Ji Chong”, mapping the four gestures to numeric codes and providing functions to convert between names and numbers, generate random gestures, evaluate a round, and simulate multiple rounds to estimate probabilities.

The core functions include

def name_to_number(name):
    if name == "虫子":
        return 0
    elif name == "鸡":
        return 1
    elif name == "老虎":
        return 2
    elif name == "杠子":
        return 3
    else:
        return -1

,

def number_to_name(number):
    if number == 0:
        name = "虫子"
    elif number == 1:
        name = "鸡"
    elif number == 2:
        name = "老虎"
    elif number == 3:
        name = "杠子"
    else:
        name = "所喊无效"
    return name

,

def shout_out(name):
    if name == "随机":
        number = random.randrange(0, 4)
    else:
        number = name_to_number(name)
    return number

,

def play_one_round(player1_name, player1_code, player2_name, player2_code, print_msg=True):
    # main game logic
    de_code = player1_code - player2_code
    # determine result based on de_code
    # return 0 for tie, 1 for player1 win, 2 for player2 win
    # optional printing when print_msg is True
    return res_ben

, and

def result_probability():
    play_times = 0
    player1_win_times = 0
    player1_loss_times = 0
    tie_times = 0
    # repeat play_one_round many times, update counters
    # calculate and print probabilities
    return

, each with logic for handling invalid inputs and optional output.

Instructions guide the developer through implementing each function step‑by‑step, testing them with sample calls, and extending the simulation to verify theoretical probabilities (win, tie, loss) for the players.

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.

simulationPythonprobability
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

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.