include chess2; def V voidleap #0 #1 1 1 or voidride #0 #1 1 0; def v voidleap #0 #1 1 1 or voidride #0 #1 1 0; def P cond cond empty #0 capture (islower #1) (checkleap #0 #1 1 1) (checkleap #0 #1 0 1) and > rank #1 rank #0; def p cond cond empty #0 capture (isupper #1) (checkleap #0 #1 1 1) (checkleap #0 #1 0 1) and < rank #1 rank #0; // Checks whether a player has a legal move. // To check for checkmate, check for check + stalemate with separate subroutines. // Modified to accomodate moves into void. En passant code removed. sub stalemated kingpos: store; local from piece to; if isupper space #kingpos: def friends onlyupper; def nofriends noupper; def friend isupper #0; else: def friends onlylower; def nofriends nolower; def friend islower #0; endif; // While the royal piece is called the King in these comments, // it may be any piece. These variables determine what the royal piece is. set royal space var kingpos; // Can the king move? // The King is done separately for two reasons. // (1) Efficiency: The King is always on the board and can usually move. // (2) Accuracy: For a King's potential move, the King's new location must be checked for check. // But for other pieces, the King's actual position must be checked for check. store; for to fn join #royal L #kingpos: if fn #royal #kingpos #to and not fn friend space #to and onboard #to: move #kingpos #to; set incheck sub checked #to; restore; verify #incheck; endif; next; for to leaps #kingpos 1 0: if == void space #to: move #kingpos #to; delete #kingpos; set incheck sub checked #to; restore; verify #incheck; endif; next; // Can another piece legally move? restore; for (from piece) fn friends: if == #from #kingpos: continue; endif; for to fn join #piece L #from: if fn #piece #from #to and not fn friend space #to and onboard #to: move #from #to; set incheck sub checked #kingpos; restore; verify #incheck; elseif fn V #from #to and == void space #to and == toupper #piece V: move #from #to; delete #from; set incheck sub checked #kingpos; restore; verify #incheck; endif; next; for to leaps #from 1 0: if == void space #to: move #from #to; delete #from; set incheck sub checked #kingpos; restore; verify #incheck; endif; next; next; // At this point, all tests are positive: It is stalemate. return true; endsub;