# Learning Agents: For turn based games

**URL:** <https://forums.unrealengine.com/t/learning-agents-for-turn-based-games/2215882>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Learning-Agents, question\
**Created:** [December 13, 2024, 12:00am UTC](https://forums.unrealengine.com/t/learning-agents-for-turn-based-games/2215882 "2024-12-13T00:00:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrWetsnow](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrWetsnow](https://forums.unrealengine.com/u/MrWetsnow)\
**Post date:** [December 13, 2024, 12:00am UTC](https://forums.unrealengine.com/t/learning-agents-for-turn-based-games/2215882/1 "2024-12-13T00:00:56Z")

</div>

Hi,

I am training an agent on a turn based game. One side of the game makes (for now) random moves, the other side is a learning agent.

I am unclear on how to handle invalid moves. (Think tic-tac-toe like game). I am using `Get Exclusive Discrete Action` to get the possible x,y coordinates to move to, but a bunch of them are not valid.

Ideally I could mask out the invalid moves, is this supported?

If not, how should I handle this in the `PerformAgentAction` function? Is there a way to end that episode early? I see an `End Training` function, but not an `End Episode` one.

Or is there some other way to handle this? Right now my training gets stuck because the agent hasn’t made a valid move. I am able to see if the move is valid or not from inside the Action function. I suppose I could have it sample until it picks a valid one, but that seems wrong. I would have to give it a negative reward first somehow, and it’s not clear to me how to do that in the context of the `Action` function.

Thank you for your help  
Dan
