Commit c08c1578 authored by Adrian Kosmaczewski's avatar Adrian Kosmaczewski

First successful world creation

parent 2f4442a9
......@@ -3,16 +3,29 @@
(cells :initarg :cells))
(:documentation "A lattice of cells referenced by coord values."))
(defun find-in-list (object list)
(block nested-loops
(loop for a in list do
(if (equalp a object)
(return-from nested-loops t)))))
(defun make-world (size alive-cells)
(defvar cells (make-hash-table))
(defvar cells (make-hash-table :test #'equalp))
(loop for a from 0 to size do
(loop for b from 0 to size do
(let ((c (make-coord :x a :y b)))
(print c))))
;; (if (member c alive-cells)
;; (setf (gethash c cells) 'alive)
;; (setf (gethash c cells) 'dead))))
(if (find-in-list c alive-cells)
(setf (gethash c cells) 'alive)
(setf (gethash c cells) 'dead)))))
(make-instance 'world :size size :cells cells))
(defmethod print-world ((object world))
(with-slots (size cells) object
(loop for a from 0 to size do
(loop for b from 0 to size do
(let ((c (make-coord :x b :y a)))
(format t "~A" (print-cell (gethash c cells)))))
(format t "~%"))))
(defmethod evolve ((object world))
(make-instance 'world :size (size object)))
(require "asdf")
(asdf:operate 'asdf:load-op 'conway)
(defparameter *my-hash* (make-hash-table))
(defparameter *my-hash* (make-hash-table :test #'equalp))
(defparameter *coord1* (make-coord :x 45 :y 64))
(defparameter *coord2* (make-coord :x 356 :y 65))
(setf (gethash *coord1* *my-hash*) 'alive)
(format t "~A~%" (print-cell (gethash *coord1* *my-hash*)))
(format t "~A~%" (print-cell (gethash (make-coord :x 45 :y 64) *my-hash*)))
;; ALIVE
(format t "~A~%" (gethash *coord2* *my-hash*))
;; NIL
......@@ -15,13 +16,12 @@
;; DEAD
(defun fa ()
(vector *coord1* *coord2* (make-coord :x 1 :y 2)))
(defparameter *vec* (fa))
(format t "~A~%" *vec*)
(list *coord1* *coord2* (make-coord :x 1 :y 2)))
(sleep 0.5)
(defparameter *w1* (make-world 5 nil))
(defvar alive-cells (fa))
(defparameter *w1* (make-world 5 alive-cells))
(print-world *w1*)
;;(defparameter *w2* (evolve *w1*))
;;(format t "~A~%" (size *w2*))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment