Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defparameter *names* (list 'character1 'character2 'character3))
- (defparameter *strings* (list "~A 1 question" "~A 2 question" "~A 3 question" "~A 4 question" "~A 5 question" "~A 6 question" "~A 7 question"))
- (defun replace-all (string part replacement &key (test #'char=))
- "Returns a new string in which all the occurences of the part
- is replaced with replacement."
- (with-output-to-string (out)
- (loop with part-length = (length part)
- for old-pos = 0 then (+ pos part-length)
- for pos = (search part string
- :start2 old-pos
- :test test)
- do (write-string string out
- :start old-pos
- :end (or pos (length string)))
- when pos do (write-string replacement out)
- while pos)))
- (defun tweak-text (lst caps lit)
- (when lst (let ((item (car lst))
- (rest (cdr lst)))
- (cond ((eq item #\space) (cons item (tweak-text rest caps lit)))
- ((member item '(#\! #\? #\.)) (cons item (tweak-text rest t lit)))
- ((eq item #\") (tweak-text rest caps (not lit)))
- (lit (cons item (tweak-text rest nil lit)))
- ((or caps lit) (cons (char-upcase item) (tweak-text rest nil lit)))
- (t (cons (char-downcase item) (tweak-text rest nil nil)))))))
- (defun interp1 (name string)
- (format nil (replace-all string "~A" "~:*~A")
- (coerce (tweak-text (coerce (prin1-to-string name)
- 'list)
- t
- nil)
- 'string)))
- (defun combine-all (namelist stringlist)
- (mapcar (lambda (x) (mapcar (lambda (y) (interp1 y x)) namelist)) stringlist))
- (defun swap-right (lst)
- "Swaps the first element of a given list with a random
- OTHER element (not itself). This is intentional. We do
- not want each party member appearing in his/her own list."
- (if (= (length (cdr lst)) 0)
- nil
- (progn
- (rotatef (car lst)
- (nth (1+ (random (length (cdr lst))))
- lst))
- lst)))
- (defun shuffle (lst)
- "This goes through a list and swap-rights each element."
- (if (null lst)
- nil
- (let ((swapped (swap-right lst)))
- (cons (car lst) (shuffle (cdr swapped))))))
- (defun transpose (lst)
- "Does just what it says; transposes a list of lists,
- creating a number of new lists equal to the length of
- the longest starting sub-list."
- (let ((maxsize (reduce #'max (mapcar #'length lst))))
- (loop for i
- from 0
- to (1- maxsize)
- collect (mapcar (lambda (x) (nth i x))
- lst))))
- (defun make-party-alist (namelist stringlist)
- "Creates a list of questions for each party member
- about the others."
- (pairlis namelist
- (transpose (mapcar #'shuffle
- (combine namelist
- stringlist)))))
- (defun make-dm-list (namelist stringlist)
- "Creates a list of questions (intended for the DM)
- about the various party members."
- (let* ((numnames (length namelist))
- (numstrings (length stringlist))
- (newnamelist (copy-list namelist))
- (newstringlist (subseq stringlist 0 (- numstrings (mod numstrings numnames)))))
- (alexandria:shuffle (mapcar (lambda (y)
- (interp1
- (car (setf newnamelist
- (alexandria:rotate newnamelist)))
- y))
- (alexandria:shuffle newstringlist)))))
- (defun pprint-questions (qlist)
- (if (null qlist)
- nil
- (loop for i
- below (length qlist)
- collect (format t
- "~d. ~A~% ~A~%~%~%"
- (1+ i)
- (nth i qlist)
- (coerce (make-list 250
- :initial-element #\_)
- 'string)))))
Advertisement
Add Comment
Please, Sign In to add comment