(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 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))
You should convert tabs to spaces before posting here.
Leaving that aside, what exactly are you trying to accomplish? (I have yet to fully read your code, but it does appear valid, at least syntactically and as far as the compiler is concerned).
>>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.
>>4
What is the input format supposed to look like?
You're setting numbers to the "array" (you should use an array instead of a list, but whatever):
CL-USER> (let ((gen '((O O O) (O X O) (O O O)))) (loop repeat 10 do (print (setf gen (next-gen gen)))))
((X 5 O) (4 6 X) (1 O O))
((0 5 1) (1 X X) (1 X X))
((1 5 1) (1 X X) (1 X X))
...
The problem here is that:
((< neigh-val 2) (setf (get-pos output x-num y-num) [i]neigh-val[/i]))
((= neigh-val 3) (setf (get-pos output x-num y-num) 'x))
((> neigh-val 3) (setf (get-pos output x-num y-num) [i]neigh-val[/i]))))))
those 2 are numeric, while the rest are supposed to be symbolic?
(defun next-gen (board)
(let ((output (copy-list board)))
(loop for x-num from 0 to (1- (length board))
for x in board do
(loop for y in x
for y-num from 0 to (1- (length x)) do
(let ((neigh-val (cell-times (get-neighbours board 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))
How come that this manipulates not only the output but also the board variable that I feed the function with?
>>9
Yes! That worked, nice (I used mapcar).
Though now I'm kind of scared as I have no idea what serves as a "deep copy" and just a reference to another object.
>>11
I find that to be completely unreadable.
I have some more functions to print the board and stuff like that, it all clocks in at about 83 LoC.
I also do not browse Reddit.
Name:
Anonymous2011-04-22 5:16
>>16 I also do not browse Reddit.
None of us does at the moment, man. You're not alone. Together we will survive.