Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defparameter kingdoms (make-hash-table :test #'equalp)) ; empty hashtable to store all the kingdoms
- (defun r-walk (val len)
- "increases val randomly, until len = 0"
- (if (zerop len)
- val
- (r-walk (if (zerop (random 2))
- (+ val 3)
- (+ val (+ (random 11) 5)))
- (1- len))))
- (defun f-digit (val)
- "Finds the first digit in val and converts
- it from a float to a number."
- (format t "~f / ~f = ~f~%" val (expt 10 (log val 10)) (/ val (expt 10 (log val 10))))
- (rational (/ val (expt 10 (log val 10)))))
- (defun init-kingdom (name)
- "Initiates a kingdom as a hash table, indexed by name
- and contains a pair of (workers . power)"
- (setf (gethash name kingdoms) (list 1 100)))
- (defun update-kingdoms (kingdom-list workers)
- "Add workers to each kingdom by a random walk with the
- value of workers and the length of the first digit of
- a specific kingdom's power."
- (loop for key being the hash-keys of kingdom-list
- using (hash-value (a b))
- do (setf (gethash key kingdom-list)
- (list (+ (r-walk workers
- (f-digit a))
- a)
- (+ (r-walk workers
- (f-digit a))
- b)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement