There are few ways to do so depending on how you want it
You could use the los to detect when the player is close enough in viewing range
or
you can give your ai a number variable call it dist then make an every tick and do set dist to distance(player.x,player.y,enemy.x,enemy.y) then just compare the distance
Or
Make a If hit boolean then compare player.x to enemy. X then simulation control you could use timers to let them know how long to runaway for
Me realizing I forgot to mention it's 8 direction movement with the enemies being solid so they can't run through the player. Like if it were a platformer this would be easy, it's just the fact that it's 8 directions so I can't just say an X value or they'll have times where they're just trying to push into the player when they're supposed to be running away.