Guard

SPGG Bot Docs

Give me your ID if you want to cross this world!

#Screen Comparator

Defined in: fc25.py, und.py (inline class) · Class: ScreenComparator

#Overview

The ScreenComparator class provides real-time screen state detection by comparing screenshots against pre-made template images. Each game has its own instance with different template folders and mask colors.

This class is defined inline within each bot script (not a shared module). The implementations are largely identical.

#Configuration Per Game

Setting FC24 FC25 Undisputed
Templates folder templates/ fc25_templates/ undisputed_templates/
Threshold 90% 90% 90%
Pixel threshold 30 30 30
Mask color Red #ff0000 Red #ff0000 Green #22ff00
Monitor interval 0.5s 0.5s 0.5s

#Constructor

ScreenComparator(templates_folder, threshold=90.0, pixel_threshold=30)
Parameter Type Default Description
templates_folder str Path to template images
threshold float 90.0 Minimum similarity %
pixel_threshold int 30 Max RGB difference per channel

#Methods

#_load_templates() → dict INTERNAL

Load all .png files from templates folder into memory as OpenCV images.


#_create_mask(template) → np.ndarray INTERNAL

Create binary mask that excludes the mask color from comparison. Pixels matching the mask color are ignored during comparison.

FC24/FC25 mask color: #ff0000 (R=255, G=0, B=0)
Undisputed mask color: #22ff00 (R=34, G=255, B=0)


#_calculate_similarity(screen, template, mask, pixel_threshold) → float INTERNAL

Calculate percentage of similar pixels in non-masked area.

Algorithm:

  1. Resize screen to match template dimensions
  2. Extract only non-masked pixels
  3. Calculate per-channel absolute difference
  4. A pixel is "similar" if ALL channels are within threshold
  5. Return (similar_pixels / total_mask_pixels) × 100

#capture_screen() → np.ndarray ACTIVE

Capture full screen using PIL.ImageGrab and convert to OpenCV BGR format.


#find_best_match() → (str, float) | None ACTIVE

Compare current screen against all templates and return the best match if above threshold.

Returns: (template_name, similarity_percentage) or None


#register_callback(callback_func) ACTIVE

Register callback function called when screen state changes.

Parameter Type Description
callback_func callable(str, float) Receives (screen_name, similarity)

#start_monitoring() ACTIVE

Start background thread that continuously monitors screen state.


#stop_monitoring() ACTIVE

Stop the monitoring thread.


#reload_templates() ACTIVE

Reload all templates from disk and rebuild masks. Triggered by F5 hotkey.


#_monitor_loop() INTERNAL

Main monitoring loop (runs in daemon thread):

  1. Call find_best_match() every 0.5 seconds
  2. If state changed → call registered callback
  3. If no match → set state to None, throttle "none" callbacks to every 2 seconds

#Template Image Format

  • Format: PNG
  • Resolution: Must match game window resolution (usually 1920×1080)
  • Naming: File name (without extension) becomes the screen_name
  • Mask: Pixels of the mask color (#ff0000 or #22ff00) are excluded from comparison

#Common Template Names

Name Game Description
start All Main menu / start screen
finished FC24/FC25 Match result screen
pause_screen FC24/FC25 Pause menu
draw_screen FC24/FC25 Draw result
winniewinner Undisputed Winner announcement
internet_error FC24/FC25 Internet connectivity popup
confirmation_botvsbot FC24/FC25 Bot vs Bot confirmation