Game Development 9 min read

Building a Simple Python Bot for a 4399 Mini‑Game Using autopy and PIL

This tutorial explains how to create a Python‑based automation script that captures screen images, analyzes them, and controls mouse movements to automatically play a 4399 sushi‑making mini‑game, covering tool setup, coordinate handling, image matching, and basic bot logic.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Building a Simple Python Bot for a 4399 Mini‑Game Using autopy and PIL

The article introduces a small Python project that automates a 4399 sushi‑making mini‑game by simulating mouse clicks and analyzing on‑screen images. It starts by recommending the installation of autopy , PIL , and pywin32 on Windows.

It explains how to capture screenshots using either autopy or PIL.ImageGrab , and how to locate fixed UI elements (customer avatars, ingredient slots) by measuring screen coordinates. The author notes that screen coordinates start at (0,0) in the top‑left corner and discusses the inaccuracy of autopy 's absolute coordinate conversion, showing the original and corrected formulas:

point.x *= 0xFFFF / GetSystemMetrics(SM_CXSCREEN);

point.x = point.x * 0xFFFF / GetSystemMetrics(SM_CXSCREEN);

Mouse movement is performed with autopy.mouse.move(x, y) , and a short sleep is recommended to let the game react before issuing the next click.

For image recognition, the tutorial moves beyond the exact‑match find_bitmap method (which fails with minor pixel differences) and adopts a perceptual‑hash approach. It resizes captured avatars to a fixed size (e.g., 18×13), computes a binary fingerprint, and compares fingerprints using Hamming distance:

def hamming_dist(self, hash1, hash2): return sum(itertools.imap(operator.ne, hash1, hash2))

If the distance exceeds a threshold (e.g., 50), the script assumes no dish is present at that position. Otherwise, the smallest distance identifies the requested dish.

Finally, the bot stores a mapping of dishes to ingredient coordinates and programmatically clicks the required ingredients in order, encapsulated in a simple Python class (code omitted for brevity). The author emphasizes that the bot is a learning exercise rather than a competitive cheat.

Pythonautomationimage-processingPILGame Botautopy
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

login 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.