r5103: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 12 Jun 2003 12:42:13 +0000 (12:42 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 12 Jun 2003 12:42:13 +0000 (12:42 +0000)
base.lisp
edge-table-storage.lisp
edge-table.lisp
io-clim.lisp
io.lisp
package.lisp
strategies.lisp
utils.lisp

index ac4fb55d8d91c256bb3f2844913317f58fe390cb..bbcd87209a1b349a8d46e9712d395c3f090b8156 100644 (file)
--- a/base.lisp
+++ b/base.lisp
@@ -8,7 +8,7 @@
 ;;;;  Programer:      Kevin Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: base.lisp,v 1.3 2003/05/06 15:51:20 kevin Exp $
+;;;; $Id: base.lisp,v 1.4 2003/06/12 12:42:13 kevin Exp $
 ;;;;
 ;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
@@ -20,9 +20,6 @@
 
 (in-package #:reversi)
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
-
 (defparameter +all-directions+ '(-11 -10 -9 -1 1 9 10 11))
 (defconstant +default-max-minutes+ 30)
 
   `(the piece (aref (the board ,board) (the square ,square))))
 
 (defparameter all-squares
-    (loop for i from 11 to 88 when (<= 1 (mod i 10) 8) collect i)
+    (loop for i fixum from 11 to 88 when (<= 1 (mod i 10) 8) collect i)
   "A list of all squares")
 
 (defun initial-board ()
 (defun count-difference (player board)
   "Count player's pieces minus opponent's pieces."
   (declare (type board board)
-          (fixnum player))
-  (- (count player board)
-     (count (opponent player) board)))
+          (fixnum player)
+          (optimize (speed 3) (safety 0) (space 0)))
+  (the fixnum (- (the fixnum (count player board))
+                (the fixum (count (opponent player) board)))))
 
 (defun valid-p (move)
-  (declare (type move move))
+  (declare (type move move)
+          (optimize (speed 3) (safety 0) (space 0)))
   "Valid moves are numbers in the range 11-88 that end in 1-8."
   (and (typep move 'move) (<= 11 move 88) (<= 1 (mod move 10) 8)))
 
   (declare (type board board)
           (type move move)
           (type player player)
-          (optimize (speed 3) (safety 0))
-)
+          (optimize (speed 3) (safety 0) (space 0)))
   (if (= (the piece (bref board move)) empty)
       (block search
        (dolist (dir +all-directions+)
   (declare (type board board)
           (type move move)
           (type player)
-          (optimize (speed 3) (safety 0))
-)
+          (optimize (speed 3) (safety 0) (space 0)))
   (setf (bref board move) player)
   (dolist (dir +all-directions+)
     (declare (type dir dir))
           (type move move)
           (type player player)
           (type dir dir)
-          (optimize (speed 3) (safety 0))
-)
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((bracketer (would-flip? move player board dir)))
     (when bracketer
       (loop for c from (+ move dir) by dir until (= c (the fixnum bracketer))
           (type move move)
           (type player player)
           (type dir dir)
-          (optimize (speed 3) (safety 0))
-)
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((c (+ move dir)))
     (declare (type square c))
     (and (= (the piece (bref board c)) (the player (opponent player)))
 (defun replace-board (to from)
   (replace to from))
 
-#+ignore
-(defun replace-board (to from)
-  (declare (type board to from)
-           (optimize (safety 0) (debug 0) (speed 3))
-)
-  (dotimes (i 100)
-    (declare (type 'fixnum i))
-    (setf (aref to i) (aref from i)))
-  to)
-
 #+allegro
 (defun replace-board (to from)
   (declare (type board to from))
   (apply #'vector (loop repeat 40 collect (initial-board))))
 
 
-
 (defvar *move-number* 1 "The number of the move to be played")
 (declaim (type fixnum *move-number*))
 
index d09f4166aeea8ee23859da69464b7b18693cb734..366aa90b84d19e75ed8dd4ca1131efc0df2dcb22 100644 (file)
@@ -7,16 +7,16 @@
 ;;;;  Programer:      Kevin Rosenberg
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: edge-table-storage.lisp,v 1.3 2002/10/25 12:39:15 kevin Exp $
+;;;; $Id: edge-table-storage.lisp,v 1.4 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2002 by Kevin M. Rosenberg
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;;***************************************************************************
 
-(in-package :reversi)
+(in-package #:reversi)
 
 (defparameter *et-path* nil)
 
index 653c0c12c118970e09d0a388b117e710dbad4416..9b2f94928403f06212845e2eea1f5f5c44f78f24 100644 (file)
@@ -7,9 +7,9 @@
 ;;;;  Programer:      Kevin M. Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: edge-table.lisp,v 1.3 2003/05/06 15:51:20 kevin Exp $
+;;;; $Id: edge-table.lisp,v 1.4 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
@@ -20,8 +20,6 @@
 
 (in-package #:reversi)
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (defparameter *edge-and-x-lists*
@@ -52,7 +50,8 @@
           (type player player)
           (type square index)
           (type (simple-array fixnum (100)) board)
-          (list squares))
+          (list squares)
+          (optimize (speed 3) (space 0) (safety 0)))
   (cond
     ((< (length squares) n) nil)
     ((null squares) (funcall fn board index))
@@ -92,7 +91,7 @@
   (declare (type board board)
           (type player player)
           (type cons squares)
-          (optimize (speed 3) (safety 1)))
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((index 0))
     (declare (fixnum index))
     (dolist (sq squares)
 
 (defun combine-edge-moves (possibilities player)
   "Combine the best moves."
+  (declare (optimize (speed 3) (safety 0) (space 0)))
   (let ((prob 1.0)
         (val 0.0)
         (fn (if (= player black) #'> #'<)))
   "What's the probability that player can move to this square?"
   (declare (type board board)
           (type player player)
-          (type square square))
+          (type square square)
+          (optimize (speed 3) (safety 0) (space 0)))
   (cond
     ((x-square-p square) .5) ;; X-squares
     ((legal-p square player board) 1.0) ;; immediate capture
 (defun static-edge-stability (player board)
   "Compute this edge's static stability"
   (declare (type board board)
-          (type player player))
+          (type player player)
+          (optimize (speed 3) (safety 0) (space 0)))
   (loop for sq in *top-edge*
       for i from 0
       sum (the fixnum 
     
     (defun piece-stability (board sq)
       (declare (type board board)
-              (fixnum sq))
-    (cond
-      ((corner-p sq) stable)
-      ((x-square-p sq)
-       (if (eql (bref board (corner-for sq)) empty)
-           unstable semi-stable))
-      (t (let* ((player (bref board sq))
-                (opp (opponent player))
-                (p1 (find player board :test-not #'eql
-                          :start sq :end 19))
-                (p2 (find player board :test-not #'eql
-                          :start 11 :end sq
-                          :from-end t)))
-          (declare (fixnum player opp))
-           (cond
-             ;; unstable pieces can be captured immediately
-             ;; by playing in the empty square
-             ((or (and (eql p1 empty) (eql p2 opp))
-                  (and (eql p2 empty) (eql p1 opp)))
-              unstable)
-             ;; Semi-stable pieces might be captured
-             ((and (eql p1 opp) (eql p2 opp)
-                   (find empty board :start 11 :end 19))
-              semi-stable)
-             ((and (eql p1 empty) (eql p2 empty))
-              semi-stable)
-             ;; Stable pieces can never be captured
-             (t stable))))))))
+              (fixnum sq)
+              (optimize (speed 3) (safety 0) (space 0)))
+      (cond
+       ((corner-p sq) stable)
+       ((x-square-p sq)
+        (if (eql (bref board (corner-for sq)) empty)
+            unstable semi-stable))
+       (t (let* ((player (bref board sq))
+                 (opp (opponent player))
+                 (p1 (find player board :test-not #'eql
+                           :start sq :end 19))
+                 (p2 (find player board :test-not #'eql
+                           :start 11 :end sq
+                           :from-end t)))
+            (declare (fixnum player opp))
+            (cond
+              ;; unstable pieces can be captured immediately
+              ;; by playing in the empty square
+              ((or (and (eql p1 empty) (eql p2 opp))
+                   (and (eql p2 empty) (eql p1 opp)))
+               unstable)
+              ;; Semi-stable pieces might be captured
+              ((and (eql p1 opp) (eql p2 opp)
+                    (find empty board :start 11 :end 19))
+               semi-stable)
+              ((and (eql p1 empty) (eql p2 empty))
+               semi-stable)
+              ;; Stable pieces can never be captured
+              (t stable))))))))
 
 
 (defun init-edge-table ()
   "Initialize *edge-table*, starting from the empty board."
   ;; Initialize the static values
+  (declare (optimize (speed 3) (safety 0) (space 0)))
   (loop for n-pieces from 0 to 10 do 
         (map-edge-n-pieces
         #'(lambda (board index)
   (dotimes (i 5) 
     (declare (fixnum i))
     ;; Do the indexes with most pieces first
-    (loop for n-pieces from 9 downto 1 do 
+    (loop for n-pieces fixnum from 9 downto 1 do 
           (map-edge-n-pieces
             #'(lambda (board index)
-            (declare (type board board)
-                     (fixnum index))
+               (declare (type board board)
+                        (fixnum index))
                 (setf (aref *edge-table* index)
                       (the fixnum (possible-edge-moves-value black board index))))
             black (initial-board) n-pieces *top-edge* 0))))
index 7516869528412c8732f8576c8d4ea1d7b1dd6f04..12ea49b5f11370bf8004f960a24122de472cdc3f 100644 (file)
@@ -8,9 +8,9 @@
 ;;;;  Programer:      Kevin M. Rosenberg
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: io-clim.lisp,v 1.12 2003/05/06 15:53:47 kevin Exp $
+;;;; $Id: io-clim.lisp,v 1.13 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
diff --git a/io.lisp b/io.lisp
index 26872eca12a75a20d0cf33123892d2481c24ee55..1d3d2c81781eccb6169b1b3d61467e83b981637d 100644 (file)
--- a/io.lisp
+++ b/io.lisp
@@ -8,9 +8,9 @@
 ;;;;  Programer:      Kevin Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: io.lisp,v 1.3 2003/05/06 15:51:20 kevin Exp $
+;;;; $Id: io.lisp,v 1.4 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
@@ -20,9 +20,6 @@
 
 (in-package #:reversi)
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
-
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
 (let ((square-names 
index ee2cd6ac549375afabed076246d27344fd4c42be..5abbd7c1549695f6d38c01b0ecb6177cfa108ec4 100644 (file)
@@ -7,9 +7,9 @@
 ;;;;  Programer:      Kevin M. Rosenberg
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: package.lisp,v 1.5 2003/05/06 16:17:53 kevin Exp $
+;;;; $Id: package.lisp,v 1.6 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
index e7d2fe681063a35c0c402e28b0a035c7cb99a2dc..c2cade730dbc034d99bba3498b72fec6842ff592 100644 (file)
@@ -8,9 +8,9 @@
 ;;;;  Programer:      Kevin Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: strategies.lisp,v 1.5 2003/05/06 15:51:20 kevin Exp $
+;;;; $Id: strategies.lisp,v 1.6 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
@@ -20,9 +20,6 @@
 
 (in-package #:reversi)
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
-
 (defun random-strategy (player board)
   "Make any legal move."
   (declare (type player player)
   searching PLY levels deep and backing up values."
   (declare (type player player)
           (type board board)
-          (fixnum ply))
+          (fixnum ply)
+          (optimize (speed 3) (space 0) (safety 0)))
   (if (= ply 0)
       (funcall eval-fn player board)
       (let ((moves (legal-moves player board)))
   using cutoffs whenever possible."
   (declare (type player player)
           (type board board)
-          (fixnum achievable cutoff ply))
+          (fixnum achievable cutoff ply)
+          (optimize (speed 3) (safety 0) (space 0)))
   (if (= ply 0)
       (funcall eval-fn player board)
       (let ((moves (legal-moves player board)))
   "Like WEIGHTED-SQUARES, but don't take off for moving
   near an occupied corner."
   (declare (type player player)
-          (type board board))
+          (type board board)
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((w (weighted-squares player board)))
     (declare (fixnum w))
     (dolist (corner '(11 18 81 88))
 (defun alpha-beta2 (player node achievable cutoff ply eval-fn)
   "A-B search, sorting moves by eval-fn"
   ;; Returns two values: achievable-value and move-to-make
+  (declare (fixnum ply)
+          (optimize (speed 3) (space 0) (safety 0)))
   (if (= ply 0)
       (values (node-value node) node)
       (let* ((board (node-board node))
 
 (defun negate-value (node)
   "Set the value of a node to its negative."
+  (declare (fixnum node)
+          (speed 3) (safety 0) (space 0))
   (setf (node-value node) (- (node-value node)))
   node)
 
                     killer)
   (declare (type board board)
           (type player player)
-          (type fixnum achievable cutoff ply))
+          (type fixnum achievable cutoff ply)
+          (optimize (speed 3) (space 0) (safety 0)))
   "A-B search, putting killer move first."
   (if (= ply 0)
       (funcall eval-fn player board)
   (declare (type board board)
           (type player player)
           (type fixnum achievable cutoff ply)
-          (type move killer))
+          (type move killer)
+          (optimize (speed 3) (safety 0) (space 0)))
   "A-B search, putting killer move first."
   (if (= ply 0)
       (funcall eval-fn player board)
   Returns current and potential mobility for player."
   (declare (type board board)
           (type player player)
-          (optimize (speed 3) (safety 0 )))
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((opp (opponent player))
         (current 0)    ; player's current mobility
         (potential 0))                 ; player's potential mobility
   (declare (type board board)
           (type player opp)
           (type cons neighbors)
-          (optimize (speed 3) (safety 0)))
+          (optimize (speed 3) (safety 0) (space 0)))
   (block search
     (dolist (sq neighbors)
       (declare (type square sq))
 (defun edge-stability (player board)
   "Total edge evaluation for player to move on board."
   (declare (type board board)
-          (type player player))
+          (type player player)
+          (optimize (speed 3) (safety 0) (space 0))
   (loop for edge-list in *edge-and-x-lists*
         sum (aref *edge-table*
                   (edge-index player board edge-list))))
   ;; The three factors are multiplied by coefficients
   ;; that vary by move number:
   (declare (type board board)
-          (type player player))
+          (type player player)
+          (optimize (speed 3) (safety 0) (space 0)))
   (let ((c-edg  (+ 312000 (* 6240 *move-number*)))
         (c-cur (if (< *move-number* 25)
                   (+ 50000 (* 2000 *move-number*))
index 247722415a707252417378d1fefa378d61431a4e..8a3ac40577d047ad9180359642a13ebdab05ab51 100644 (file)
@@ -7,9 +7,9 @@
 ;;;;  Programer:      Kevin M. Rosenberg
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: utils.lisp,v 1.4 2003/05/06 15:51:20 kevin Exp $
+;;;; $Id: utils.lisp,v 1.5 2003/06/12 12:42:13 kevin Exp $
 ;;;;
-;;;; This file is Copyright (c) 2001-2002 by Kevin M. Rosenberg 
+;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;;
 ;;;; Reversi users are granted the rights to distribute and use this software
 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
@@ -18,8 +18,6 @@
 
 (in-package #:reversi)
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (safety 1) (space 0) (speed 3) (compilation-speed 0))))
 
 (defmacro missing-argument ()
   `(error "Missing an argument to a constructor"))