Skip to content

battlecode/battlecode-playback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

battlecode-playback 📼

Analyze battlecode match files programmatically.

Contributing

Before you commit, you HAVE to run npm run build and commit the changes in the out/ directory. This is a slightly painful fact due to typescript, sorry.

Quick sample:

Install node.

$ npm init
$ npm i --save battlecode-playback
$ $EDITOR analyze.js

analyze.js:

const bc = require('battlecode-playback');

let aliveRobots = {};
let lifetimes = [];

bc.stream('match.bc17').on('spawn', spawnEvent => {
  aliveRobots[spawnEvent.bodyId] = {
    born: spawnEvent.round
  };
}).on('death', deathEvent => {
  let lifetime = death.round - aliveRobots[deathEvent.bodyId].born;
  delete aliveRobots[deathEvent.bodyId];
}).on('close', () => {
  console.log('Average robot life length: ' +
    (lifetimes.reduce((a,b) => a+b, 0) / lifetimes.length));
});