First of all, please don't use such an enormous title; it kind of breaks the website…
So what it looks like you're trying to do is:
- generate a random number D
- D determines the direction to draw the next section of wall
- if there is no wall two spaces away in that direction, then draw the section of wall one space away
In theory this will work to generate a labyrinthine structure, but bear in mind you will have to post-process it to add in some walls, otherwise it will probably be a very easy maze (nothing wrong with easy, I'm just letting you know).
Anyway, it looks like you're missing some parentheses in your 'if' conditions. For example:
if D=4 not(PxlTest(Y+1,Xnot(PxlTest(Y+2,X
is not the same as:
if D=4 not(PxlTest(Y+1,X))not(PxlTest(Y+2,X
The latter is more likely what you meant, but I can see where the confusion came from.
You should only omit closing parentheses (or closing quotations) at the end of a line or before a '→'. Notice I added in the parentheses in the first 'not()', closing the function call before calling the second one. Before this change, the output of the second 'not()' was being multiplied by the X in the first 'not()', so a lot of the time you'd be checking the wrong X-value in the first 'not()'.
Try to make those changes and see if your code works better
(I haven't tested it but it seems to make sense from a high-level POV).