Check out Glinski's Hexagonal Chess, our featured variant for May, 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 Thu, Dec 9, 2004 01:45 AM UTC:
After creating user defined functions, I discovered that my Polish Notation
calculator wouldn't let recursive functions work. So I came up with some
replacements for cond, called unless and onlyif. These work sort of like
cond but with only two arguments instead of three. The expression 'cond x
y z' is supposed to be equivalent to 'x ? y : z' but it evaluates both y
and z, making it unsuitable for recursion. It ends up creating an infinite
loop when used for recursion. Unlike previous functions in the PNC, unless
and onlyif can break out of it, allowing recursion loops to be exited. I
won't describe them in detail here, because I already did in the
documentation.

After creating these new functions, I realized the same principle could be
applied to logical operators. So I updated and, or, nand, and nor to use
either one or two arguments. When only one argument is available, these
operators will stop evaluation of the expression when the truth value of
the whole expression can be known from one value. For example, I can now
write code like this:

def Q checkride origin dest 1 1 or checkride origin dest 1 0;

This function would evaluate the Rook moves before the Bishop moves, and
if the Queen moved like a Rook, it would return true without bothering to
check whether it moved like a Bishop.

So, finally, logical operators can be used for flow control in
expressions. They can also be used for exiting from recursive functions.