Improve Game Strategy with LISP Function Help | Random Stone Placement

  • Thread starter Thread starter Adam
  • Start date Start date
  • Tags Tags
    Function
AI Thread Summary
The discussion revolves around a function intended for a game heuristic that places a stone in a strategic location based on the opponent's last move. The goal is to either create a winning row of five stones or block the opponent from doing so. The function is designed to randomly place a stone in one of the adjacent positions to the opponent's last move, but it currently freezes when the opponent's move is on the left edge of the board. The issue appears to stem from a lack of error checking for the row and column values generated, which may lead to illegal positions that the score function cannot handle, resulting in an infinite loop. Suggestions for improvement include implementing boundary checks to ensure that the randomly generated positions remain within the valid range of the game board.
Adam
Messages
65
Reaction score
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:
(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?
 
Computer science news on Phys.org
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.
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...

Similar threads

Replies
8
Views
2K
Replies
18
Views
7K
Replies
11
Views
9K
Replies
3
Views
4K
Back
Top