GithubHelp home page GithubHelp logo

hagl's Introduction

Hagl: Haskell Game Language

Description

A DSEL for experimental game theory (also called evolutionary game theory and behavioral economics). Supports defining games and strategies, then executing them repeatedly in order to collect and observe the results.

Hagl provides built-in support for standard game representations, such as normal and extensive form, and constructs for defining games in terms of the manipulation of a shared state (as in tic-tac-toe). New game representations can be easily added by instantiating a type class.

A monadic strategy DSL supports concise and vaguely English-like definitions of strategies for playing these games, usually iteratively.

While Hagl provides some basic game analyses, its primary focus is simulation and experimentation. Games can be executed and strategies can be pitted against each other for repeated play and in various kinds of tournaments.

Examples

To play with the examples, load them into GHCi by running ghci Hagl.Examples from this directory.

There are examples of Normal Form, Extensive Form, and State-Driven games.

For normal form games, you can view the payoff matrix by just evaluating the game in GHCi.

For example:

>> pd
    |  C  |  D 
  C | 2,2 | 0,3
  D | 3,0 | 1,1

You can view the game tree for any discrete game by using the gameTree function.

>> gameTree pd
Player 1
+- C -> Player 2
|  +- C -> [2,2]
|  `- D -> [0,3]
`- D -> Player 2
   +- C -> [3,0]
   `- D -> [1,1]

The function execGame is used to execute a game. It takes a game, a set of players to play the game, and a function to execute within the game execution monad.

Execution functions include:

  • step - Process a single node in the game tree.
  • once - Run through the game a single time to completion.
  • times n - Run the full game n times.

There are also many printing functions available for inspecting the execution state. These can be found in Hagl.Print.hs. Some examples include:

  • printMovesFromHere - Print the available moves from this location in the game tree.
  • printTranscripts - Print the transcript of all completed games.
  • printScore - Print the current score.

The execution and printing functions can be executed sequentially via bind operations. The best way to illustrate how this all works together is a few examples.

The following processes the first node in the game tree (Player 1's decision), then prints the moves available to Player 2.

>> execGame pd [tft, pavlov] (step >> printMovesFromHere)

The following runs the game four times, prints the transcript of all iterations, and then prints the current (in this case, final) score.

>> execGame pd [tft, suspicious] (times 4 >> printTranscripts >> printScore)

And finally, the following runs the game three times, prints the score, then runs 100 more iterations and prints the final score.

>> execGame pd [ccd, grim] (times 3 >> printScore >> times 100 >> printScore)

There is also a "tournament" facility that eases running many combinations of players and comparing their final scores. The tournament running functions can be found in Hagl.Tournament.hs.

All tournament functions return their results as a list of player names paired with scores. This can be printed in a nice way by passing this result to the printResults function, as shown below.

>> roundRobin pd 2 [tft, titForTwoTats, grim, suspicious, pavlov] (times 100 >> printScore) >>= printResults

For each pair of players from the list, this will run the iterated prisoner's dilemma 100 times, and print the score for those players. At the end, the total scores of all players involved will be printed in sorted order.

hagl's People

Contributors

pparkkin avatar walkie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hagl's Issues

New maintainer?

hi!
It seems like a good repo without maintenance. I am Haskell newbie looking for a project to adopt.
I have forked the project and working to make it build. Does it make sense to change the code to run with latest versions of packages?
I changed .cabal to have >= insted of == and I get this error:

[ 6 of 23] Compiling Hagl.Exec        ( Hagl/Exec.hs, interpreted )

Hagl/Exec.hs:261:21: error:
    • Could not deduce (MonadFail (ExecM g))
        arising from a use of ‘processLocation’
      from the context: (Game g, Eq (Move g))
        bound by the type signature for:
                   step :: forall g. (Game g, Eq (Move g)) => ExecM g (Maybe Payoff)
        at Hagl/Exec.hs:260:1-55
    • In the second argument of ‘(>>=)’, namely ‘processLocation’
      In the expression: location >>= processLocation
      In an equation for ‘step’:
          step
            = location >>= processLocation
            where
                processLocation l
                  = case treeAction l of
                      Decision i -> decide i >>= performMove l
                      Chance d -> fromDist d >>= performMove l
                      Payoff p -> givePayoff p
                performMove l m
                  = do e <- getExec
                       ....
                inc (Decision p) ns = setForPlayer p (forPlayer p ns + 1) ns
                inc _ ns = ns
                decide i
                  = do p <- liftM (forPlayer i) players
                       ....
                ....
    |
261 | step = location >>= processLocation
    |                     ^^^^^^^^^^^^^^^

Hagl/Exec.hs:318:10: error:
    • No instance for (Applicative (ExecM g))
        arising from the superclasses of an instance declaration
    • In the instance declaration for ‘Monad (ExecM g)’
    |
318 | instance Monad (ExecM g) where
    |          ^^^^^^^^^^^^^^^

Hagl/Exec.hs:321:10: error:
    • No instance for (Applicative (StratM s g))
        arising from the superclasses of an instance declaration
    • In the instance declaration for ‘Monad (StratM s g)’
    |
321 | instance Monad (StratM s g) where
    |          ^^^^^^^^^^^^^^^^^^
Failed, five modules loaded.

Any suggestion on how I should proceed?
thanks

Current version fails to build with recent versions of cabal (ghc 8.0.1)

There are some apparently minor changes to the library required per @peitalin due to changes in GHC over the last couple of years. I've gotten his forked version running without much trouble --- Is this project still maintained? I'd like to use the library but I don't have the Haskell background to make significant modifications or maintenance.

Cabal repl in a project depending on Hagl fails with "can't load .so/.DLL"

I created a new project with a dependency on Hagl, and tried to open up a REPL with "cabal repl" to play around with the Hagl DSL, but the command failed with the following message:

Loading package Hagl-3.0.0 ... <command line>: can't load .so/.DLL for: /vagrant/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.3/Hagl-3.0.0/libHSHagl-3.0.0-ghc7.8.3.so (/vagrant/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.3/Hagl-3.0.0/libHSHagl-3.0.0-ghc7.8.3.so: undefined symbol: Haglzm3zi0zi0_HaglziHistory_zuscore1_info)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.