Part of why people enjoy games is the sense of agency. You make a choice, you see the result straight away, and you know it was you who caused it.
For someone recovering from a stroke, that feeling is often missing from daily life. Sensorimotor impairment limits what they can do, and many were fully independent before. A game can help with motivation, but only if they feel they’re winning through their own effort. Give them too much help and the game plays itself: the score goes up, but the sense of agency goes down, and so does the motivation to keep going.
So the question is how to help a player without taking away their control. This simulation is a proof of concept built at CMC Vellore. Nothing was tested with people.
Code: Zilch123/AgentAssistance-RL
The game
The game is a 4×4 grid. The player starts in one corner (S) and has to reach the goal (G) in the opposite corner, avoiding a trap (T) on the way. They can move in 8 directions: up, down, left, right and the four diagonals.
| Event | Reward |
|---|---|
| Reach the goal | +10 |
| Step on the trap | -5 |
| Any other step | -1 |
The -1 per step means fewer moves is better.
Step 1: learn the best moves with Q-learning
First, an agent learns the game with Q-learning. The Q-table has one value for each square and each of the 8 moves, so it’s 4×4×8. After training, the highest Q-value in each square points to the best move from there.
num_episodes = 600
gamma = 0.99
eps = 0.05
lr = 0.01
for ep in range(num_episodes):
data = env.reset()
s_0 = data[0]
done = False
rewards = 0
while done == False:
if np.random.rand() < eps:
# Random Action 5% of the time
action = np.random.choice(env.action_space)
else:
# Deterministic Action- max q value
action = np.argmax(q_table[s_0[0], s_0[1]])
s_1, reward, done = env.step(action)
q_table[s_0[0], s_0[1], action] += lr*(reward + \
gamma*np.max(q_table[s_1[0], s_1[1]]) \
- q_table[s_0[0], s_0[1], action])
s_0 = s_1.copy()
rewards += rewardHere’s the trained agent going from start to goal around the trap:

Step 2: simulate a player who struggles
The player is simulated as someone with poor control: every move is a random direction. In a real game, the direction would come from the player moving a mouse.
On its own, this player is hopeless. Some episodes take 350 steps to stumble onto the goal.
Step 3: Assist As Needed
At every step, the player picks a direction. The assistant doesn’t just replace it with the best move. Instead, it scores all 8 moves on two things:
- Competence: how good the move is, using its Q-value.
- Autonomy: how close the move is to the direction the player picked. Agreeing with the player keeps the sense of control.
Autonomy is measured as the angle between each move and the player’s move, in steps of 45°. The same direction is 0, opposite is 4 (180°). Both scores are normalised to 0 to 1, then combined with two weights:
score = (competence weight × normalised Q) − (autonomy weight × normalised angle error)
The move with the highest score is the one that actually happens.
To normalise the Q-values, I used the cumulative histogram of all values in the Q-table. That maps each value to where it ranks among all the others, between 0 and 1.
# Assist As Needed ( Current GS, Action, weight1, weight2, Q-table, Normalised Q-table)
def AAN(s_0, au, z1, z2, q_table, cumulative):
Norm_Q = np.array([])
########Get Normalised QValues ########
Qs0 = q_table[s_0[0]][s_0[1]]
for qv_ in Qs0:
idx = base.tolist().index(round(qv_,1))
Norm_Q = np.append(Norm_Q,np.array([cumulative[idx]]))
#################Normalise Angle#######
ANu = au
ANrl = deque([0,1,2,3,4,-3,-2,-1])
ANrl.rotate(au)
ANu_ANrl = np.array(ANrl)
Norm_ang = map_(abs(ANu_ANrl), 0.0, 4.0, 0.0, 1.0)
########Weighted Q & Angle Error #######
WeightedNorm = (z1 * Norm_Q) - (z2 * Norm_ang)
Weighted_ComptVsSOA = np.argmax(WeightedNorm)
return int(Weighted_ComptVsSOA)Rotating the deque by the player’s action gives the angle difference from the player’s direction to each of the 8 moves.
Results
Each plot shows many episodes. The top panel is the random player alone and the bottom panel is the same player with AAN. The y-axis is the distance to the goal, so a line ends when the player reaches it.
Competence 1.0, Autonomy 0.75. The assistant leans towards the best move. Every episode reaches the goal within about 30 steps.

Competence 1.0, Autonomy 1.0. Equal weights. Episodes take up to about 60 steps.

Competence 0.75, Autonomy 1.0. The assistant leans towards what the player chose. Episodes take up to about 115 steps, and the player wanders more, but the moves are more often their own.

All three are far better than the unassisted player.
The trade-off
Competence and autonomy pull in opposite directions. More help gets the player to the goal faster, but more of the moves aren’t theirs, so the win feels less earned. More autonomy keeps the player in control, but the game takes longer and can get frustrating.
There’s no single right setting. The weights are something you’d tune for each person: more help early on, and less as their control improves.
Limitations
- It’s a simulation. The player is random input, not a real person.
- Agency is modelled, not measured. Angle error is a stand-in for the sense of agency, which in real use you’d measure by asking players.
- The grid is tiny. A 4×4 grid with 8 moves keeps the Q-table small. A real game would need function approximation instead of a table.