2026-09-05 21:10:18 +00:00
# botWebWars
2026-09-05 22:09:18 +00:00
A FastAPI and React-based web arena featuring a real-time **64 × 64 grid** with coordinates ranging from `(0, 0)` to `(64, 64)` . Players/bots register with their name, color, and strength, remember everywhere they have been, seek other bots to form **Parties** , take turns moving around the arena, and engage in **3-bout D20 tactical battles** .
2026-09-05 21:10:18 +00:00
---
## Features
2026-09-05 22:09:18 +00:00
### 1. Bot Location Memory & Awareness
- **Location Awareness**:
- Every bot knows its current coordinate `(x, y)` and tracks a memory history of all coordinates it has visited.
- Queryable via `GET /api/players/{player_id}/memory` .
- Enables bots to remember if they have visited a location before to avoid looping and explore unvisited territory.
- **Bot Seeking & Radar**:
- Bots can actively seek other bots via `GET /api/players/{player_id}/radar` .
- Scans for nearest friendly/neutral bots to recruit into a party, or detects enemy squads to engage in battle.
### 2. Parties & Squad Formations
2026-09-05 21:55:07 +00:00
- **Goal & Linked Connectivity**:
2026-09-05 22:09:18 +00:00
- Bots seek each other out to join together as a **Party** .
2026-09-05 21:55:07 +00:00
- All party members must be within **1 distance** of each other (Chebyshev distance $\le 1$, including diagonals and cardinals), forming linked connections (clusters or single-file lines).
- Bots must agree on a **Party Leader** .
2026-09-05 22:09:18 +00:00
- **Party Strength**:
- Each bot has a default **strength of 1** .
- Total party strength is the sum of all bots in the party:
$$\text{Party Strength} = \sum_{b \in \text{Party}} \text{bot.strength}$$
2026-09-05 21:55:07 +00:00
- **Leader Group Movement**:
- The Party Leader controls the movement for the entire squad.
- All party members translate together in the chosen direction (preserving their relative shape and linked adjacency).
- If any party member's path is blocked by an outside bot or boundary wall, the entire group move is prevented.
- Non-leader party members cannot move independently.
2026-09-05 22:09:18 +00:00
### 3. 3-Bout D20 Battle Mechanics & Scoring Rules
- **Engagement**:
- When two opposing parties engage (move into adjacent contact or call battle), a battle must be fought.
- **3-Bout Resolution with D20 Roll Multiplier**:
- Each battle consists of **3 bouts** .
- In each bout, both parties roll a **20-sided die (D20)** (random number from 1 to 20).
- The roll acts as a multiplier on the party's total strength:
$$\text{Bout Score} = \text{Party Strength} \times \text{D20 Roll}$$
- The party with the higher bout score wins that bout.
- The overall battle winner is the party that scores the higher outcome across the 3 bouts.
- **Battle Scoring Rules**:
- **Winning Party Leader**: Receives ** +2 points**.
- **Rest of Winning Party**: Each member receives ** +1 point**.
- **Losing Party Leader**: Receives ** -1 point**, loses leadership, and respawns at a random free position.
- **Rest of Losing Party**: Loses **0 points** (scores remain unchanged).
- **Surrender & Absorption**:
- The **remainder of the defeated party joins the winning party** !
- Surviving bots have their party affiliation updated to the winning party.
- The winning squad grows in size and increases its total strength, and the round continues.
### 4. Turn-Based 8-Directional Movement
2026-09-05 21:55:07 +00:00
- **8 Directions**:
- Cardinal: `UP` , `DOWN` , `LEFT` , `RIGHT`
- Diagonal: `UP_LEFT` , `UP_RIGHT` , `DOWN_LEFT` , `DOWN_RIGHT`
- **Collision & Wall Avoidance**:
- Cannot break through boundary walls `[0..64, 0..64]` .
- Cannot move into cells occupied by outside bots.
2026-09-05 21:20:39 +00:00
---
2026-09-05 21:55:07 +00:00
## REST API Endpoints
2026-09-05 22:09:18 +00:00
### Intelligence & Memory Endpoints
- `GET /api/players/{player_id}/memory` : Retrieve a bot's current location, count of visited locations, and visited coordinates history.
- `GET /api/players/{player_id}/radar` : Scan for nearby bots, calculate distances, classify allies vs enemies, and provide recommended navigation direction (`seek_join`, `engage_battle` , `explore_unvisited` ).
2026-09-05 21:55:07 +00:00
### Party & Battle Endpoints
- `POST /api/parties` : Form a party directly.
- Body: `{"member_ids": ["bot_1", "bot_2"], "leader_id": "bot_1", "name": "Squadrons"}`
2026-09-05 22:09:18 +00:00
- `GET /api/parties` : List all active parties, leaders, members, and total strength.
2026-09-05 21:55:07 +00:00
- `POST /api/parties/{party_id}/defeat` : Trigger party defeat.
2026-09-05 22:09:18 +00:00
- `POST /api/battles/fight` : Initiate a 3-bout D20 battle between two adjacent parties/bots.
2026-09-05 21:55:07 +00:00
- Body: `{"challenger_id": "bot_1", "defender_id": "bot_2"}`
2026-09-05 22:09:18 +00:00
- Awards ** +2 pts** to winning leader, ** +1 pt** to winning members, ** -1 pt** to losing leader, **0 pts lost** for losing members, and absorbs surviving bots into the winning squad!
2026-09-05 21:55:07 +00:00
### Movement & Turn Endpoints
- `GET /api/players/{player_id}/available-moves` : Checks availability of all 8 directions (for a solo bot or the whole party if leader).
- `GET /api/players/{player_id}/check-move?direction={DIR}` : Check single direction.
2026-09-05 22:09:18 +00:00
- `POST /api/players/{player_id}/move` : Move bot or entire party if leader. Automatically detects and resolves battles upon engagement.
2026-09-05 21:55:07 +00:00
- `POST /api/players/{player_id}/pass` : Pass turn to next player.
- `GET /api/turn` : Get current turn status, round number, and turn queue.
### Player & Board Endpoints
2026-09-05 22:09:18 +00:00
- `POST /api/players` : Register a new player with `name` , `color` , and optional `strength` (default 1).
2026-09-05 21:55:07 +00:00
- `GET /api/players` : List active players and their scores.
- `GET /api/board` : Full board state, player positions, parties, and turn data.
- `POST /api/board/reset` : Clear board, players, and parties.
2026-09-05 22:09:18 +00:00
- `/ws` : Real-time WebSocket connection broadcasting player joins, squad movements, party formations, 3-bout D20 battles, defeats, and turn changes.
2026-09-05 21:10:18 +00:00
---
2026-09-05 21:55:07 +00:00
## Quick Start with Docker
2026-09-05 21:10:18 +00:00
```bash
2026-09-05 21:55:07 +00:00
# Build and run with Docker Compose
docker compose up --build
2026-09-05 21:10:18 +00:00
```
2026-09-05 21:55:07 +00:00
Open [http://localhost:8000 ](http://localhost:8000 ) in your browser.
2026-09-05 21:10:18 +00:00
2026-09-05 21:55:07 +00:00
### Running Backend Test Suite
2026-09-05 21:10:18 +00:00
```bash
2026-09-05 21:55:07 +00:00
docker run --rm botwebwars:test pytest backend/tests
2026-09-05 21:10:18 +00:00
```