|
1 | 1 | # Copilot instructions for arrastools |
2 | 2 |
|
3 | | -Purpose: Help AI coding agents work productively in this repo of desktop automation tools and a PPO-based Arras AI. Scripts control keyboard/mouse, read pixels, and automate gameplay/UI flows on macOS. |
| 3 | +Purpose: Help AI coding agents work productively in this repo of desktop automation tools and a PPO-based Arras AI. Scripts control keyboard/mouse, read pixels, and automate gameplay/UI flows across macOS, Linux, and Windows. |
4 | 4 |
|
5 | 5 | ## Architecture and key files |
6 | 6 | - This is a collection of standalone Python scripts (no package/pytest). Common patterns repeat across files. |
7 | 7 | - Screen + input automation: |
8 | 8 | - `arrastools.py` — hotkey-driven macros using pynput. Listeners run at module end and spawn daemon threads via `start_*` helpers. |
| 9 | + - `arrastools2.py` — alternative version with similar functionality and cross-platform support. |
9 | 10 | - `arrasbot.py` — a watchdog that samples screen pixels with `mss`, reacts to state (disconnected/died/banned), and logs/screenshots. |
| 11 | + - `arrascopypasta.py` — copypasta automation with platform-agnostic file path handling using pathlib. |
10 | 12 | - PPO AI prototype: |
11 | 13 | - `arrasai.py` — defines PPO agent (PolicyNetwork, PPOMemory, ArrasAI) and training/exec loops over screen observations sampled in a polygon (`GAME_REGION`). Models saved to `arras_models/` (e.g., `arras_model.pt_best`). |
12 | 14 | - Assets/data: `arras_models/`, `logs/`, `copypastas/`. |
13 | 15 |
|
14 | | -## Runtime assumptions and permissions (macOS) |
15 | | -- Requires Accessibility (keyboard/mouse control) and Screen Recording permissions for Terminal/VS Code (pynput + mss). |
16 | | -- Coordinates are absolute screen pixels for a specific UI layout. Retina scaling handled manually: |
17 | | - - `arrasbot.py`: `MONITOR_INDEX` (default 1) and `SCALE` (2 on Retina, 1 on non-Retina). Convert global to local with these. |
18 | | - - If your resolution/layout differs, update `GAME_REGION` and bounds used by `arrastools.py` and `arrasai.py` (e.g., mouse x in [2,1693], y in [128,1094]). |
| 16 | +## Cross-platform support and runtime assumptions |
19 | 17 |
|
20 | | -## Dependencies used across scripts |
21 | | -- Core: `pynput`, `mss`, `numpy`. |
22 | | -- Bot: `ping3`, `Pillow`, `mss.tools`. |
23 | | -- AI: `torch`, `shapely`, `pytesseract` (requires system Tesseract), `Pillow`. |
24 | | -- Example install (Python 3.10+): pynput, mss, numpy, ping3, pillow, torch, shapely, pytesseract. |
| 18 | +### Platform detection |
| 19 | +All main scripts now include platform detection using `platform.system().lower()`: |
| 20 | +- Returns: `'darwin'` (macOS), `'linux'`, `'windows'` |
| 21 | +- Scripts print platform on startup and warn if unsupported |
| 22 | + |
| 23 | +### Platform-specific behaviors |
| 24 | +- **macOS (primary development platform)**: |
| 25 | + - Requires Accessibility + Screen Recording permissions (System Settings > Privacy & Security) |
| 26 | + - Retina displays: Set `SCALE=2` in `arrasbot.py` |
| 27 | + - Modifier keys: `Option+Arrow` for 1px mouse nudges |
| 28 | + - Coordinate system: May differ from Linux/Windows due to Retina scaling |
| 29 | + |
| 30 | +- **Linux (Arch, Debian, Ubuntu)**: |
| 31 | + - Install dependencies via package manager: `sudo apt install python3-tk tesseract-ocr` (Debian/Ubuntu) or `sudo pacman -S tk tesseract` (Arch) |
| 32 | + - Accessibility permissions may vary by DE/WM (check pynput documentation) |
| 33 | + - Standard displays: Set `SCALE=1` in `arrasbot.py` |
| 34 | + - Modifier keys: `Alt+Arrow` for 1px mouse nudges |
| 35 | + - Wayland vs X11: pynput works best on X11; Wayland may have limitations |
| 36 | + |
| 37 | +- **Windows**: |
| 38 | + - Install Tesseract OCR separately: Download from https://github.com/UB-Mannheim/tesseract/wiki |
| 39 | + - May require running as Administrator for input automation |
| 40 | + - Standard displays: Set `SCALE=1` in `arrasbot.py` |
| 41 | + - Modifier keys: `Alt+Arrow` for 1px mouse nudges |
| 42 | + - Path separators: Now handled automatically via pathlib |
| 43 | + |
| 44 | +- **Android**: |
| 45 | + - Limited/experimental support |
| 46 | + - pynput may not work on all devices |
| 47 | + - Consider using Termux with X11 server for best compatibility |
| 48 | + |
| 49 | +### Display scaling and coordinates |
| 50 | +- Coordinates are absolute screen pixels for a specific UI layout |
| 51 | +- **Critical**: Adjust based on YOUR display resolution: |
| 52 | + - `arrasbot.py`: `MONITOR_INDEX` (default 1) and `SCALE` (2 on Retina, 1 on standard displays) |
| 53 | + - `arrasai.py`: Update `GAME_REGION` polygon coordinates to match your game window |
| 54 | + - `arrastools.py`: Update mouse bounds in `on_press()` and click positions in `conq_quickstart()` |
| 55 | +- Use `arrasbot.py` CLI command `probe` to sample pixel colors and positions on your setup |
| 56 | +- Retina/HiDPI displays require coordinate conversion: multiply or divide by `SCALE` as needed |
| 57 | + |
| 58 | +## Dependencies and installation |
| 59 | + |
| 60 | +### Python requirements |
| 61 | +- **Python version**: 3.10+ recommended |
| 62 | +- **Core libraries**: `pynput`, `mss`, `numpy`, `pathlib` (built-in) |
| 63 | +- **Bot utilities**: `ping3`, `Pillow`, `mss.tools` |
| 64 | +- **AI/ML**: `torch`, `shapely`, `pytesseract`, `Pillow` |
| 65 | + |
| 66 | +### System dependencies (platform-specific) |
| 67 | +- **macOS**: Tesseract via Homebrew: `brew install tesseract` |
| 68 | +- **Linux**: `sudo apt install python3-tk tesseract-ocr` (Debian/Ubuntu) or equivalent |
| 69 | +- **Windows**: Download Tesseract installer from GitHub, add to PATH |
| 70 | +- **All platforms**: Ensure Python tkinter is installed (usually bundled) |
| 71 | + |
| 72 | +### Quick setup |
| 73 | +```bash |
| 74 | +# Create virtual environment (recommended) |
| 75 | +python3 -m venv .venv |
| 76 | +source .venv/bin/activate # Linux/macOS |
| 77 | +# OR |
| 78 | +.venv\Scripts\activate # Windows |
| 79 | + |
| 80 | +# Install dependencies |
| 81 | +pip install pynput mss numpy ping3 pillow torch shapely pytesseract |
| 82 | + |
| 83 | +# Platform-specific system packages |
| 84 | +# macOS: brew install tesseract |
| 85 | +# Linux: sudo apt install tesseract-ocr python3-tk |
| 86 | +# Windows: Install Tesseract from GitHub releases |
| 87 | +``` |
25 | 88 |
|
26 | 89 | ## How to run and control |
27 | | -- `arrastools.py` hotkeys (hold Ctrl): |
| 90 | +- `arrastools.py` / `arrastools2.py` hotkeys (hold Ctrl): |
28 | 91 | - `Ctrl+1` one/two/three presses within 2s: `$arena size` automation type 1/2/3 (`start_arena_automation`). |
29 | | - - `Ctrl+y` begin “Controlled Nuke”: click 2 points in 10s to spray `k` within rectangle (uses global mouse listener). |
| 92 | + - `Ctrl+y` begin "Controlled Nuke": click 2 points in 10s to spray `k` within rectangle (uses global mouse listener). |
| 93 | + - `Alt+Arrow` (Option+Arrow on macOS): Move mouse 1 pixel in arrow direction (for precise positioning). |
30 | 94 | - Safety: `Esc` stops activities; `Ctrl+Esc` immediate exit. |
31 | 95 | - Other examples: `Ctrl+6` double-press within 5s triggers `ballcrash()`; `Ctrl+9` runs `nuke()`; `Ctrl+m` benchmarks ball spam. |
32 | 96 | - `arrasbot.py` CLI commands (typed in terminal while running): `stop`, `setscale <1|2>`, `setmon <index>`, `dbgmon`, `screenshot`, `status`, `ping`, `probe`, `forcedisconnect`, `forcedeath`, `forcereconnect`. |
33 | | - - Logs: `logs/abss_*.log`; screenshots: `~/Desktop/abss/<session>/`. Uses `color_close()` for tolerant RGB checks. |
| 97 | + - Logs: `logs/abss_*.log`; screenshots: `~/Desktop/abss/<session>/` (Linux/macOS) or `C:\Users\<user>\Desktop\abss\<session>\` (Windows). |
| 98 | + - Uses `color_close()` for tolerant RGB checks (accounts for antialiasing). |
34 | 99 | - `arrasai.py` training: |
35 | 100 | - Hotkeys while running: `Esc` force-stop (hard exit), `p` pause/resume, `r` simulate death. |
36 | 101 | - Samples RGB at `OBSERVATION_POINTS = sample_points_in_polygon(GAME_REGION, step=10)` using `mss`; outputs: action (W/A/S/D/Space), mouse target, Sum42 head, and upgrade path. |
37 | 102 | - Models saved in `arras_models/` with suffixes `_best`, `_final`, `_interrupted` based on training flow. |
| 103 | +- `arrascopypasta.py`: Reads `.txt` files from `copypastas/` directory (uses pathlib for cross-platform compatibility). |
38 | 104 |
|
39 | 105 | ## Conventions and patterns to follow |
40 | | -- Threading: Use `threading.Thread(..., daemon=True)` for background actions; toggle with global flags (e.g., `slowballs`, `randomwalld`). Provide `start_*` helpers to avoid duplicate threads. |
41 | | -- Input synthesis: Use a single `KeyboardController`/`MouseController` per module; batch keystrokes within backtick-quoted console in-game by `controller.press("`")` … `controller.release("`")`. |
42 | | -- Color detection: Prefer `color_close(tupleRGB, tupleRGB, tol=6)` rather than strict equality to account for antialiasing/transparency. |
43 | | -- File outputs: Prefer timestamped paths from `timestamp()`; keep bot logs under `logs/` and images under `~/Desktop/abss/<session>/`. |
| 106 | +- **Threading**: Use `threading.Thread(..., daemon=True)` for background actions; toggle with global flags (e.g., `slowballs`, `randomwalld`). Provide `start_*` helpers to avoid duplicate threads. |
| 107 | +- **Input synthesis**: Use a single `KeyboardController`/`MouseController` per module; batch keystrokes within backtick-quoted console in-game by `controller.press("`")` … `controller.release("`")`. |
| 108 | +- **Color detection**: Prefer `color_close(tupleRGB, tupleRGB, tol=6)` rather than strict equality to account for antialiasing/transparency. |
| 109 | +- **File paths**: Use `pathlib.Path` for cross-platform compatibility (see `arrascopypasta.py` for example). Avoid hardcoded `/` or `\`. |
| 110 | +- **File outputs**: Prefer timestamped paths from `timestamp()`; keep bot logs under `logs/` and images under `~/Desktop/abss/<session>/`. |
| 111 | +- **Modifier key detection**: Use helper functions `is_ctrl()`, `is_alt()`, `is_modifier_for_arrow_nudge()` to handle cross-platform modifier key variants (Key.ctrl vs Key.ctrl_l vs Key.ctrl_r). |
44 | 112 |
|
45 | 113 | ## When extending |
46 | 114 | - For new macros, mirror `arrastools.py` style: add a function, a `start_*` wrapper if it loops, and wire a Ctrl+<key> branch in `on_press()` with debouncing if needed. |
47 | 115 | - For new detectors, add small, monitor-relative probes (`probe` in `arrasbot.py`) and gate user-visible actions with tolerant checks + cooldowns. |
48 | 116 | - If changing layout/resolution, update `GAME_REGION`, bounds and any hard-coded click points in `arrastools.py` (e.g., `conq_quickstart()` positions). |
| 117 | +- **Platform testing**: Test on target platforms before committing. Use virtual machines or containers for cross-platform validation. |
| 118 | +- Add platform detection at script start: `PLATFORM = platform.system().lower()` with appropriate warnings. |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +### Permission issues |
| 123 | +- **macOS**: Grant Accessibility + Screen Recording in System Settings > Privacy & Security |
| 124 | +- **Linux**: Check X11 vs Wayland; pynput may need additional configuration for Wayland |
| 125 | +- **Windows**: Run Terminal/IDE as Administrator if input automation fails |
| 126 | + |
| 127 | +### Coordinate/scaling issues |
| 128 | +- Use `arrasbot.py` command `dbgmon` to list all monitors and their properties |
| 129 | +- Use `probe` command to check pixel colors at cursor position |
| 130 | +- Adjust `SCALE` variable to match your display (2 for Retina/HiDPI, 1 for standard) |
| 131 | +- Re-map `GAME_REGION` coordinates for your screen resolution |
| 132 | + |
| 133 | +### Dependency issues |
| 134 | +- Ensure Tesseract OCR is installed system-wide and in PATH |
| 135 | +- Virtual environment recommended to isolate Python packages |
| 136 | +- Check pynput documentation for platform-specific requirements |
49 | 137 |
|
50 | | -References: `arrastools.py`, `arrasbot.py`, `arrasai.py`, `arras_models/`, `logs/`, `copypastas/`. Keep changes minimal and aligned with existing patterns. |
| 138 | +References: `arrastools.py`, `arrastools2.py`, `arrasbot.py`, `arrasai.py`, `arrascopypasta.py`, `arras_models/`, `logs/`, `copypastas/`. Keep changes minimal and aligned with existing patterns. |
0 commit comments