Wild West - Competitive JavaScript!


Write your own AI

Creating a JS bot for playing Wild West is not a difficult task. You need only minimum JavaScript syntax knowledge, programming experience is advantageous but not necessary.
For easy reference, a sample bot was created. You can view its source at bots/sample.js

How to write a bot

Every Wild West bot is an instantiable JavaScript object. In other words, your bot must be declared as function myBot() {} and not var myBot = {}. Apart from this basic declaration, the object in question must implement six easy methods (functions). Their names, parameters and return values are described below.

  1. getName()
    This method is called without arguments and returns a single string - the name of your bot.
  2. getAuthor()
    This method is called without arguments and returns a single string - your name.
  3. getVersion()
    This method is called without arguments and returns a single number - your bot's version.
  4. prepare(myIndex, arrayOfTeams)
    Game engine executes this method once, before the match starts. This is used to let players know about their competitors. Argument myIndex tells the bot its index in players table (starting from zero). Second argument, arrayOfTeams, informs about teams participating in the game: for every player, the array contains name of his team. This means that arrayOfTeams[myIndex] is the team in which your bot plays.
    This method doesn't return anything.
  5. playRound()
    The core method: it is called every round and is used to find out what action your bot performs. There are no arguments passed to playRound().
    This method must return an array with two elements: chosen action and action target. Chosen action is one of the following four predefined constants: ACTION_BLOCK, ACTION_ARM, ACTION_SHOOT, ACTION_DANDY. These correspond to four allowed actions available in game rules. Action target makes sense only for ACTION_SHOOT and is equal to the index of a player you want to shoot at.
  6. roundResults(arrayOfActions, arrayOfLives)
    This method is called at the end of every round. Its purpose is to notify players about what other bots decided to do. First argument is an array, whose length equals to number of players. Each item is a value returned by playRound() of the respective player. Second argument is also an array, but contains only boolean values, specifying state of each player. True == alive, false == dead.
    This method doesn't return anything.

How to obey the rules

When designing your AI, please keep in mind these useful suggestions:

How to use a bot

First of all, you are strongly encouraged to test your bot in the Arena. For this purpose, you can download Arena in the download section. Once you have the Arena working, just include your bot's .js file and add constructor name to bots array.
When you are satisfied with your masterpiece, feel free to send it to me! I will happily include your bot in the official Arena, so you can compete against other players!