Thank you for the fixes and explanations. But you have overlooked that in
sub 'enpassant' there is twice 'filename' used.
It should be 'filename #to rankname #from'.
To check if any piece or any empty square is attacked, one could use the
following subroutine:
// This subroutine checks whether 'square' is attacked by the given
side:
sub attacked square bywhite:
local from piece pawn pdir;
if #bywhite:
def enemies onlyupper;
set pawn P;
set pdir 1;
else:
def enemies onlylower;
set pawn p;
set pdir -1;
endif;
for (from piece) fn enemies:
if == #piece #pawn:
if checkaleap #from #square 1 #pdir or
checkaleap #from #square -1 #pdir:
return #from;
endif;
elseif fn #piece #from #square:
return #from;
endif;
next;
return false;
endsub;