Skip to content

Commit

Permalink
congame-example-study: use opt-hash-ref to simplify prisoners-dilemma
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Nov 12, 2024
1 parent 35026d7 commit 5ada9ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions congame-example-study/info.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"gregor-lib"
"forms-lib"
"koyo-lib"
["monocle-lib" #:version "0.3"]
"sentry-lib"
"threading-lib"
"web-server-lib"))
Expand Down
14 changes: 8 additions & 6 deletions congame-example-study/prisoners-dilemma.rkt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#lang conscript

(require conscript/survey-tools
data/monocle
racket/match)

(provide
Expand All @@ -14,14 +15,15 @@
(defvar*/instance choices dilemma-choices)
(defvar choice)

(define (&my-choice)
(parameterize ([current-hash-maker hash])
(&opt-hash-ref*
(get-current-group)
(current-participant-id))))

(define (make-choice! choice)
(with-study-transaction
(if (undefined? choices)
(set! choices (hash (get-current-group) (hash (current-participant-id) choice)))
(set! choices (hash-update
choices (get-current-group)
(λ (ht) (hash-set ht (current-participant-id) choice))
hash)))))
(set! choices ((&my-choice) (if-undefined choices (hash)) choice))))

(defstep (intro)
@md{# Prisoner's Dilemma
Expand Down
2 changes: 2 additions & 0 deletions conscript/base.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
set!
values

parameterize
with-handlers

;; Racket Runtime
Expand Down Expand Up @@ -132,6 +133,7 @@
congame-web/components/uploaded-file
conscript/matchmaking
conscript/survey-tools
data/monocle
gregor
koyo/haml
racket/format
Expand Down

0 comments on commit 5ada9ec

Please sign in to comment.