gregparkes/BattleSimulator

Wrong Enemy Selection

kmcnayr opened this issue · 1 comments

Hello, I think I found an issue: every sim I run has the same problem including the example notebooks and dataset. In the very first frame of the simulation there is one and sometimes two units on one of the teams that are not displayed as arrows but as hexagons. From what I can tell these units have no dxx/dxy movement and remain stationary.

All units in the battle, including their own team target these stationary units first; they also target themselves in the initial step of the simulation which is very odd.

It seems like it always occurs with units on the first team/army that is created.

I can't find what the problem might be, here is a screenshot of the first frame of the examples/notebook1 simulation using the clone wars unit dataset.

image

Here is the output from the first frame: all of team 1 is targeting unit 2 with the exception of unit 4 which for some reason is targeting another teammate.

  x y target hp armor ddx ddy team utype
0 0.054352 -0.246322 2 20 40 0.525136 0.851019 1 1
1 0.38671 -0.093172 2 20 40 0.230794 0.973003 1 1
2 0.53523 0.532973 2 20 40 0 0 1 1
3 -0.815678 0.177755 2 20 40 0.967125 0.254303 1 1
4 1.034064 -0.82021 3 20 40 -0.880084 0.474819 1 1
5 0.650016 0.749444 2 20 40 -0.468473 -0.883478 1 1
6 0.113461 0.009714 2 20 40 0.627559 0.778569 1 1
7 -0.366717 0.80359 2 20 40 0.957817 -0.287379 1 1
8 -0.342028 -0.365436 2 20 40 0.698634 0.715479 1 1
9 1.078876 0.418672 0 20 40 -0.838797 -0.544444 1 1
10 2.318572 1.852982 9 35 45 -0.653914 -0.756569 0 2
11 1.150131 2.927896 5 35 45 -0.223753 -0.974646 0 2
12 1.138769 2.461794 5 35 45 -0.274467 -0.961597 0 2
13 2.905375 1.393993 9 35 45 -0.882115 -0.471035 0 2
14 2.353364 2.187001 9 35 45 -0.584695 -0.811253 0 2

I tracked this down to simulation._target.global_nearest.

It appears the function is supposed to return an index related to all units in M but it looks like it's only returning an index of the id_is list.

after this line:
j = _mathutils.matrix_argmin(D[id_is, :][:, id_not])

I added this line:
j = j + id_not[0]

which converts the index to the global unit index.

I believe this works but the original author will need to validate a correct solution. I suspect this is an issue with the other global target function global_close_weak, I have not tested that one I am only using random targeting.