Agent X

bots don’t cheat

Read this first

Milestone: Villages

screenshot0008.png

Almost one year ago I started on this project. It still looks promising, I’ve found work-arounds for all road blocks and nearly all abstractions are in place and working. That means I from now I build on code I’ve written myself. No one is left to blame except the guy in the mirror.

Why is this a milestone? Well, running the demo is clearly not impressive, but is proves a few important things:

  • The triple store + query language deals with all 14 civilizations
  • 8 Hannibal run simultaneously without logical interfering
  • Map processor reliably finds free places for new buildings
  • The economy model prioritize units by cost or other properties
  • The groups and their DSL just workTM
  • The event system properly identifies external events and fires the internal ones
  • The 0 A.D. Bot API is stable enough to rely on, even in Alpha stage.
  • Hannibal and SpiderMonkey 31 are a good team :)

screenshot0010.png

The...

Continue reading →


Simple Lists with ES6/Harmony Proxies

If you are into meta programming proxies are the most outstanding addition to JavaScript. Together with apply(), call() they allow to nicely abstract from build-in features and help to create domain specific languages.

I was in need of simple lists spending a vocabulary like head, tail.

var lst = list(1, 2, 3, 4);
lst.head  // 1
lst.tail  // 2, 3, 4

Before ES6 you had two choices either extend the prototype of arrays (dangerous) or code your own library. With proxies you can avoid the former and simplify the latter. Here’s the first, second, third attempt:

function list(){
  var 
    ap     = Array.prototype,
    arr    = ap.slice.call(arguments),
    copy   = Array.apply.bind(Array, Array, arr),
    slice  = ap.slice.bind(arr),
    concat = ap.concat.bind(arr),
    multiply = function(m){
      return concat.apply(null, 
        Array.apply(null, {length: m -1}).map(() => arr));
...

Continue reading →


Realtime JavaScript

100 - 200 milliseconds, that’s the time a bot has each tick to do its stuff. Included are path finding, building placement, unit management, combat planning, village layout and resource planning + allocation.

It is a relief to not write JavaScript against 5 or more browsers on mobile, tablet or desktop. With 0 A.D. there is only one engine and the current version already implements many ES6 features like fat arrows, sets, maps and more. However finding the sweet spot and have SpiderMonkey generating fast code is not exactly intuitive. Here is an example showing different ways of calling a function with multiple parameters:

// Call
  o.f.call(o, d, e, f)     // 15,702,342 ops/sec

// Call with null
  o.f.call(null, d, e, f)  // 15,399,460

// Direct
  o.f(d, e, f)             // 15,062,388

// Apply predefined array
  o.f.apply(o, z)          //  4,197,047

// Apply
  o.f.apply(o, [d,
...

Continue reading →


On Writing a RTS Bot

I’ve started looking for a new challenge in 2014 and after three months of contemplation my deeper mind returned: Write a bot. And I accepted. A few decision had to be made, e.g. which language and which domain? The latter was easy, it should be a game, a 3D game. At that moment I realized I can’t code C nor C++. Will I find a game where JavaScript or Python does any good?

After a bit of searching 0 A. D. appeared on the radar and I got excited: It already has one bot written with JavaScript and it is an Open Source RTS Game with binaries for Windows, Mac and Linux. A perfect match. On top the art team seems to be very capable. Visual pleasure is a powerful motivation at least for me.

Then I’ve dug the forum, the bot’s sources, the TRAC repository, old and new tickets to get an idea about the volume of work I was willing to accept. Interestingly writing bots for RTS games includes...

Continue reading →