I used collaborative diffusion in my bot as well. Even though I'm happy with the results, I have some questions on whether I was doing things correctly.
I had two double arrays (for each type of scent, I had four scents in my bot: defend, explore, enemy_hills, and enemy_ants),
double[][] values - initialized to 0 at start of game
boolean[][] sources - initialized to false at start of each turn
On each turn, I place values in certain cells depending on state of the game (i.e. 100.0 for unexplored square) and at the same time I set the corresponding source boolean to true. I then proceed to diffuse in the following fashion,
- Code: Select all
double tmpValues[][];
for (int row = 0; row < maxRows; row++) {
for (int col = 0; col < maxCols; col++) {
next if water[row][col]
if sources[row][col] {
tmpValues[row][col] = values[row][col]
} else {
tmpValues[row][col] = sum of values of neighbors(row,col) / number of neighbors(row,col)
}
}
}
values = tmpValues
When looking at neighbors, I would exclude water and thus a cell could have 4, 3, 2, 1, and in theory 0 neighbors. But for demonstration here, that's not important.
So starting with all 0 and placing a single 100 source at the center,
- Code: Select all
0 0 0 0 0
0 0 0 0 0
0 0 100 0 0
0 0 0 0 0
0 0 0 0 0
and after one step of diffusion, I would get,
- Code: Select all
0 0 0 0 0
0 0 25 0 0
0 25 100 25 0
0 0 25 0 0
0 0 0 0 0
and after another step of diffusion, I would get,
- Code: Select all
0 0 6.25 0 0
0 12.5 25 12.5 0
6.25 25 100 25 6.25
0 12.5 25 12.5 0
0 0 6.25 0 0
As you can see the numbers drop off very very fast (even though next iteration the 25 will actually become 12.5 + 100 + 12.5 + 6.25 / 4). In general, it takes many iteration to spread source information around. This becomes particularly a problem when trying to spread information about an ant hill far far away from that ant hill. In fact, I could not seem to iterate enough even in few turns to spread this information far and strongly enough. Eventually, I ended up using the following diffusion for ant hills,
- Code: Select all
tmpValue[row][col] = max of values of neighbors(row,col) * decay factor
with high decay factor somewhere in the 0.95 - 0.99 range, the spread is very fast even over large maps.
I am wondering whether my diffusion function (average of 4 neighbors) was flawed? or are these normal problems of diffusion?