diff options
| author | Mario Lang <mlang@delysid.org> | 2014-03-24 14:36:41 +0100 |
|---|---|---|
| committer | Mario Lang <mlang@delysid.org> | 2014-03-24 14:36:41 +0100 |
| commit | 5130570807b16e7fceccaefb2d6b34502e31c1bb (patch) | |
| tree | a8ff0033eb5d52816a81023c547626210e42178c /chess-pos.el | |
| parent | 5a2cd0a0a96e38fd440055c2672b8a8ed0cc2b92 (diff) | |
chess-pos-can-castle: Avoid error if there is no king on the board.
Diffstat (limited to 'chess-pos.el')
| -rw-r--r-- | chess-pos.el | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/chess-pos.el b/chess-pos.el index 4958720..0956fe5 100644 --- a/chess-pos.el +++ b/chess-pos.el @@ -304,18 +304,19 @@ lowercase to query if black can castle)." (value (aref position index))) (if (or (eq value nil) (integerp value)) value - (let* ((color (< side ?a)) - (long (= ?Q (upcase side))) - (file (if long 0 7)) - (king-file (chess-index-file - (chess-pos-king-index position color))) - rook) - (while (funcall (if long '< '>) file king-file) - (let ((index (chess-rf-to-index (if color 7 0) file))) - (if (chess-pos-piece-p position index (if color ?R ?r)) - (setq rook index file king-file) - (setq file (funcall (if long '1+ '1-) file))))) - (aset position index rook))))) + (when (chess-pos-king-index position (< side ?a)) + (let* ((color (< side ?a)) + (long (= ?Q (upcase side))) + (file (if long 0 7)) + (king-file (chess-index-file + (chess-pos-king-index position color))) + rook) + (while (funcall (if long '< '>) file king-file) + (let ((index (chess-rf-to-index (if color 7 0) file))) + (if (chess-pos-piece-p position index (if color ?R ?r)) + (setq rook index file king-file) + (setq file (funcall (if long '1+ '1-) file))))) + (aset position index rook)))))) (defsubst chess-pos-set-can-castle (position side value) "Set whether the king can castle on the given POSITION on SIDE. |
