Function: landmark-strongest-square

landmark-strongest-square is a byte-compiled function defined in landmark.el.gz.

Signature

(landmark-strongest-square)

Documentation

Compute index of free square with highest score, or nil if none.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/landmark.el.gz
(defun landmark-strongest-square ()
  "Compute index of free square with highest score, or nil if none."
  ;; We just have to loop other all squares. However there are two problems:
  ;; 1/ The SCORE-TABLE only gives correct scores to free squares. To speed
  ;;	up future searches, we set the score of padding or occupied squares
  ;;	to -1 whenever we meet them.
  ;; 2/ We want to choose randomly between equally good moves.
  (let ((score-max 0)
	(count	   0)			; Number of equally good moves
	(square	   (landmark-xy-to-index 1 1)) ; First square
	(end	   (landmark-xy-to-index landmark-board-width landmark-board-height))
	best-square score)
    (while (<= square end)
      (cond
       ;; If score is lower (i.e. most of the time), skip to next:
       ((< (aref landmark-score-table square) score-max))
       ;; If score is better, beware of non free squares:
       ((> (setq score (aref landmark-score-table square)) score-max)
	(if (zerop (aref landmark-board square)) ; is it free ?
	    (setq count 1		       ; yes: take it !
		  best-square square
		  score-max   score)
	    (aset landmark-score-table square -1))) ; no: kill it !
       ;; If score is equally good, choose randomly. But first check freedom:
       ((not (zerop (aref landmark-board square)))
	(aset landmark-score-table square -1))
       ((zerop (random (setq count (1+ count))))
	(setq best-square square
	      score-max	  score)))
      (setq square (1+ square)))	; try next square
    best-square))