Build a Python Bot to Automate a Simple Web Game
This tutorial explains how to create a Python-based game bot that captures the screen, analyzes order icons with image fingerprinting, and automates mouse movements and clicks to play a simple online cooking game, covering tool setup, coordinate handling, and code examples.
Many gamers are familiar with cheats, but this article shows how to build a simple game bot using Python to automate playing a web‑based cooking game.
Preparing Tools
Install autopy, Pillow (PIL) and pywin32. autopy provides cross‑platform mouse, keyboard and screen‑capture functions; Pillow handles image processing; pywin32 is optional for Windows convenience.
Screen capture can be done with any image editor (e.g., PicPick or Photoshop) that allows you to view pixel coordinates.
Moving the Mouse
The screen uses a coordinate system where the top‑left corner is (0,0) and values increase to the right and down. autopy.mouse.move(x, y) moves the cursor, but due to integer rounding the actual position may be a few pixels off. The source shows the original calculation and suggests multiplying before dividing to improve accuracy.
Clicking the Mouse
Mouse clicks are straightforward, but because the game may not react instantly, inserting a short sleep between actions is recommended.
Keyboard Operations
This particular bot does not use keyboard input.
Image Analysis
The bot captures the game screen, locates the fixed positions of customer order icons, and determines the coordinates of ingredients. Relative positions are measured once; if the game window moves, only the reference point needs updating. Screenshots are obtained with PIL.ImageGrab or autopy.
Similar Image Search Principle
To identify which dish a customer ordered, the bot creates a fingerprint of the captured icon and compares it with pre‑computed fingerprints of reference images 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 region is considered empty or not a dish.
Automating Cooking
Recipes are stored as ingredient coordinates. The bot clicks the appropriate screen locations to assemble each dish, encapsulated in a simple Python class.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
