Commit d6e07ba1 authored by Adrian Kosmaczewski's avatar Adrian Kosmaczewski

Fixed lattice size

parent ba00c9a6
......@@ -2,5 +2,5 @@
(defun print-cell (c)
(if (eq c 'alive)
(format nil " * |")
(format nil " x |")
(format nil " |")))
......@@ -10,8 +10,8 @@
(defun make-world (size alive-cells)
(defvar cells (make-hash-table :test #'equalp))
(loop for a from 0 to size do
(loop for b from 0 to size do
(loop for a from 0 to (- size 1) do
(loop for b from 0 to (- size 1) do
(let ((c (make-coord :x a :y b)))
(if (find-in-list c alive-cells)
(setf (gethash c cells) 'alive)
......@@ -41,16 +41,16 @@
(defmethod print-world ((object world))
(with-slots (size cells) object
(loop for a from 0 to size do
(loop for a from 0 to (- size 1) do
;; First line with coordinates
(if (= a 0)
(progn
(format t " ")
(loop for b from 0 to size do
(loop for b from 0 to (- size 1) do
(format t "~3d|" b))
(format t "~%")))
(format t "~3d|" a)
(loop for b from 0 to size do
(loop for b from 0 to (- size 1) do
(let ((c (make-coord :x b :y a)))
(format t "~A" (print-cell (gethash c cells)))))
(format t "~%"))))
......
(require "asdf")
(asdf:operate 'asdf:load-op 'conway)
(defun clear ()
(defun clear-screen ()
;; https://rosettacode.org/wiki/Terminal_control/Clear_the_screen#Common_Lisp
(format t "~C[2J" #\Esc))
......@@ -15,7 +15,7 @@
(defvar generation 1)
(loop
(clear)
(clear-screen)
(print-world world)
(format t "~%Generation ~d~%" generation)
(setq generation (+ 1 generation))
......
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