If the enemy is to the right of the player, then it's closer to player.x + 50, to the left it's closer to player.X - 50, so the following -- which uses a conditional expression -- gets you the desired X coordinate:
enemy.X < player.X ? (player.X - 50) : (player.X + 50)[/code:3ly2dk1z]