This AI is still in early stages of development.
Babel API
- Aubergine
Overview
While all the AIs live in Warzone, they each have their own dialect which poses some problems when they decide to communicate with each other. This API, inspired by a forum discussion, deals with those problems.
Babel makes it easier for AIs to speak to each other in different dialects via the chat() interface. It deals with the cruft so you don't have to:
- Dialect namespacing, error handling, etc.
- JSON conversions – including JS API Objects, primitive values, custom objects and arrays.
- Proper handling of Game objects if they get destroyed before the message arrives
It doesn't pollute the global object (other than backporting some JS API constants on old versions of Warzone) and stays out of your way when you're not using it. The API also has extensive unit testing to make sure it works both now and in the future.
Quick start
Include the API (get it from github)...
include("path/to/APIs/Babel.js");
Compile a simple Babel message and send it to some AI player (tip: you can find out if player .isAI
via their Player object) ...
// compile babel message... // Syntax: chat.toBabel(message[, dialect[, data[, replacer]]]) var msg = chat.toBabel( "help" ); // dialect defaults to "ai" // send compiled message via chat... chat( someAIplayer, msg );
The recipient is notified when they receive the message, can check to see if it's Babel formatted and if so decompile it...
include("path/to/APIs/Babel.js"); function eventChat(sender, to, message) { if (chat.isBabel(message)) { // decompile and use as parameters to custom event... eventChatAI.apply( this, chat.fromBabel(sender, to, message) ); } else { // from a human or lame AI } } // Custom event handler to process the decompiled Babel message... function eventChatAI(sender, to, message, dialect, data) { switch (dialect) { case "ai": { // standard dialect (all AIs should handle this) switch (message) { case "help": { // send help to player // at their beacon, or their base if no beacon break; } // etc... } break; } case "nb": { // nullbot dialect // process any nullbot messages you understand break; } // etc... case "error": { // something went wrong... // ... break; } } }
Obviously, you don't need to use switch statements – use whatever you want, there are certainly better ways to handle dialects, the above is just an example.
Compatibility with other APIs
Babel API is designed to run stand-alone but will automatically integrate with other APIs if they are available via the Dependency Checking system:
- Util API – Babel will integrate with the dependency checker
- Define API – Babel will use Define.has() and Define() when filling cracks on Warzone 3.1.
- Diag API – Babel lazy-loads diagnostic routines when Diag becomes available
- Test API – Babel lazy-loads it's unit tests when Test becomes available
- Players API – Babel will use Players API's enhanced Players Objects if available.
With the exception of Diag and Test APIs, all other APIs should obviously be loaded before loading Babel API.
If one AI is using enhanced objects (such as those provided by Players API or Defines) and another AI is using basic JS API objects, Babel will transparently convert between them. For example, if an AI sends a basic JS API Player object to an AI that has Players API installed, the receiving player will get an enhanced Players Object and vice versa.
Availability BETA
Requires:
- Warzone 3.2 or above
On Warzone 3.1, a fake chat object is created for convenience (learn more).
Contents
Jump to:
Dialect Quick Reference
Name | Dialect |
---|---|
Standard Dialect | "ai" |
Error Dialect | "error" |
NullBot | "nb" |
Ultimate Scavs | "usm" |
ContingencyBot | "cb" |
EggPlant | "ep" |
Semperfi | |
Nexus | "nx" |
Babel API
Topics:
- Data types — Babel supports most types of data...
- Error Dialect — A specific dialect for reporting errors within Babel...
- Babel on Warzone 3.1 — Babel handles Warzone 3.1 gracefully...
- Position-like Objects — If your data has {x, y} properties, Babel treats it like a Position object...
- chat.toBabel() — Compiles a Babel format message, ready for sending to your AI buddies...
- chat.isBabel() — Quickly determine if a received message is in Babel format...
- chat.fromBabel() — Converts a Babel format message in to an array...
- Handling Dialects — Some ideas on how to handle multiple dialects...