-
Notifications
You must be signed in to change notification settings - Fork 9
Creating a Starter kit
An AI Starter kit is just basic code implemented to help you create an AI to compete in the design
you made really quickly. This will lead you through how the JavaScript starter kit works, a template of which can be found in /templates/starter-kits/js
This part is not language bound, so you can program an AI in any language you want for your design! (Just because your friend only codes in Rust and you are a die hard JavaScript fan doesn't mean you two can't compete!)
Other starter kit templates in other languages can be found in /templates/starter-kits and you can use them to help kickstart development for your own starter kit for your own design
AI Starter kits are suggested to contain at least two files, kit.js
(or whichever extension matches your language) and myBot.js
. It can be merged into one but for organization, splitting it up is better. Every bot must have some entry point file like myBot.js
of which the match will use to execute the bot.
kit.js
should have a Agent
class with some kind of asynchronous initialize, update
functions and a endTurn
function.
initialize
should have the agent wait for input from stdin
(standard input) if anything is being sent to the agent through match.send
in the design
in initialize(match)
.
update
should do the same thing as initialize
but is used to update the agent with new information from the match. Updates are sent to this agent through match.send
in the design
in update(match, commands)
. The agent should typically wait for some signal from the match to tell it to proceed in processing. This can either be a explicit message like match.sendAll('START')
or just the next set of update commands from the match
.
endTurn
should always just print to stdout
(standard out) 'D_FINISH\n'
Then in myBot.js
, a new kit.Agent
should be initialized as agent
and should run agent.initialize
Once initialization is completely done, then there should be a infinite while loop that runs the AI agent's code and also waits for updates through agent.update
For example, in JS this would be equivalent to
const kit = require('./kit');
// create a new agent
const agent = new kit.Agent();
// first initialize the agent, and then proceed to go in a loop waiting for updates and running the AI
agent.initialize().then(async () => {
while(true) {
// wait for update from match engine
await agent.update();
/** AI Code goes here */
let commands = [];
// push some commands in to be processed by the MatchEngine
commands.push('somecommand');
commands.push('anothercommand');
// submit commands to the `MatchEngine` and the `Match`, using ',' as the delimiter
console.log(commands.join(','));
// now we end our turn
agent.endTurn();
}
});
Note that the await agent.update()
can be moved after agent.endTurn()
if needed, this really depends on how you make the design
.