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.
Reading font

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.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.