Emacs gamification

zen-reward-mode is a simple gamification of emacs. The idea of gamification is explained at http://en.wikipedia.org/wiki/Gamification

The rules of the game are:

  • Typing a character in a buffer gives you one zen reward point, ZRP for short.
  • Closing an org mode TODO item gives you 1000 ZRP!
  • Doing something silly like browsing 9gag costs you all your ZRP, so its quite expensive

This concept might appear dumb. It is easy to fool the system and browse the precious 9gag regardless of how many ZRP you have.

It is my experience that this system works remarkably well. It is simply more rewarding to play mental judo with yourself rather than obtaining the reward by cheating.

It might be the same for you!

 1;;
 2(define-minor-mode zen-reward-mode
 3  "type a lot and get a reward!."
 4  :global t
 5  :init-value nil
 6  :lighter nil
 7  :keymap nil
 8  :group 'zen
 9
10  (if zen-reward-mode
11      (progn (add-hook 'pre-command-hook 'zen-reward-pre-command-hook)
12	     (add-hook 'org-after-todo-state-change-hook 'zen-reward-todo-state-change-hook))
13    (progn (remove-hook 'pre-command-hook 'zen-reward-pre-command-hook)
14	   (remove-hook 'org-after-todo-state-change-hook 'zen-reward-todo-state-change-hook))))
15
16(defvar  zen-reward-accumulator 0)
17
18(defun zen-reward-todo-state-change-hook ()
19  (message "todo hook %s %s" org-state (org-show-priority))
20  ;;if you toggle a task back and forth you get super rich.
21  ;;you get rewarded for CANCELLED also, but that is good!
22  (if  (equal org-state "DONE")
23      (progn
24	(let ((reward (string-to-number (substring (org-show-priority) (length "Priority is ") ))))
25	  ;;priority A is 4001, B 3001 and so on. probably can be negative as well. so reward needs to be modified a bit
26	  (message "todo reward %d!" reward)
27	  (setq zen-reward-accumulator (+ reward zen-reward-accumulator) ))
28      ))
29  )
30				      ;testing. only get reward for typing, not for cursor movement and other things
31(defun zen-reward-pre-command-hook ()
32  "accumulate typing reward."
33  (if (or (eq real-last-command 'self-insert-command)
34	  (eq real-last-command 'org-self-insert-command))
35      (setq zen-reward-accumulator (1+ zen-reward-accumulator) ))
36  ;;  (message "reward:%d %s %d" zen-reward-accumulator real-last-command (random))
37  )
38(defun zen-claim-reward ()
39  "cash in your bountiful reward, spend it on fun and games!"
40  (interactive )
41  (message "reward:%d" zen-reward-accumulator)
42  (setq zen-reward-accumulator 0))
43
44(defun zen-inspect-reward ()
45  "how soon can i afford fun and games?"
46  (interactive )
47  (message "zen reward:%d" zen-reward-accumulator)
48  )
49
50;;
51(zen-reward-mode)

an example for 9gag:

 1(defun zen-can-haz-reward ()
 2  (< 1000 zen-reward-accumulator ))
 3
 4(defun 9gag ()
 5  (interactive)
 6  (if (zen-can-haz-reward)
 7      (progn
 8	(zen-set-state 0)
 9	(zen-claim-reward)
10	(xwidget-webkit-browse-url "http://www.9gag.com")
11	)
12    (message "Your meager offerings of %s ZRP wont suffice. Go away!" zen-reward-accumulator))
13
14    )