Skip to content

Instantly share code, notes, and snippets.

@death
Created December 24, 2009 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save death/263071 to your computer and use it in GitHub Desktop.
Save death/263071 to your computer and use it in GitHub Desktop.
(defclass random-world (world)
((initial-random-state :initarg :initial-random-state :accessor initial-random-state))
(:default-initargs :initial-random-state (make-random-state t)))
(defmethod shared-initialize :after ((world random-world) slot-names &rest initargs &key)
(declare (ignore slot-names initargs))
(let ((*random-state* (make-random-state (initial-random-state world))))
;; Add random objects to the world
))
(defmethod reinitialize-instance :before ((world random-world) &rest initargs)
(declare (ignore initargs))
(clear-objects world)) ; tbd
(defun random-worlds-generator (n)
(let ((worlds (map-into (make-array n) (lambda () (make-instance 'random-world)))))
(lambda (index)
(reinitialize-instance (aref worlds (mod index n))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment