🚢 Battleship Battle Server

A competitive battleship game server where engineering teams build bots to compete via REST API. Build your bot, compete with others, and prove your coding skills!

🚀Get Started

Ready to build your battleship bot? Start with our comprehensive API documentation and example bot implementations.

Quick Start Steps:

1 Explore the API Documentation
2 Register your bot via POST /bots
3 Get automatically paired with another bot
4 Place your ships and start firing!
View API Docs

📖Documentation

Complete OpenAPI 3.0 specification with interactive Swagger UI. Test endpoints, understand schemas, and see examples.

POST /bots Register Bot
POST /games/{id}/place-ships Place Ships
POST /games/{id}/fire Fire Shot
GET /games/{id}/state Get Game State
Explore API

👀Watch Live Games

Spectate ongoing battles and learn from other players' strategies in real-time.

Spectator Features:

👁️ View live game boards and moves
📊 See player statistics and accuracy
🔄 Auto-refreshing game updates
🏆 Filter by game state and status
Watch Games

🎯Example Bot

Learn by example! Here's how to register a bot and start playing:

# Register your bot curl -X POST https://battleship.lab.voze.com/bots \ -H "Content-Type: application/json" \ -d '{"name": "MyAwesomeBot"}' # Response includes game assignment { "playerId": "uuid", "gameId": "uuid", "accessToken": "jwt_token", "refreshToken": "refresh_token" }
See Full Examples

🤖 Building Your Bot

Bot Lifecycle

1

Register & Get Game ID

Register your bot and receive a game ID immediately. The server automatically pairs you with another bot or puts you in queue.

POST https://battleship.lab.voze.com/bots {"name": "MyAwesomeBot"} // Response includes immediate game assignment { "playerId": "uuid", "gameId": "uuid", // ← Your game ID! "accessToken": "jwt_token", "refreshToken": "refresh_token" }
2

Monitor Game State

Poll game state to detect when both players are ready. Game progresses from WAITING_FOR_PLAYERS → PLACING_SHIPS → IN_PROGRESS.

GET https://battleship.lab.voze.com/games/{gameId}/state // Game states: // "WAITING_FOR_PLAYERS" - Need opponent // "PLACING_SHIPS" - Ready to place ships // "IN_PROGRESS" - Game active // "COMPLETED" - Game finished
3

Place Ships

Strategically place all 5 ships when game state is PLACING_SHIPS. Each ship has a specific size:

POST https://battleship.lab.voze.com/games/{gameId}/place-ships { "ships": [ { "type": "CARRIER", // Size: 5 spaces "startPosition": {"x": 0, "y": 0}, "orientation": "HORIZONTAL" }, { "type": "BATTLESHIP", // Size: 4 spaces "startPosition": {"x": 0, "y": 2}, "orientation": "HORIZONTAL" }, { "type": "CRUISER", // Size: 3 spaces "startPosition": {"x": 0, "y": 4}, "orientation": "HORIZONTAL" }, { "type": "SUBMARINE", // Size: 3 spaces "startPosition": {"x": 0, "y": 6}, "orientation": "HORIZONTAL" }, { "type": "DESTROYER", // Size: 2 spaces "startPosition": {"x": 0, "y": 8}, "orientation": "HORIZONTAL" } ] }
4

Fire & Monitor

Poll game state to wait for your turn, then fire at coordinates and repeat until completion

// Check if it's your turn GET https://battleship.lab.voze.com/games/{gameId}/state // When isYourTurn is true, fire POST https://battleship.lab.voze.com/games/{gameId}/fire {"coordinate": {"x": 5, "y": 3}}

Strategy Tips

🎯

Ship Placement

Avoid predictable patterns. Use board dimensions dynamically and query game rules programmatically.

🧠

Firing Strategy

Consider probability-based targeting after hits. Balance systematic searching vs random shots.

🔍

Hunt Mode

Use systematic patterns to efficiently search for enemy ships across the board.

🎲

Target Mode

When you hit a ship, focus on sinking it completely before moving to new areas.

🔄

Adaptability

Query /api/docs for current rules rather than hardcoding assumptions about board size.

📊

State Tracking

Maintain probability maps and track opponent patterns for predictive targeting.

🔑 Registration & Game Assignment

Understanding how bots get matched and games begin:

1. Immediate Game Assignment

When you register, you receive a game ID immediately - no waiting required. The server either pairs you with an existing waiting bot or puts you in queue for the next registration.

2. Game State Monitoring

Use the game ID to poll GET /games/{gameId}/state and watch for state transitions:

  • WAITING_FOR_PLAYERS - You're registered but need an opponent
  • PLACING_SHIPS - Opponent found! Time to place your ships
  • IN_PROGRESS - Both players ready, game active
  • COMPLETED - Game finished

3. Example Registration Flow

// 1. Register and get immediate game assignment
const registration = await fetch('/bots', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'MyBot' })
});
const { gameId, accessToken } = await registration.json();

// 2. Monitor game state until ready
async function waitForGameStart() {
  while (true) {
    const response = await fetch(`/games/${gameId}/state`, {
      headers: { 'Authorization': `Bearer ${accessToken}` }
    });
    const gameState = await response.json();
    
    if (gameState.state === 'PLACING_SHIPS') {
      console.log('Game ready! Start placing ships');
      return gameState;
    }
    
    console.log('Current state:', gameState.state);
    await new Promise(resolve => setTimeout(resolve, 2000));
  }
}
              

Example Bot Structure

class MyBot {
  async register(name: string) {
    // Register with server and store auth tokens
    const response = await fetch('https://battleship.lab.voze.com/bots', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ name })
    });
    return response.json();
  }

  async placeShips(gameId: string, token: string) {
    // Implement your ship placement strategy
    const ships = this.generateShipPlacements();
    return fetch(`https://battleship.lab.voze.com/games/${gameId}/place-ships`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ ships })
    });
  }

  async waitForTurn(gameId: string, token: string) {
    // Poll until it's your turn or game ends
    while (true) {
      const response = await this.getGameState(gameId, token);
      const gameState = await response.json();

      if (gameState.state === 'COMPLETED') {
        console.log('Game completed!', gameState.winner);
        break;
      }

      if (gameState.isYourTurn) {
        console.log('It\'s your turn!');
        return gameState;
      }

      // Wait 2 seconds before polling again
      await new Promise(resolve => setTimeout(resolve, 2000));
    }
  }

  async makeMove(gameId: string, token: string) {
    // Implement your firing strategy
    const coordinate = this.calculateNextShot();
    return fetch(`https://battleship.lab.voze.com/games/${gameId}/fire`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ coordinate })
    });
  }

  async getGameState(gameId: string, token: string) {
    // Poll for game updates
    return fetch(`https://battleship.lab.voze.com/games/${gameId}/state`, {
      headers: { 'Authorization': `Bearer ${token}` }
    });
  }
}

Example Game State Response

When it's your turn, the game state response will look like this:

{
  "gameId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "state": "IN_PROGRESS",
  "isYourTurn": true,
  "boardDimensions": {
    "width": 10,
    "height": 10
  },
  "yourBoard": {
    "hits": [
      {"x": 2, "y": 3},
      {"x": 5, "y": 7}
    ],
    "misses": [
      {"x": 0, "y": 0},
      {"x": 1, "y": 1}
    ],
    "shipsRemaining": 4
  },
  "opponentBoard": {
    "hits": [
      {"x": 6, "y": 2},
      {"x": 8, "y": 4}
    ],
    "misses": [
      {"x": 3, "y": 3},
      {"x": 9, "y": 9}
    ],
    "shipsRemaining": 3
  },
  "winner": null
}
          

Key fields to monitor: isYourTurn indicates when you can fire, state shows game progress, and boardDimensions provides current board size for coordinate validation.

Built with ❤️ for the engineering community • Health CheckAPI Docs