X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=edge-table.lisp;h=9b2f94928403f06212845e2eea1f5f5c44f78f24;hb=20c849f483c381f84eae22eee807280c8d00e554;hp=30a8ccc659c0627843e7f31a0a3a76496db9f05b;hpb=1758cfb593196dd65c70199aa1ebd90cbd6e7ee5;p=reversi.git diff --git a/edge-table.lisp b/edge-table.lisp index 30a8ccc..9b2f949 100644 --- a/edge-table.lisp +++ b/edge-table.lisp @@ -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.2 2002/10/25 09:23:39 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 @@ -18,8 +18,8 @@ ;;;;*************************************************************************** -(in-package :reversi) -(declaim (optimize (safety 1) (debug 3) (speed 3) (compilation-speed 0))) +(in-package #:reversi) + (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *edge-and-x-lists* @@ -50,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)) @@ -90,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) @@ -118,6 +119,7 @@ (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) #'> #'<))) @@ -140,7 +142,8 @@ "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 @@ -187,7 +190,8 @@ (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 @@ -205,39 +209,41 @@ (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) @@ -250,11 +256,11 @@ (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))))