Skip to content

antononcube/Raku-Math-GameTheory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Math::GameTheory

The package provides descriptions and data of different games amenable for Game Theory experiments and studies.


Installation

From Zef ecosystem:

zef install Math::GameTheory

From GitHub:

zef install https://github.com/antononcube/Raku-Math-GameTheory

Game Theory data

All games known by the package "Math::GameTheory":

use Math::GameTheory;

say "Total number of known games: {game-theory-data().elems}";
say game-theory-data();
# Total number of known games: 52
# (3Coordination ArmsRaces BachOrStravinsky BattleOfTheBismarck BattleOfTheSexes BeerQuiche BertrandOligopoly BuyingStock Centipede Chicken ColonelBlotto Compound Contribution Convergence CournotOligopoly DangerousCoordination DinersDilemma Discoordination ElFarolBar Entry Escalation Exponential Greedy GuessTwoThirdsAverage HawkDove Hero Inspection LinearCournotDuopoly LinearCournotOligopoly MatchingPennies Morra MultivariateRandom NashPoker OPD OddsAndEvens OptionalPrisonersDilemma PlatoniaDilemma PrisonersDilemma PureCoordination Random Revolution RockPaperScissors Shapley SimpleInspection SmallPig StagHunt TravelersDilemma TreeBattleOfTheBismarck TreeMatchingPennies VolunteersDilemma Welfare ZeroSumRandom)

Games and their classes:

my @dsGames = game-theory-data(Whatever, property => "Classes").map({ $_.key X $_.value.Array }).flat(1).map({ <name property> Z=> $_  })».Hash;
@dsGames.elems
# 153

Here is a summary:

use Data::Summarizers;

sink records-summary(@dsGames)
# +------------------+--------------------------+
# | property         | name                     |
# +------------------+--------------------------+
# | MatrixGame => 42 | ZeroSumRandom     => 5   |
# | 2Player    => 26 | MatchingPennies   => 5   |
# | Symmetric  => 24 | PureCoordination  => 5   |
# | NPlayer    => 12 | VolunteersDilemma => 5   |
# | Social     => 10 | RockPaperScissors => 5   |
# | TreeGame   => 7  | Welfare           => 4   |
# | Recreation => 6  | Shapley           => 4   |
# | (Other)    => 26 | (Other)           => 120 |
# +------------------+--------------------------+

Here is a "taxonomy tree" like breakdown:

use ML::TriesWithFrequencies;

my %cat = <2Player 3Player NPlayer MatrixGame TreeGame Symmetric> Z=> (^7);

game-theory-data(Whatever, property => "Classes").values
==> { .map({ %cat.keys (&) $_ }) }()
==> { $_.map({ $_ ?? $_.keys !! 'Other' })».sort({ %cat{$_} })».List }()
==> trie-create()
==> trie-form()
# TRIEROOT => 52
# ├─2Player => 26
# │ ├─MatrixGame => 25
# │ │ └─Symmetric => 14
# │ └─NPlayer => 1
# │   └─MatrixGame => 1
# ├─3Player => 3
# │ └─MatrixGame => 3
# ├─MatrixGame => 2
# ├─NPlayer => 11
# │ └─MatrixGame => 11
# │   └─Symmetric => 8
# ├─Other => 1
# ├─Symmetric => 2
# └─TreeGame => 7

Here is a property vs. game cross tabulation:

use Data::Reshapers;
use Data::Translators;

cross-tabulate(@dsGames, 'property', 'name')
==> { $_.map({ %( property => $_.key, |$_.value) }).sort(*<property>).List }()
==> to-dataset()
==> to-html(field-names => ['property', |game-theory-data()], :vertical-header-names)
==> { .subst('1', '', :g) }()
==> { .subst(/ ['<th' .+? '>' property '</th>'] /,  '<th>property</th>') }()
property3CoordinationArmsRacesBachOrStravinskyBattleOfTheBismarckBattleOfTheSexesBeerQuicheBertrandOligopolyBuyingStockCentipedeChickenColonelBlottoCompoundContributionConvergenceCournotOligopolyDangerousCoordinationDinersDilemmaDiscoordinationElFarolBarEntryEscalationExponentialGreedyGuessTwoThirdsAverageHawkDoveHeroInspectionLinearCournotDuopolyLinearCournotOligopolyMatchingPenniesMorraMultivariateRandomNashPokerOPDOddsAndEvensOptionalPrisonersDilemmaPlatoniaDilemmaPrisonersDilemmaPureCoordinationRandomRevolutionRockPaperScissorsShapleySimpleInspectionSmallPigStagHuntTravelersDilemmaTreeBattleOfTheBismarckTreeMatchingPenniesVolunteersDilemmaWelfareZeroSumRandom
2Player
3Player
Coordination
Economics
Intransitive
MatrixGame
Military
NPlayer
Random
Recreation
Social
Symmetric
TreeGame
ZeroSum

Two player games

Get the game "Chicken" (provided by the package):

my $obj = game-theory-data('Chicken')
# MatrixGame(:name("Chicken"), :number-of-players(2), :number-of-actions(("Player 1" => 2, "Player 2" => 2)))

Here is a description of the game:

$obj.description
# The name \"chicken\" has its origins in a dangerous game in which two drivers drive toward each other. Each driver has the choice to either continue or swerve. Either at least one driver swerves, or both may die in the crash. The driver who swerved will be called a chicken, meaning a coward.

Here is game's table:

$obj.html
Chicken
Swerve Straight
Swerve 0 0 -1 1
Straight 1 -1 -5 -5

Here is a gray-scale version of the dataset can be obtained with $obj.html(theme => 'gray-scale').


Three player games

Get the game "3Coordination" (provided by the package):

my $obj = game-theory-data('3Coordination')
# MatrixGame(:name("3Coordination"), :number-of-players(3), :number-of-actions((:Roosevelt(3), :Churchill(3), :Stalin(3))))
$obj.description
# An extension of the coordination game where payoffs are based on the number of coordinated players.

Here is game's table:

$obj.html
3Coordination
Churchill Roosevelt Stalin
Churchill Roosevelt Stalin Churchill Roosevelt Stalin Churchill Roosevelt Stalin
Churchill 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1
Roosevelt 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1
Stalin 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2

Zero sum games

Represent a Rock Paper Scissors game as a directed graph:

use Graph;
my $g = Graph.new(edges => [Rock => "Scissors", Scissors => "Paper", Paper => "Rock"]):d;
#$g.dot(engine => 'neato', :2size, vertex-font-size => 8):svg
# Graph(vertexes => 3, edges => 3, directed => True)

Create a Rock Paper Scissors game:

use Data::Reshapers;

my @payoff-array = ($g.adjacency-matrix <<->> transpose($g.adjacency-matrix)).deepmap(-> Int:D $p { [$p, -$p] });
my $game = Math::GameTheory::MatrixGame.new(:@payoff-array, game-action-labels => ($g.vertex-list xx 2))
# MatrixGame(:name(Whatever), :number-of-players(3), :number-of-actions(("Player 2" => 3, "Player 1" => 3)))

Here is game's table:

$game.html(theme => 'default')
Paper Rock Scissors
Paper 0 0 1 -1 -1 1
Rock -1 1 0 0 1 -1
Scissors 1 -1 -1 1 0 0

TODO

  • TODO Implementation
    • TODO Retrieval and creation of games
      • DONE Games data JSON file and corresponding retrieval (multi-)sub
      • TODO Retrieving games using regexes
      • TODO Using properties with any case
    • TODO Matrix games
      • DONE MatrixGame class
      • DONE HTML format of matrix game dataset
      • DONE Wolfram Language (WL) representation
      • TODO Payoff functions
        • TODO Expectation
        • TODO MarginalDistribution
        • TODO MultivariateDistribution
        • TODO Variance
        • TODO Simulation
      • TODO Simpler zero-sum games initialization
    • TODO Tree games
      • TODO TreeGame class
      • TODO Creation using WL's tree game input format
      • TODO Special tree-game plots
  • TODO Documentation
    • DONE Complete README
    • TODO Basic usage notebook
    • TODO Blog post
    • TODO Video demo

About

Raku package with descriptions and data of different games amenable for Game Theory experiments and studies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages