From 8f0f2044b5445722aff29a0c58461a794564f13a Mon Sep 17 00:00:00 2001 From: Mario Lang Date: Tue, 20 May 2014 03:25:59 +0200 Subject: [PATCH] Eliminate the circular dependency between chess-pos and chess-fen. 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. --- chess-crafty.el | 3 ++- chess-fen.el | 5 +++-- chess-file.el | 2 ++ chess-gnuchess.el | 3 ++- chess-network.el | 29 ++++++++++++++++++++++++----- chess-pos.el | 14 -------------- chess-sjeng.el | 5 +++-- 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/chess-crafty.el b/chess-crafty.el index ddd0cf1a..11245b6c 100644 --- a/chess-crafty.el +++ b/chess-crafty.el @@ -22,6 +22,7 @@ ;;; Code: (require 'chess-common) +(require 'chess-fen) (require 'chess-var) (defgroup chess-crafty nil @@ -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) diff --git a/chess-fen.el b/chess-fen.el index 568e461d..001c2c4f 100644 --- a/chess-fen.el +++ b/chess-fen.el @@ -57,6 +57,7 @@ ;;; Code: +(require 'chess-pos) (eval-when-compile (require 'cl-lib)) (defconst chess-fen-regexp @@ -64,7 +65,7 @@ (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)) @@ -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) diff --git a/chess-file.el b/chess-file.el index 84e6c1f4..1b3028b9 100644 --- a/chess-file.el +++ b/chess-file.el @@ -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) diff --git a/chess-gnuchess.el b/chess-gnuchess.el index 227ee845..81d71524 100644 --- a/chess-gnuchess.el +++ b/chess-gnuchess.el @@ -22,6 +22,7 @@ ;;; Code: (require 'chess-common) +(require 'chess-fen) (defgroup chess-gnuchess nil "The publically available chess engine 'gnuchess'." @@ -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) diff --git a/chess-network.el b/chess-network.el index efc9d280..6de3978c 100644 --- a/chess-network.el +++ b/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 +;; Maintainer: Mario Lang +;; 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 . + +;;; Code: (require 'chess-common) +(require 'chess-fen) (defvar chess-network-regexp-alist (list @@ -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" diff --git a/chess-pos.el b/chess-pos.el index b6b1bdea..c2050698 100644 --- a/chess-pos.el +++ b/chess-pos.el @@ -84,7 +84,6 @@ ;;; Code: (require 'chess-message) -(require 'chess-fen) (eval-when-compile (require 'cl-lib) (cl-proclaim '(optimize (speed 3) (safety 2)))) @@ -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) diff --git a/chess-sjeng.el b/chess-sjeng.el index 7dcabf74..88fec05c 100644 --- a/chess-sjeng.el +++ b/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. @@ -21,6 +21,7 @@ ;;; Code: (require 'chess-common) +(require 'chess-fen) (defgroup chess-sjeng nil "The publically available chess engine 'sjeng'." @@ -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))