Generate random chess position: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed REXX program to allow generation of an unbalanced total number of pieces (by color).) |
(→{{header|zkl}}: doh) |
||
Line 224: | Line 224: | ||
# We try to find suitable king positions on non-adjacent squares. |
# We try to find suitable king positions on non-adjacent squares. |
||
# If we could not find any, we return recursively |
# If we could not find any, we return recursively |
||
kings := Utils.Helpers.cprod2(n,n). |
kings := Utils.Helpers.cprod2(n,n).filter1(fcn([(a,b)]){ // cross product |
||
a!=b and (a/8 - b/8).abs() or (a%8 - b%8).abs()>1 |
a!=b and (a/8 - b/8).abs() or (a%8 - b%8).abs()>1 |
||
}) |
}); # (a,b) on success, False on fail |
||
if(not kings) return(pickFEN()); |
if(not kings) return(pickFEN()); // tail recursion |
||
# We make a list of pieces we can pick (apart from the kings) |
# We make a list of pieces we can pick (apart from the kings) |