Jump to content

Numerus - a Statistics Bot


Recommended Posts

This is a little Hannibal spin-off, a bot which does nothing except logging some stats about other players. Currently it uses print() and dbgView is one way of capturing the output. It probably needs some cleansing by hand. It should look like this:

time;id;name;civ;phase;food;wood;stone;metal;tresaure;unitsLost;unitsTrai;bldgsCons;bldgsLost;techs;popcnt;popcap;popmax;explored;kills0.6;1;Player 1;brit;village;300;300;300;300;0;0;0;0;0;2;9;20;300;8;00.6;2;Cleopatra Selene;ptol;village;300;300;300;300;0;0;0;0;0;1;9;20;300;8;02.2;1;Player 1;brit;village;300;300;300;300;0;0;0;0;0;2;9;20;300;8;02.2;2;Cleopatra Selene;ptol;village;300;300;300;300;0;0;0;0;0;1;9;20;300;8;03.8;1;Player 1;brit;village;300;300;300;300;0;0;0;0;0;2;9;20;300;8;03.8;2;Cleopatra Selene;ptol;village;250;300;300;300;0;0;0;0;0;1;10;20;300;8;05.4;1;Player 1;brit;village;300;300;300;300;0;0;0;0;0;2;9;20;300;8;05.4;2;Cleopatra Selene;ptol;village;200;300;300;300;0;0;0;0;0;1;10;20;300;8;07.0;1;Player 1;brit;village;300;300;300;300;0;0;0;0;0;2;9;20;300;8;07.0;2;Cleopatra Selene;ptol;village;150;300;300;300;0;0;0;0;0;1;10;20;300;8;0

More columns can be easily included, the attached code gives a few hints what else is available. I use an IPython Notebook to analyze the data, it is here: http://nbviewer.ipython.org/url/dl.dropboxusercontent.com/u/354885/notebooks/Numerus.ipynb

And that's me playing against another bot:

numerus01.png

numerus.zip

  • Like 3
Link to comment
Share on other sites

Awesome, do you think it's possible performancewise to plot it ingame as 'realtime' statistics somewhere in the GUI?

Don't know, haven't investigated the GUI system yet. But in principle, I'd say yes, it is only a few numbers per second, thus only a few pixel to draw. But you are the master of mod! In any case, I think it'd be worth the effort, especially new comers appreciate to know where exactly the opponent is performing better. On the other hand, having live stats from your enemy is close to cheating, right?

At second thought, at least on Linux it should be possible to live capture Numeris' output and draw it onto a separate window/canvas. This looks like a good starting point: http://www.tutorialspoint.com/python/tk_canvas.htm

Mmh, going that route, a 0 A. D. launcher is pretty close, something where one selects mod, ai, map, etc. and get live stats in return, well, no fullscreen then.

Do you speak Python?

Link to comment
Share on other sites

The gui is also scripted, but the engine is made towards drawing rectangles with textures and text, so I don't really know if you can draw per pixel in an efficient way.

Well, let's say pixels are very little rectangles and graphic stats appear only at game end, so no cheating and no efficiency headache. StatisticsTracker could possibly be extended to store all its data in an growing array with time stamp. Apparently the GUI can already ask StatisticsTracker for numbers and draw them. Where does that happen? Deep links, please :)

Link to comment
Share on other sites

Right, deep links. Sorry for being so late.

The statistics tracker: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/components/StatisticsTracker.js

This is a component per player. And at the end of each game, the Gui queries the GetStatistics for every player. That returns just a JS object. Currently it only contains the totals, but you can make the object as complicated as you want.

The gui: http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/gui/summary

Well, as I said, now it only displays numbers. I've got no idea how hard it will be to make graphs.

  • Like 1
Link to comment
Share on other sites

Thx, I think I spend the tracker a timer, but would prefer it get called on tick, any idea? Re GUI/XML, is there a way to create <objects> on the fly with JS and set size, width, height? Also where are the II_xxxx constants defined, searched all code to no success. I have already a chart panel, will make there subpanels per metric and use many little coloured dot objects per player.

gui-sketch.jpg

Like it?

Link to comment
Share on other sites

I don't think you can add Object tags on the fly. You can edit their size on the fly though.

Not sure what you want with the tracker. You can listen to the OnUpdate message to get executed every tick. But that would cause huge objects (those objects are also send to the lobby server when a game is finished). I think listening to the separate actions, and getting the time from the Timer component would help.

And what constants do you mean? Do you have a code example of where they are used?

Link to comment
Share on other sites

Hephaestion looks around and wonders if he is dreaming or seeing a chart in 0AD.

We could somehow generate those objects in a generator (like your webpage for Hannibal) and copy it over. Not ideal, but better than by hand.

Do you need to pop up a panel/page too? PostPage I think is the command. In comparison to SwitchPage which changes the major page. (I hope that's right but I'm not sure anymore. Anyway, I think you already pretty awesomely solved it.)

Link to comment
Share on other sites

> seeing a chart in 0AD

Unfortunately it is still a chart in Gimp. Generating the <objects> is a good idea and feasible. But has anybody experience if the UI can manage 8 players * 10 metrics * 100 dots? Actually I'd prefer rounded dots not squares, so these are in fact images. Do PNGs with alpha channel work?

> listen to the OnUpdate message

I want to use the tracker, because the numbers are already there. How do I make it listen to the OnUpdate message? All the stats may amount to a few kilo bytes, is that of concern?

Here is an II_xxxx example:

var cmpUnitEntityIdentity = Engine.QueryInterface(trainedUnit, IID_Identity);

Btw: anybody keen on thinking of the priorities of the metrics? What is a must have? Is units top?

// found in StatisticsTracker.js, there is more...unitsTrainedunitsLostunitsLostValueenemyUnitsKilledenemyUnitsKilledValuebuildingsConstructedbuildingsLostbuildingsLostValueenemyBuildingsDestroyedenemyBuildingsDestroyedValueresourcesGatheredresourcesUsedresourcesSoldresourcesBoughttributesSenttributesReceivedtradeIncometreasuresCollectedpercentMapExplored
Link to comment
Share on other sites

I said that the graph would be the most difficult thing. You'll have to add a new sort gui object, a graph, that accepts coordinate pairs and draws lines. That new object would have to be defined in c++.

For the OnUpdate message, just create a method in the statTracker's prototype with that name. Methods starting with On are always recognised as message handlers by the Engine.

And the IID_interface comes from components/interfaces. Registering an interface creates that global.

Link to comment
Share on other sites

The GUI scripting reference might be helpful. The only feasible way to do a graph with the current system would be by using the <repeat> element with some size manipulations similar to what options.js does during initialization. That said; at best the graph drawing code would be a mess. The best solution would be a C++ extension, but if you aren't familiar with C++ this might work in the mean time.

  • Like 2
Link to comment
Share on other sites

wow, that's coming along great. (though I wonder that you use the old buttons, I thought they were grey now .. )

* is glad that this project is so well underway. He wishes that it could also be in a real-time window, so that it could conceivably show up on his second monitor.

I think it was decided that having it ingame should be avoided due to performance + cheating in multiplayer. Though there might be workarounds and the performance impact is not certain too.

Link to comment
Share on other sites

> that you use the old buttons

Still on A15, because I figured I need to switch to dev on Linux because of better testing, stdout and such. So the charts are postponed a bit. May be you have the time to make a quick mod test on A16? You can switch metrics and toggle player on/off. Would need feedback whether GUI handling is OK. And I need an idea to nicely highlight the active metric in the menu....

gui-sketch-02.jpg

charts-02.zip

Link to comment
Share on other sites

thx man, working like a charm, though there are undefined values the charts show up:

Charts.action: undefined, undefinedshowMetric: Units, p: 1, vis: trueshowMetric: Units, p: 2, vis: trueshowMetric: Units, p: 3, vis: trueshowMetric: Units, p: 4, vis: falseshowMetric: Units, p: 5, vis: falseshowMetric: Units, p: 6, vis: falseshowMetric: Units, p: 7, vis: falseshowMetric: Units, p: 8, vis: false

post-15921-0-48047900-1401180387_thumb.j

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...