-
-
Save luxbock/6d8250cdc12b9eb27567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn game-n | |
[N A & game-elements] | |
{:pre [every? true? (map unique? A)]} | |
(let [payoffs (payoff-matrix N A game-elements)] | |
{:players (range N) | |
:actions A | |
:payoffs payoffs | |
:utility-fn (fn utility-fn | |
([actions] | |
{:pre [(= N (count actions))]} | |
(let [indices (map #(.indexOf %1 %2) A actions)] | |
(apply (partial mget payoffs) indices))) | |
([actions player] | |
{:pre [(= N (count actions)) | |
(<= player N)]} | |
(nth player (utility-fn actions))))})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
game-theory.core> (def pd | |
(game-n 2 | |
[[:confess :deny] | |
[:confess :deny]] | |
[[:confess :confess] [1, 1]] | |
[[:confess :deny] [4, 0]] | |
[[:deny :confess] [0, 4]] | |
[[:deny :deny] [3, 3]])) | |
#'game-theory.core/pd | |
game-theory.core> (:utility-fn pd [:confess :confess]) | |
#<core$game_n$utility_fn__39171 game_theory.core$game_n$utility_fn__39171@1104203> | |
game-theory.core> (*1 [:confess :confess]) | |
[1 1] | |
game-theory.core> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment