Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why this no work?

Name: Anonymous 2011-04-21 11:41

;___;



(defmacro get-pos (board x y)
  `(nth ,y (nth ,x ,board)))

(defun cell-times (lst &optional (acc 0))
  (if lst
      (cond ((eq (car lst) nil)
         (cell-times (cdr lst) acc))
        ((numberp (car lst))
         (cell-times (cdr lst) acc))
        (t (cell-times (cdr lst) (1+ acc))))
      acc))
 
(defun get-if-possible (board x y) ;X och Y felet ligger här!?
  (if (not
       (and (>= x (length board))
        (>= y (length (nth 0 board)))))
      (if
       (not (< x 0))
       (if (not (< y 0))
       (get-pos board x y)))))

(defun get-neighbours (board x y)
  (let ((output '() ))
    (push (get-if-possible board (1+ x) y) output)
    (push (get-if-possible board (1- x) y) output)

    (push (get-if-possible board x (1+ y)) output)
    (push (get-if-possible board x (1- y)) output)

    (push (get-if-possible board (1+ x) (1+ y)) output)
    (push (get-if-possible board (1- x) (1- y)) output)

    (push (get-if-possible board (1+ x) (1- y)) output)
    (push (get-if-possible board (1- x) (1+ y)) output)
    output))

(defun next-gen (board) ;Den ändrar board, men hur ><?!
  (let ((output board))
  (loop for x-num from 0 to (1- (length output))
     for x in output do
       (loop for y in x
        for y-num from 0 to (1- (length x)) do
        (let ((neigh-val (cell-times (get-neighbours output x-num y-num))))
          (cond
        ((< neigh-val 2) (setf (get-pos output x-num y-num) neigh-val))
        ((= neigh-val 3) (setf (get-pos output x-num y-num) 'x))
        ((> neigh-val 3) (setf (get-pos output x-num y-num) neigh-val))))))
  output))

Name: Anonymous 2011-04-21 12:01

>>2
Nope, forgot removing the comment.

>>3
It's Conway's game of life (a very cluttered version of it), or at least it is supposed to be.
The next-gen function is the most interesting one I guess as I get weird output which doesn't fit into the sims I've tested out on the web.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List