Giter Site home page Giter Site logo

axelrod.js's Introduction

Axelrod.js

An Axelrod's Iterative Prisoner's Dilemma tournament simulator for NPM.

(Tl;dr for Axelrod's tournament - in Prisoner's Dilemma, you want the lowest score. In iterative Prisoner's Dilemma, you want the lowest score after playing the same rival again and again.

Axelrod's tournament plays several strategies against each other, with the strategy that won most games - i.e. got the least points in most matches against other strategies - winning the tournament).

Dependencies (installed via npm install)

  • Gulp
  • Gulp-babel

Usage

node axelrod.js 
[-p, --plays (int >= 1) number of plays in each game between strategies]
[-r, --rounds (int >= 1) number of rounds in the tournament]
[-o, --output outputFileName] 
[-s, --strategies [strategyName1, strategyName2...]]
[-h, --help (shows this message)]
[-v, --verbose (true/false)]

Note that strategy names must correspond to strategies available at src/sample_strategies or src/custom_strategies - i.e. strategies whose implementations are available.

If a strategy name is provided and it does not exist in either of these directories, it will not be utilized; if no proper strategy names are supplied, the strategies from default mode will be played instead (see below).

Available sample strategies

  • Always-cooperate: always cooperates (does not snitch). If both players utilize this strategy, they each receive 1 point per play.
  • Always-defect: always defects (snitches on the other 'prisoner'). If both players utilize this strategy, they each receive 2 points; however, if one player cooperates and the other defects, the defecting player receives 0 points, while the cooperating player receives 3 points.
  • Random: chooses between defecting and cooperating randomly (50% chance for each).
  • Tit-for-tat: if it's the first turn, the strategy cooperates. Otherwise, it looks at what the rival player did in his previous turn, and does that.
  • Go-by-majority: if it's the first turn, the strategy cooperates. Otherwise, it looks at what the rival player did most in all previous turns, and does that.
  • Go-against-majority: similar to go-by-majority, only it does the opposite of what the rival player did most.

Default mode

Simply calling node axelrod.js will run a:

  • 200-plays, single round tournament
  • between the always-cooperate, always-defect, random and tit-for-tat strategies,
  • with verbose output (detailing for each play, each move made by each player, and the winner for each game and the total tournament)
  • which will be written to the console, rather than an output file.

Create your own strategy!

The simulator allows you to create your own strategies for the players, by creating a proper strategyName.js file and putting it in the src/custom_strategies folder. (An example of a created strategy can be found in src/custom_strategies/TemplateStrategy.js)

How to run

  • npm install
  • gulp build
  • node axelrod.js

axelrod.js's People

Contributors

udidoron avatar

Stargazers

 avatar

Watchers

James Cloos avatar Justin avatar  avatar

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.