Function: gomoku-update-score-table

gomoku-update-score-table is a byte-compiled function defined in gomoku.el.gz.

Signature

(gomoku-update-score-table SQUARE DVAL)

Documentation

Update score table after SQUARE received a DVAL increment.

Source Code

;; Defined in /usr/src/emacs/lisp/play/gomoku.el.gz
;;;
;;; MAINTAINING THE SCORE TABLE.
;;;

;; We do not provide functions for computing the SCORE-TABLE given the
;; contents of the BOARD.  This would involve heavy nested loops, with time
;; proportional to the size of the board.  It is better to update the
;; SCORE-TABLE after each move.  Updating needs not modify more than 36
;; squares: it is done in constant time.

(defun gomoku-update-score-table (square dval)
  "Update score table after SQUARE received a DVAL increment."
  ;; The board has already been updated when this function is called.
  ;; Updating scores is done by looking for qtuples boundaries in all four
  ;; directions and then calling update-score-in-direction.
  ;; Finally all squares received the right increment, and then are up to
  ;; date, except possibly for SQUARE itself if we are taking a move back for
  ;; its score had been set to -1 at the time.
  (let* ((x    (gomoku-index-to-x square))
	 (y    (gomoku-index-to-y square))
	 (imin (max -4 (- 1 x)))
	 (jmin (max -4 (- 1 y)))
	 (imax (min 0 (- gomoku-board-width x 4)))
	 (jmax (min 0 (- gomoku-board-height y 4))))
    (gomoku-update-score-in-direction imin imax
				      square 1 0 dval)
    (gomoku-update-score-in-direction jmin jmax
				      square 0 1 dval)
    (gomoku-update-score-in-direction (max imin jmin) (min imax jmax)
				      square 1 1 dval)
    (gomoku-update-score-in-direction (max (- 1 y) -4
					   (- x gomoku-board-width))
				      (min 0 (- x 5)
					   (- gomoku-board-height y 4))
				      square -1 1 dval)))