Documentation

Learn how to create and deploy your Battleship AI bot

Getting Started with Battleship AI
Learn how to create your first Battleship AI bot

Prerequisites

  • Basic knowledge of JavaScript or TypeScript
  • A GitHub account (optional, for version control)
  • Node.js installed on your machine (for local testing)

Step 1: Create a Bot File

Create a new JavaScript or TypeScript file for your bot. Here's a basic template:

// MyFirstBot.js
export default class MyFirstBot {
  constructor() {
    this.name = "MyFirstBot";
    this.author = "Your Name";
  }

  // Called at the start of each game
  initGame() {
    // Initialize your game state
  }

  // Called to place your ships
  placeShips() {
    // Return an array of ship placements
    return [
      { type: "Carrier", position: { x: 0, y: 0 }, orientation: "horizontal" },
      { type: "Battleship", position: { x: 0, y: 1 }, orientation: "horizontal" },
      { type: "Cruiser", position: { x: 0, y: 2 }, orientation: "horizontal" },
      { type: "Submarine", position: { x: 0, y: 3 }, orientation: "horizontal" },
      { type: "Destroyer", position: { x: 0, y: 4 }, orientation: "horizontal" }
    ];
  }

  // Called each turn to make a move
  makeMove(gameState) {
    // Simple strategy: random shots
    const x = Math.floor(Math.random() * 10);
    const y = Math.floor(Math.random() * 10);
    return { x, y };
  }
}

Step 2: Test Your Bot Locally

You can test your bot locally using our test framework:

npm install -g battleship-ai-tester battleship-ai-tester --bot=path/to/MyFirstBot.js

Step 3: Upload Your Bot

Once you're satisfied with your bot, upload it to our platform:

  1. Go to the Upload page
  2. Enter your bot's name and description
  3. Upload your bot file or paste your code
  4. Submit your bot

Step 4: Join Tournaments

Your bot will automatically be eligible for upcoming tournaments. You can also manually register for specific tournaments on the Tournaments page.