diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-12 07:58:22 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-12 07:58:22 +0000 |
| commit | e66b028def9af45cc545c973255df42c9b90cde1 (patch) | |
| tree | b4d7bf33b4aabfee075ff211e3da12456fbeaf70 /chess-fen.el | |
| parent | cdba8a5aed3bd66e62f348a7064acece342bb68e (diff) | |
optimizations and bug fixes
Diffstat (limited to 'chess-fen.el')
| -rw-r--r-- | chess-fen.el | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/chess-fen.el b/chess-fen.el index 8dca4f6..b104f06 100644 --- a/chess-fen.el +++ b/chess-fen.el @@ -46,21 +46,24 @@ (let ((i 0) (l (length fen)) (rank 0) (file 0) (c ?0) (position (chess-pos-create t)) - number) - (while (and (/= c ? ) (< i l)) + error number) + (while (and (null error) (/= c ? ) (< i l)) (setq c (aref fen i)) (cond ((= c ?/) (setq file 0 rank (1+ rank))) ((and (>= c ?1) (<= c ?9)) (setq file (+ file (- c ?0)))) - ((/= c ? ) + ((memq (upcase c) '(?K ?Q ?B ?N ?R ?P)) (chess-pos-set-piece position (chess-rf-to-index rank file) c) - (setq file (1+ file)))) + (setq file (1+ file))) + (t (setq error t))) (setq i (1+ i))) - (chess-pos-set-side-to-move position (= (aref fen i) ?w)) + (if (memq (aref fen i) '(?b ?w)) + (chess-pos-set-side-to-move position (= (aref fen i) ?w)) + (setq error t)) (setq i (+ i 2) number nil) - (while (< i l) + (while (and (null error) (< i l)) (setq c (aref fen i)) (cond ((= c ?K) (chess-pos-set-can-castle position ?K t)) @@ -70,9 +73,11 @@ ((and (>= c ?a) (<= c ?h)) (chess-pos-set-en-passant position (chess-coord-to-index (substring fen i (+ i 2)))) - (setq i (1+ i)))) + (setq i (1+ i))) + (t (setq error t))) (setq i (1+ i))) - position)) + (unless error + position))) (defun chess-pos-to-fen (position &optional full) "Convert a chess POSITION to FEN-like notation. |
