OK... as they say, a picture says more than thousand words, so I just sketched up a diagram of the possibilities which may occur...
The first up arrow gives the direction the enemy comes from, black arrows give the following direction if it's not dependent from the player position.
In the right 3 pictures, the colored dots give possible player positions which give the new directions pointed to by the arrows in the same colors.
An asterisk says that the mirror of this case may occur and has to be accounted for as well.
To explain this, there are six possible patterns an enemy may encounter on an intersection...
1. Continuation... in tnis case, continue direction
2. Dead end... in this case, reverse direction
3. L piece... in this case, continue along the L (this may have to be mirrored to a left or right L)
4. T piece with possibility to continue along the same direction... here the direction depends on the player position, and this pattern has to be mirrored as well.
5. T piece leading left or right... here, again, the player position decides which way gets taken
6. Intersection with all ways open... here, again, the player position decides which way to go
All of those possibilities can occur relative to any of the 4 directions the enemy may come from.
In the pseudo code you've given, I think the "L" is not properly accounted for in all cases.
Let's take, for example, my 3rd drawing, and let's assume that the player is to the upper right of the enemy... in this case, your pseudocode does the following:
Current Direction LR? CUD (No, it's up)
Current Direction UP? CLR (-> CLR)
Compare with player X (which actually should be irrelevant here because there's only one way to continue)
If Left, switch to left if possible, exit (no, player is right)
If Right, switch to right if possible, exit (not possible)
Check current direction, if can't move, use opposite direction. (this would take the opposite direction, not along the L)
Sorry for critizising you...
Edited by Kurt_Woloch, Sun Jan 13, 2019 11:24 AM.