Skip to content

Commit

Permalink
Eliminate the circular dependency between chess-pos and chess-fen.
Browse files Browse the repository at this point in the history
We remove functions chess-pos-to-string and chess-pos-from-string which
are really just aliases for chess-fen-to-pos and chess-pos-to-fen.
  • Loading branch information
mlang committed May 20, 2014
1 parent 940fce2 commit 8f0f204
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
3 changes: 2 additions & 1 deletion chess-crafty.el
Expand Up @@ -22,6 +22,7 @@
;;; Code:

(require 'chess-common)
(require 'chess-fen)
(require 'chess-var)

(defgroup chess-crafty nil
Expand Down Expand Up @@ -131,7 +132,7 @@

((eq event 'setup-pos)
(chess-engine-send nil (format "setboard %s\n"
(chess-pos-to-string (car args)))))
(chess-pos-to-fen (car args)))))

((eq event 'evaluate)
(setq chess-crafty-evaluation nil)
Expand Down
5 changes: 3 additions & 2 deletions chess-fen.el
Expand Up @@ -57,14 +57,15 @@

;;; Code:

(require 'chess-pos)
(eval-when-compile (require 'cl-lib))

(defconst chess-fen-regexp
"^\\([bnrqkpBNRQKP1-8]*/?\\)+ [bw] \\(-\\|[KQkq]+\\) \\(-\\|[1-8]\\)")

(defun chess-fen-to-pos (fen)
"Convert a FEN-like notation string to a chess position."
(assert (stringp fen))
(cl-assert (stringp fen))
(let ((i 0) (l (length fen))
(rank 0) (file 0) (c ?0)
(position (chess-pos-create t))
Expand Down Expand Up @@ -117,7 +118,7 @@
(defun chess-pos-to-fen (position &optional full)
"Convert a chess POSITION to FEN-like notation.
If FULL is non-nil, represent trailing spaces as well."
(assert (vectorp position))
(cl-assert (vectorp position))
(let ((blank 0) (str "") output)
(dotimes (rank 8)
(dotimes (file 8)
Expand Down
2 changes: 2 additions & 0 deletions chess-file.el
Expand Up @@ -27,6 +27,8 @@

;;; Code:

(require 'chess-fen)

(defvar chess-file-locations nil
"A list of starting positions of individual records of this collection.")
(make-variable-buffer-local 'chess-file-locations)
Expand Down
3 changes: 2 additions & 1 deletion chess-gnuchess.el
Expand Up @@ -22,6 +22,7 @@
;;; Code:

(require 'chess-common)
(require 'chess-fen)

(defgroup chess-gnuchess nil
"The publically available chess engine 'gnuchess'."
Expand Down Expand Up @@ -69,7 +70,7 @@

((eq event 'setup-pos)
(let ((file (chess-with-temp-file
(insert (chess-pos-to-string (car args)) ?\n))))
(insert (chess-pos-to-fen (car args)) ?\n))))
(chess-engine-send nil (format "epdload %s\n" file))))

((eq event 'setup-game)
Expand Down
29 changes: 24 additions & 5 deletions chess-network.el
@@ -1,9 +1,28 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Play against an opponent over the network
;;
;;; chess-network.el --- Play against an opponent over the network

;; Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc.

;; Author: John Wiegley <johnw@gnu.org>
;; Maintainer: Mario Lang <mlang@delysid.org>
;; Keywords: games

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'chess-common)
(require 'chess-fen)

(defvar chess-network-regexp-alist
(list
Expand Down Expand Up @@ -140,7 +159,7 @@

((eq event 'setup-pos)
(chess-engine-send nil (format "fen %s\n"
(chess-pos-to-string (car args)))))
(chess-pos-to-fen (car args)))))

((eq event 'setup-game)
(chess-engine-send nil (format "pgn %s\n"
Expand Down
14 changes: 0 additions & 14 deletions chess-pos.el
Expand Up @@ -84,7 +84,6 @@
;;; Code:

(require 'chess-message)
(require 'chess-fen)
(eval-when-compile
(require 'cl-lib)
(cl-proclaim '(optimize (speed 3) (safety 2))))
Expand Down Expand Up @@ -679,19 +678,6 @@ The current side-to-move is always white."
[nil nil nil nil nil nil t nil nil nil nil])
(chess-pos-copy chess-starting-position)))

(defsubst chess-pos-to-string (position &optional full)
"Convert the given POSITION into a string.
The returned string can be converted back to a position using
`chess-pos-from-string'."
(cl-assert (vectorp position))
(chess-pos-to-fen position full))

(defsubst chess-pos-from-string (string)
"Convert the given STRING to a chess position.
This string should have been created by `chess-pos-to-string'."
(cl-assert (stringp string))
(chess-fen-to-pos string))

(defconst chess-pos-piece-values
'((?p . 1)
(?n . 3)
Expand Down
5 changes: 3 additions & 2 deletions chess-sjeng.el
@@ -1,4 +1,4 @@
;;; chess-sjeng.el --- Play chess against sjeng!
;;; chess-sjeng.el --- Play against sjeng!

;; Copyright (C) 2004 Free Software Foundation, Inc.

Expand All @@ -21,6 +21,7 @@
;;; Code:

(require 'chess-common)
(require 'chess-fen)

(defgroup chess-sjeng nil
"The publically available chess engine 'sjeng'."
Expand Down Expand Up @@ -73,7 +74,7 @@

((eq event 'setup-pos)
(chess-engine-send nil (format "setboard %s\n"
(chess-pos-to-string (car args)))))
(chess-pos-to-fen (car args)))))

((eq event 'move)
(when (= 1 (chess-game-index game))
Expand Down

0 comments on commit 8f0f204

Please sign in to comment.