I'm working on a cops & robbers game, and there is one single event that is very very important, the event of catching someone. I'm trying to do when any robber is catched, delete it from the robbers array. I think it must be done with WhenEvent
A cop catches a robber if the circles that define them are touching.
A visual representation can be seen here.
There is an array showing the initial positions of all (let's say cops=5 and robbers=3) the cops & robbers
The arrays are like this (the 0 is the time):
cops = 5; robbers = 3;
Array[c[#][0] &, cops]
Array[r[#][0] &, robbers]
The NDSolve
looks like this:
NDSolve[
Join[
Table[
r[i]'[t] == v[r[i][t], b[r[i][t]]~Join~Array[c[#][t] &, cops], 2],
{i, robbers}
],
Table[
c[i]'[t] == -v[c[i][t], Array[r[#][t] &, robbers], 4],
{i, cops}
],
(*initial positions*)
Thread[
Array[r[#][0] &, robbers] == {{1,2},{3,4},{5,6}}
],
Thread[
Array[c[#][0] &, cops] == {{6,5},{4,3},{2,1}}
]
],
Array[c, cops]~Join~Array[r, robbers],
{t, 0, 10},
FilterRules[{opts}, Options[NDSolve]],
Method -> {"EquationSimplification" -> "Solve"}
]
I'm guessing to put something like:
Table[
WhenEvent[
catched[i]==True,
Array[r[#][t] &, robbers]->
Cases[
Array[r[#][t] &, robbers],
Except[
r[i][t]
]
]
],
{i,robbers}
]
But doesn't work, I'm guessing because NDSolve
can't calculate with this method lists of functions that vary with time.