# Track Player Movement in a First-Person Shooter Game

In a first-person shooter game, an agent is hiding inside a level and waiting to jump out at the player. The agent cannot see the player, but can hear what they are doing and can then match that against its knowledge of the layout to estimate the players position. Consider a layout with 27 regions of four typesgrass, metal grates, water, and door portals.

Assign colors to the different types of regions.

 In[2]:= Xcolors = Transpose[{{grass, Green}, {metal, Gray}, {water, Blue}, {door, Brown}}];

Walking on the different terrain types produces different kinds of sounds.

 In[3]:= X{none, footsteps, splashing, creaking, unclear} = Range[5];

Probabilities of giving out sounds depends on the terrain type.

 In[4]:= Xem = SparseArray[{ {{grass, none}, {grass, unclear}} -> {0.9, 0.1}, {{metal, none}, {metal, footsteps}} -> {0.1, 0.9}, {{water, splashing}, {water, unclear}} -> {0.9, 0.1}, {{door, creaking}, {door, unclear}} -> {0.9, 0.1}}, {27, 5}];

Visualize the layout of the level.

 Out[7]=

Assume the player enters through one of the doors with equal probability.

 In[8]:= Xp0 = SparseArray[{door -> 1/Length[door]}, 27];

The player remains in the current region with probability 10%, and otherwise is equally likely to move to any of the neighboring regions.

 In[10]:= Xhmm = HiddenMarkovProcess[p0, tm, em];

The agent hears the following sequence of noises.

 In[11]:= Xobs = {creaking, none, footsteps, none, none, splashing, splashing, footsteps, splashing};

This shows that most likely the player entered through the door marked 27 and is currently in region 7.

 In[12]:= XFindHiddenMarkovStates[obs, hmm] /. MapThread[v : #1 :> Framed[v, FrameStyle -> #2] &, colors]
 Out[12]=

## Mathematica + Mathematica Online

Questions? Comments? Contact a Wolfram expert »