#!/bin/bash # Multi-bot launcher for tactical-shooter headless testing. # Launches N bot instances simultaneously, each connecting to the server. # # Usage: ./tests/run_multi_bot.sh [count] [server] [duration] # count - number of bots (default: 2) # server - server address (default: 192.168.0.127:34197) # duration - seconds per bot (default: 10) COUNT=${1:-2} SERVER=${2:-192.168.0.127:34197} DURATION=${3:-10} SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" echo "# ============================================================" echo "# Multi-bot launcher: $COUNT bots → $SERVER for ${DURATION}s" echo "# ============================================================" # Launch N bots in background, each gets a unique stdout color tag PIDS=() for i in $(seq 1 $COUNT); do PORT=$((34197 + i)) # unique but unused — just for identification echo "# Starting bot $i..." cd "$PROJECT_DIR" && \ timeout $((DURATION + 15)) \ ~/.local/bin/godot --headless --scene res://tests/bot_test_scene.tscn \ --path . -- --server "$SERVER" --duration "$DURATION" --scenario idle \ --peer-id 2>&1 | sed "s/^/[Bot $i] /" & PIDS+=($!) sleep 0.5 # stagger spawns to avoid connection thundering herd done # Wait for all bots to finish echo "# Waiting for $COUNT bots..." ALL_OK=true for PID in "${PIDS[@]}"; do wait $PID EXIT=$? if [ $EXIT -ne 0 ]; then ALL_OK=false echo "# Bot PID $PID exited with code $EXIT" fi done if $ALL_OK; then echo "# ALL $COUNT BOTS PASSED" exit 0 else echo "# SOME BOTS FAILED" exit 1 fi