#assert new_direction in possible_directions, "Error, action leads to impossible direction"
assertnew_position==get_new_position(agent.position,new_direction),"Error, something is wrong with new position"
opposed_agent_id=env.agent_positions[new_position]# TODO: check that agent_positions now works correctly in flatland V3 (i.e. gets correctly updated...)
# agent_positions[cell] is an agent_id if an agent is there, otherwise -1.
ifopposed_agent_id!=-1:
opposed_agent=env.agents[opposed_agent_id]
# other agent with opposing direction is in the way --> deadlock
# an opposing direction means having a different direction than our agent would have if he moved to the new cell. (180 degrees or 90 degrees to our agent)
ifopposed_agent.direction!=new_direction:
ifagentnotinnewly_deadlocked_agents:# to avoid duplicates
newly_deadlocked_agents.append(agent)
ifopposed_agentnotinnewly_deadlocked_agents:# to avoid duplicates