Page 1 of 1

Some questions, confirm or oprovergnite my guesses

Posted: Sat Aug 01, 2009 8:38 pm
by iaiaoee
it is true that the bots could save the local variables between calls method think?

Posted: Sat Aug 01, 2009 9:12 pm
by Kender
Yes that's true.

If you use class variables then each unit can keep track of things.

For instance a city can remember how many of each unit it has built:

Code: Select all

public class Elephant{
private int[] built = new int[4];

public Object think(...
...
 public int build(...) {
  if (buildItem != 0) return 0;
  int unit = 1 + r.nextInt(3);
  if (built[unit] >= 42) return 0; // never build more than 42 of any unit type
  built[unit]++;
  return unit;
}
other units are not able to access this information though.