# One Piece TCG — UAT Robot (simulator plugin)



Dev-only automated player for full workflow testing. **Does not modify** `Frontend/` or `Backend/`.



## What it does



- **`lib/decide.js`** — given a `gameState`, returns the next legal move (first legal action, not optimized).

- **`lib/game-server.js`** — resolves the game backend URL (local or deployed domain).

- **`ui/index-auto.html`** — production entry (game server: `https://onepiece.eti.com.hk`).

- **`ui/index-auto-local.html`** — local dev entry (game server: `http://localhost:3060`).

- **`run-uat.js`** — optional headless two-client runner (no browser).



## Game server URL (local or domain)



The robot UI runs on its own port/domain but loads CSS, assets, and Socket.IO from the **game backend**. Resolution order:



1. `?server=https://your-game-host` query param

2. `<meta name="game-server" content="...">` in the HTML file (see `index-auto.html` vs `index-auto-local.html`)

3. `localhost` / `127.0.0.1` → `http://localhost:3060`

4. Hostname `onepieceauto.*` → `onepiece.*` (same protocol)



Examples:



- Local: `http://localhost:3061/ui/index-auto-local.html`

- Production: `https://onepieceauto.eti.com.hk/ui/index-auto.html`



Headless CLI: `node run-uat.js --server=https://onepiece.eti.com.hk` or `GAME_SERVER=... node run-uat.js`



## Visual simulation (2 tabs)



**Terminal 1 — game server:**



```bash

cd Backend

PORT=3060 npm start

```



**Terminal 2 — simulator UI:**



```bash

cd robot

npm install

npm run serve

```



Open **two browser tabs**:



`http://localhost:3061/ui/index-auto-local.html`



1. Enter a captain name in each tab (optional — each tab auto-gets `Bot-&lt;id&gt;`) or use `?name=Bot-A` / `?name=Bot-B`.
2. Same **Room ID** in both tabs (`?room=uat-1` or the room input). Default `uat-1`.

3. Click **Auto: OFF** → **Auto: ON** in **both** tabs.

4. Lock ST-01 in both tabs (or let Auto handle it).



Optional query params:



- `?server=http://localhost:3000` — game backend URL
- `?room=uat-1` — room id (same in both tabs)
- `?name=Bot-A` — captain name (default: unique `Bot-<tabId>` per tab)
- `?tab=abc` — stable id for auto-generated bot name
- `?delay=800` — ms between auto steps (default `600`)



## Headless UAT (CLI)



With backend running:



```bash

cd robot

npm install

npm run uat

```



Options:



```bash

node run-uat.js --server=http://localhost:3060 --room=uat-cli --timeout=300000 --delay=80

```



Exits `0` when a winner is reached with no rejected actions.



## Syncing with main UI



`ui/js/auto-app.js` is a **fork** of `Frontend/js/app.js`. When the human UI changes:



```powershell

Copy-Item Frontend\js\app.js robot\ui\js\auto-app.js

# Re-apply auto hooks (GAME_SERVER, scheduleAutoStep, RobotDecide, assetUrl, etc.) — see git diff history.

```



Update `ui/index-auto.html` from `Frontend/index.html` when layout changes (keep auto-bar and game-server scripts).



## Delivery



The release zip (`scripts/package-release.ps1`) does **not** include `robot/`. Upload separately with `scripts/upload-robot-ftp.ps1`.

