Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

LISP help

  1. Oct 13, 2003 #1
    Got a problem with this function. It is part of a heuristic thing for a game. If I can't get a winning row of five stones, or block a winning row from the opponent, or blah blah blah, I want it to place a stone at some random point adjacent to the opponent's last move. Basically think of a tic-tac-toe grid but larger. A 3x3 array, 0 to 9. If opponent places a stone in 4, then I want it to place randomly in 0 to 3 or 5 to 9. At the moment it almost works, but freezes if the stone is placed on the left edge of the board.

    Code (Text):

    (defun rndplyr ()
      (if (null (get-history))
          (list 0 0 )
        (let ((hist (get-history))
              (lm (car (get-history))))
          (do ((row (+ (car lm) (+ (random 3) -1 ) ))
               (col (+ (cadr lm) (+ (random 3) -1 ) )))
              ((score (list row col) (get-board))
               (list row col)))))
    Any hints?
  2. jcsd
  3. Oct 13, 2003 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Your code doesn't seem to error check to see if your value for row and col lie on the board... I surmise that the score function isn't written to handle illegal values and gets itself caught in an infinite loop.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: LISP help
  1. LISP for autocad (Replies: 4)

  2. RAM Help (Replies: 2)

  3. CPU help (Replies: 12)

  4. WavePad help (Replies: 2)