Check out Grant Acedrex, our featured variant for April, 2024.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

Game Courier Developer's Guide. Learn how to design and program Chess variants for Game Courier.[All Comments] [Add Comment or Rating]
🕸📝Fergus Duniho wrote on Wed, Mar 1, 2023 05:16 PM UTC in reply to Daniel Zacharias from 06:49 AM:

Your function is recursive, but you're not using unless or onlyif, which were designed specifically for use in recursive functions. Although you seem to have gotten it to work anyway, I would recommend looking into how you could rewrite your function using one of them.

I replaced your TEST function with this:

def TEST aggregate lambda (fn nextstep #frm where #frm #0) (nw n w e s se) =frm;

Except for not including empty results, it gave the same output as this:

set c1 fn nextstep d4 where d4 nw;
set c2 fn nextstep d4 where d4 n;
set c3 fn nextstep d4 where d4 w;
set c4 fn nextstep d4 where d4 e;
set c5 fn nextstep d4 where d4 s;
set c6 fn nextstep d4 where d4 se;

set ra array #c1 #c2 #c3 #c4 #c5 #c6;
print #ra;

The problem with your code was that fn is a greedy function, meaning that it interprets everything following it as an argument to the function. Although you specified only two arguments for your function, it does not take this into account. So, it does not just pop off two values and leave the remaining values untouched.

To get around this, I used aggregate with a lambda function, and I used a named variable for the main input to your TEST function so that it could be used within the lambda function without being confused for input to the lambda function. Check the documentation on these details to learn more.