r10498: fix number type
[reversi.git] / strategies.lisp
index c2cade730dbc034d99bba3498b72fec6842ff592..48140bbe424019c7ac8ec2bdc094dfa42edb256f 100644 (file)
@@ -8,7 +8,7 @@
 ;;;;  Programer:      Kevin Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
 ;;;;  Programer:      Kevin Rosenberg based on code by Peter Norvig
 ;;;;  Date Started:   1 Nov 2001
 ;;;;
-;;;; $Id: strategies.lisp,v 1.6 2003/06/12 12:42:13 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
 ;;;;
 ;;;; This file is Copyright (c) 2001-2003 by Kevin M. Rosenberg 
 ;;;; and Copyright (c) 1998-2002 Peter Norvig
@@ -24,8 +24,7 @@
   "Make any legal move."
   (declare (type player player)
           (type board board))
   "Make any legal move."
   (declare (type player player)
           (type board board))
-  (random-elt (legal-moves player board)))
-
+  (random-nth (legal-moves player board)))
 
 (defun maximize-difference (player board)
   "A strategy that maximizes the difference in pieces."
 
 (defun maximize-difference (player board)
   "A strategy that maximizes the difference in pieces."
 
 (defun negate-value (node)
   "Set the value of a node to its negative."
 
 (defun negate-value (node)
   "Set the value of a node to its negative."
-  (declare (fixnum node)
-          (speed 3) (safety 0) (space 0))
+  (declare (optimize (speed 3) (safety 0) (space 0)))
   (setf (node-value node) (- (node-value node)))
   node)
 
   (setf (node-value node) (- (node-value node)))
   node)
 
   (declare (type board board)
           (type player player)
           (type fixnum achievable cutoff ply)
   (declare (type board board)
           (type player player)
           (type fixnum achievable cutoff ply)
-          (type move killer)
+          (type (or null move) killer)
           (optimize (speed 3) (safety 0) (space 0)))
   "A-B search, putting killer move first."
   (if (= ply 0)
           (optimize (speed 3) (safety 0) (space 0)))
   "A-B search, putting killer move first."
   (if (= ply 0)
 (defun alpha-beta-searcher3w (depth eval-fn)
   "Return a strategy that does A-B search with killer moves."
   #'(lambda (player board)
 (defun alpha-beta-searcher3w (depth eval-fn)
   "Return a strategy that does A-B search with killer moves."
   #'(lambda (player board)
-      (multiple-value-bind (value move)
-          (alpha-beta3w player board losing-value winning-value
-                       depth eval-fn nil)
-        (declare (ignore value))
-        move)))
+      (nth-value 1
+                (alpha-beta3w player board losing-value winning-value
+                              depth eval-fn nil))))
 
 (defun put-first (killer moves)
   "Move the killer move to the front of moves,
 
 (defun put-first (killer moves)
   "Move the killer move to the front of moves,
   "Total edge evaluation for player to move on board."
   (declare (type board board)
           (type player player)
   "Total edge evaluation for player to move on board."
   (declare (type board board)
           (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))))
+          (optimize (speed 3) (safety 0) (space 0)))
+  (loop for edge-list of-type (simple-array fixnum (*)) in *edge-and-x-lists*
+      sum (aref *edge-table* (edge-index player board edge-list))))
 
 (defun iago-eval (player board)
   "Combine edge-stability, current mobility and
 
 (defun iago-eval (player board)
   "Combine edge-stability, current mobility and
 
 (defun iago (depth)
   "Use an approximation of Iago's evaluation function."
 
 (defun iago (depth)
   "Use an approximation of Iago's evaluation function."
+  (declare (fixnum depth))
   (alpha-beta-searcher3 depth #'iago-eval))
 
 ;; Maximizer (1-ply)
   (alpha-beta-searcher3 depth #'iago-eval))
 
 ;; Maximizer (1-ply)
 
 
 (defun ab3w-df (ply)
 
 
 (defun ab3w-df (ply)
+  (declare (fixnum ply))
   (alpha-beta-searcher3w ply #'count-difference))
 
 (defun ab3w-wt (ply)
   (alpha-beta-searcher3w ply #'count-difference))
 
 (defun ab3w-wt (ply)
+  (declare (fixnum ply))
   (alpha-beta-searcher3w ply #'weighted-squares))
 
 (defun ab3w-md-wt (ply)
   (alpha-beta-searcher3w ply #'weighted-squares))
 
 (defun ab3w-md-wt (ply)
+  (declare (fixnum ply))
   (alpha-beta-searcher3w ply #'modified-weighted-squares))
 
 
   (alpha-beta-searcher3w ply #'modified-weighted-squares))