Jump to content

AI graphing


Recommended Posts

I thought it would be useful to get some stuff graphed for testing AI's.

Basically I added this to my AI so in this case it graphs the number of units that the AI has.


log("graph::units:" + gameState.getOwnEntities().filter(Filters.byClass("Unit")).length + ":" + gameState.getPlayerID() + ":" + gameState.timeElapsed);

units and gameState.getOwnEntities().filter(Filters.byClass("Unit")).length are what you would change. You can graph lots of stuff simultaneously (though you need to add more colors to the styles variable in the python script).

Then I wrote a quick and dirty python script to graph it using matplotlib (comes as part of scipy).


import re
import pylab as p

f = open('{path to logs folder}/mainlog.html', 'r')

log = f.read()

r = re.compile("graph\:\:\S+\:[0-9]+(\.[0-9]+)?")

vals = re.findall(r"graph\:\\S+)?\[0-9]+(\.[0-9]+)?)?\[0-9]+)?\[0-9]+(\.[0-9]+)?)?", log)

#print vals

a = {}
for i in vals:
key = i[0] + " Player " + i[3]
if not key in a:
a[key] = [[],[]]
a[key][0].append(i[1])
a[key][1].append(float(i[4])/1000.0)

f1 = p.figure()
p.grid()

count = 0
styles = styles = ['r-', 'g-', 'b-', 'k-', 'm-', 'r--', 'g--', 'b--', 'k--', 'm--', 'r:', 'g:', 'b:', 'k:', 'm:']
for key in a:
count += 1
p.plot(a[key][1], a[key][0], styles[count], label=key)

p.legend(loc='best')

f1.savefig("out.png")

And thus you get prettiness.

MKuPs.png

Link to comment
Share on other sites

We can also hook stuff into the rest of the simulation system for more fun. I spent a while trying to work out how to get the resources gathered stat in the AI and then realized that it would be dead easy to add some code to the statistics component.

Link to comment
Share on other sites

It's a simplified version of the Achievements Timeline from Age of Kings :)

So the graph suggests qBot reached a population of 300 in under 25 minutes?

We should put something like this in game at some point. Yes, I disabled the attack component though, normally stuff would have died much earlier.

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...