Kozma Hunor
Kozma Hunor

PhasmoBot

A Python-based AI bot that automates Phasmophobia gameplay using image recognition.

The Challenge

Phasmophobia is a time-consuming game, and I was interested in whether I could write a bot that could play without human intervention, navigate the menus, and perform the basic tasks of the game, like selecting a ghost.

My Solution

I developed a Python script that uses the OpenCV library to analyze the game screen. The bot operates based on a state machine and identifies buttons and menu items using predefined image templates (template matching). It simulates mouse movements and clicks with the `pydirectinput` library to perform the necessary steps in the game, from the main menu to selecting the ghost.

Tech Stack

  • Python: It was an ideal choice for rapid prototyping and for the available image processing libraries.
  • OpenCV: The key element of the project, this library provided the real-time image recognition capabilities with which the bot 'sees' the game.
  • pydirectinput: Enabled low-level input simulation, which worked more reliably with games than the traditional `pyautogui`.

Technical Deep-Dive

The most exciting part was fine-tuning the bot's 'eye'. Simple template matching was not always robust enough for changing lighting conditions or minor graphical updates in the game. Therefore, I implemented a feature that searches for templates in several, slightly different sizes and grayscale versions, and accepts the match with the highest confidence score. This significantly increased the bot's accuracy and reliability in recognizing UI elements.