# Replace points on a grid with numbers to maintain order

I am DMing a game of DnD and one of my players is really into fear effects, which is cool, but the effect of having monsters suffer from the "panicked" condition gets tedious to render via dice rolls.

The rule is, on the battle grid the monster will run for 1 square in a random direction, then from that new position it will move into another random adjacent square. repeat this process until its moved its full move speed.

movespeed = 6;
points = Point[
NestList[{(#[] + RandomChoice[{-1, 0, 1}]), #[] +
RandomChoice[{-1, 0, 1}]} &, {11/2, 11/2}, movespeed]];
Graphics[{PointSize[Large], points},
GridLines -> {Range[0, 11], Range[0, 11]},
PlotRange -> {{0, 11}, {0, 11}}, Axes -> True]


I have written some code that shows me the squares the monster moves through, but I would love to replace the little black dots with numbers like "1", "2",...,"6" so that I know the path it actually took.

Something like he following?

movespeed = 6;
points = NestList[{(#[] + RandomChoice[{-1, 0, 1}]), #[] +
RandomChoice[{-1, 0, 1}]} &, {11/2, 11/2}, movespeed];
c = 1;
track = MapIndexed[{#1, Sequence[#2]} &, points];
track = GatherBy[track, # [] &];
track = Text[
ToString@
If[Length[#] == 1, #[[1, 2, 1]], #[[All, 2, 1]]], #[[1, 1]]] & /@
track;
Graphics[track, GridLines -> {Range[0, 11], Range[0, 11]},
PlotRange -> {{0, 11}, {0, 11}}, Axes -> True] • Worth pointing out that the first argument to Text doesn't need to be a string Apr 18, 2021 at 22:21
• @ b3m2a1 Thanks, there is always something to learn. Apr 19, 2021 at 7:47

Here's a very small adaption to what you had that just uses MapIndexed to count positions. If a square was tracked over multiple times it only shows the latest

movespeed = 6;
points =
NestList[
{(#[] + RandomChoice[{-1, 0, 1}]), #[] +
RandomChoice[{-1, 0, 1}]} &, {11/2, 11/2},
movespeed
];
Graphics[
{
PointSize[1/(11*1.5)],
MapIndexed[
{
Point[#1],
{White, Inset[#2[], #1]}
} &,
points
]
},
GridLines -> {Range[0, 11], Range[0, 11]}, PlotRange -> {{0, 11}, {0, 11}},
Axes -> True
] 