K-Means in Among Us

Bryant Le
Analytics Vidhya
Published in
3 min readJan 27, 2021

Solving the prime shields task using the k-means algorithm.

Working through the wire tasks in electrical and shield tasks in the shield room, I realized how easily the tasks in the game, Among Us, could be automated. Among us is a multiplayer game of teamwork and betrayal in which crewmates must complete tasks before being slaughtered by the imposter. Tasks can take from seconds to over a minute to complete. I deemed these tasks a challenge to automate.

But not all tasks were a simple click.

Some tasks, such as downloading or uploading files, require a simple click of the download button, which is not programmatically challenging. Other tasks such as clearing the chute or doing the wires may require image processing and mouse action automation. But the most challenging tasks to automate required data science.

Data science is the being able to draw conclusions from data.

There is a task called “prime shields,” in which the crewmate must fix the shields that are highlighted in red. But how do we know which shields are compromised and which ones are perfectly fine. Clicking on a shield that is currently not red will turn it red, so we would want to avoid clicking on the wrong shield. However, this problem is not as simple as the color of each shield to white or red because these shields are transparent and the background behind the shields are not uniform.

To resolve this issue, we will use the k-means clustering algorithm.

K-means clustering is a method of grouping different points. More precisely, k-means clustering is a method of vector quantization that aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean or centroid. In this scenario, we would want to group our 7 shields into two groups based on pixel color.

The k-means clustering algorithm will naturally group the shields into two groups, and the group with the darker pixeled centroid will contain the compromised shields.

In addition to using to the k-means clustering algorithm, we also used PIL for processing the image and color of the pixels and pyautogui to automate the movement of the mouse. We saved the location of each of the seven shields to know which shield is which after using our k-means algorithm so that we could click on the compromised shields.

The Python code for the prime shields task.

The GIF for the execution of the Python code.

Thanks for reading! Let me know if you have any questions or requests.

--

--

Bryant Le
Analytics Vidhya

Hello! My name is Bryant, and it has been my dream to use technology to help others. Reach out at bryantl@berkeley.edu!