Improve Game Strategy with LISP Function Help | Random Stone Placement

  • Thread starter Thread starter Adam
  • Start date Start date
  • Tags Tags
    Function
Click For Summary
SUMMARY

The discussion focuses on improving a LISP function designed for a game strategy involving random stone placement adjacent to an opponent's last move. The current implementation, which utilizes a 3x3 array, encounters freezing issues when the opponent's stone is placed on the left edge of the board. The function lacks error checking for row and column values, leading to potential infinite loops in the score calculation. A suggestion was made to implement boundary checks to prevent illegal values from causing the function to freeze.

PREREQUISITES
  • Understanding of LISP programming language
  • Familiarity with game theory concepts, particularly heuristic strategies
  • Knowledge of array data structures and indexing
  • Experience with debugging techniques in LISP
NEXT STEPS
  • Implement boundary checks in LISP functions to prevent illegal indexing
  • Explore LISP debugging tools to identify infinite loops
  • Research heuristic algorithms for game strategies
  • Learn about random number generation techniques in LISP
USEFUL FOR

Game developers, LISP programmers, and anyone interested in implementing strategic algorithms in game design.

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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 33 ·
2
Replies
33
Views
7K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 18 ·
Replies
18
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
10K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
13
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K