sub GetSquares toshuffle:
my sqr piece;
// determine the squares the pieces in the given set are on.
// the result is left in 3 global arrays:
set left array; // on left board half
set light array; // as well as sorted by shade
set dark array;
printr $space;
for (sqr, piece) $space:
print . iter . #piece #sqr;
if match var piece #toshuffle:
if < * 2 file #sqr lastfile: // left half
push left #sqr;
endif;
if == color #sqr 1: // distinguish by shade
push dark #sqr;
else:
push light #sqr;
endif;
endif;
next;
print "got it";
endsub;
The actual fix was changing #piece to var piece in the conditional if match var piece #toshuffle:. There are subtle differences between these two ways of getting the values of variables. The way you were doing it embedded it into the line during pre-processing, and the problem with doing that was that its first value was -, which is also an operator. Changing it to var piece made sure that it treated the value as a string at the proper time and not as the minus operator.
I changed another line to use the color operator, because this might be a better way of doing what you want. This returns the color index associated with the space. Looking at the color values, I figured that the number 1 was being used for the dark squares.
Here is the fixed subroutine:
The actual fix was changing #piece to var piece in the conditional if match var piece #toshuffle:. There are subtle differences between these two ways of getting the values of variables. The way you were doing it embedded it into the line during pre-processing, and the problem with doing that was that its first value was -, which is also an operator. Changing it to var piece made sure that it treated the value as a string at the proper time and not as the minus operator.
I changed another line to use the color operator, because this might be a better way of doing what you want. This returns the color index associated with the space. Looking at the color values, I figured that the number 1 was being used for the dark squares.