Game Theory Tools - tutorial  v0.6.0
Tools for calculating Nash equilibria
 All Files Pages
GTL parser

Running parser

Parser can be run in a following ways:

./gtl_parser # reads from std input and writes results to std output
./gtl_parser -i ../examples/extensive_form_game.gtl # reads from file ../exmples/extensive_form_game.gtl
./gtl_parser -o ../examples/output.gtl # writes output to ../exmples/output.gtl
./gtl_parser -e ../examples/errors.gtl # writes errors to ../exmples/errors.gtl
./gtl_parser -r JSON # makes parser return results with JSON format
./gtl_parser -r XML # makes parser return results with XML format
./gtl_parser -h # displays help
./gtl_parser -v # displays version number

Context and querying

When we initaite program it creates context that stores all declared params (values). A param can be a game, a player or a number. There is also mock context param that allows us previewing all currently available params.

When we declare new param:

LET chosen_identifer BE definition;

it is placed inside out context allowing us to perform a query on it:

FIND some_property FOR chosen_identifier;

We are also available to perform several queries at once:

FIND some_property, some_property2 FOR chosen_identifier, chosen_identifier2;

If some of params will not have sought property defined information about it will be returned.

Context will be created when we run program and start reading either from standart input or file making all newly defined object go straight there. But if we'd like to read definitions from another file it is possible to do it in 2 ways:

Values of a current context can be dumped into file with command STORE identifier;.

When loading a file, make sure its name is placed inside double quotation marks:

LOAD "../examples/extensive_form_game.gtl"; // game will be available after the file is processed
EXECUTE "../examples/extensive_form_game.gtl"; // current context is left intact
STORE "../examples/result.gtl"; // store all available params to file

To preview all available params call:

FIND values FOR context;

Params and identifiers

Identifiers that names params and their properties can be defined in a 2 ways:

All params have defined at least 2 properties:

Some params will have additional ones e.g. Context will have values that displays all params known to it.

2 of commonly used params are identifeirs and numbers:

LET number1 BE 1;
LET number2 BE 2.3;
LET number3 BE 4e5;
LET number4 BE 6.7e8;
LET id1 BE number1; // alias for whatever number1 is
LET id2 BE id1; // alias for whatever id2 is, here number1

Players

Players are required to define games. Each player has its own name (do not mistake with name of param that contains it) and a set of strategies.

We can define it this way:

LET player1 BE
PLAYER p {
strategy1,
strategy2
};

Player has some additional properties:

Once defined it can be used in games.

Games

The easiest way to explain is to use an example:

/* player p1 definition */
LET player1 BE
PLAYER p1 { s1, s2 };
/* game game1 definition */
LET game1 BE
STRATEGIC GAME
WITH
player1, // player passed by identifier
PLAYER p2 { s1, s2 } // player passed explicitly
SUCH AS
{ p1=s1, p2=s1 : 10, 20 }, // setting up payoff by givin all coorinates at once
{ p1=s1, p2=s2 : 30, 40 },
{ p1=s2 :
{ p2=s1 : 50, 60 }, // setting up payoff by givine ony part of coorinates at a time
{ p2=s2 : 70, 80 }
}
END;

We can see that strategic-form game can be deifined by payoffs of each of player's strategies combinations. We can group them by some choice (p1=s1 meaning that its defined for player p1 choosing strategy s1), or pass them by giveing all player's choices at once.

Extensive-form games are defined in a similar way:

/* player p1 definition */
LET player1 BE
PLAYER p1 { s1, s2 };
/* game game2 definition */
LET game2 BE
EXTENSIVE GAME
WITH
player1, // player passed by identifier
PLAYER p2 { s1, s2 } // player passed explicitly
SUCH AS
{ p1=s1 : // extensive-form games need to be defined as a trees
{ p2=s1 : 10, 20 }, // where we pass only one choice at a time
{ p2=s2 : 30, 40 } // - notice that from each node we can pass choices of only one player
},
{ p1=s2 :
{ p2=s1 : 50, 60 },
{ p2=s2 : 70, 80 }
}
END;

main difference being that extensive form games form a tree and the definition represents it - as such it have to pass one choice at a time and cannot group them.

Games have following properties defined:

Examples

examples/strategic_form_game.gtl:

/**
* Example: shows some features of language.
*/
// Players definition
LET player1 BE
PLAYER p1 { s1, s2 };
LET player2 BE
PLAYER p2 { s1, s2 };
/**
* Defines strategic-form game under 'game1' identifier.
*/
LET game1 BE
STRATEGIC GAME
WITH
player1, // player passed by identifier
PLAYER p2 { s1, s2 } // player passed explicitly
SUCH AS
{ p1=s1, p2=s1 : 10, 20 }, // setting up payoff by giving all coordinates at once
{ p1=s1, p2=s2 : 30, 40 },
{ p1=s2 :
{ p2=s1 : 50, 60 }, // setting up payoff by givine ony part of coordinates at a time
{ p2=s2 : 70, 80 }
}
END;
/**
* Displays game definition.
*/
FIND value FOR game1;
/**
* Searches for pure-strategy equlibrium.
*/
FIND pure_equilibrium FOR game1;
/**
* Searches for mixed-strategy equlibrium.
*/
FIND mixed_equilibrium FOR game1;
/**
* Searches for behavior-strategy equlibrium (non-existent for strategic-form games).
*/
FIND behavior_equilibrium FOR game1;

examples/extensive_form_game.gtl:

/**
* Example: shows some features of language.
*/
// Players definition
LET player1 BE
PLAYER p1 { s1, s2 };
LET player2 BE
PLAYER p2 { s1, s2 };
/**
* Defines strategic-form game under 'game2' identifier.
*/
LET game2 BE
EXTENSIVE GAME
WITH
player1, // player passed by identifier
PLAYER p2 { s1, s2 } // player passed explicitly
SUCH AS
{ p1=s1 : // extensive-form games need to be defined as a trees
{ p2=s1 : 10, 20 }, // where we pass only one choice at a time
{ p2=s2 : 30, 40 } // - notice that from each node we can pass choices of only one player
},
{ p1=s2 :
{ p2=s1 : 50, 60 },
{ p2=s2 : 70, 80 }
}
END;
/**
* Displays game definition.
*/
FIND value FOR game2;
/**
* Searches for pure-strategy equlibrium.
*/
FIND pure_equilibrium FOR game2;
/**
* Searches for mixed-strategy equlibrium.
*/
FIND mixed_equilibrium FOR game2;
/**
* Searches for behavior-strategy equlibrium (non-existent for strategic-form games).
*/
FIND behavior_equilibrium FOR game2;

examples/properties_querying.gtl:

/**
* Example: shows some features of language.
*/
// Values definitions
LET a BE 1;
LET b BE -1;
// Players definitions
LET player1 BE
PLAYER p1 { s1, s2 };
LET player2 BE
PLAYER p2 { s1, s2 };
// Game definition
LET game3 BE
STRATEGIC GAME
WITH
player1,
player2
SUCH AS
{ p1=s1 :
{ p2=s1 : a, b },
{ p2=s2 : b, a }
},
{ p1=s2 :
{ p2=s1 : b, a },
{ p2=s2 : a, b }
}
END;
// Querying for properties
FIND
properties, // list of known properties
referred_properties, // list of known properties of referred object
type // type of object
FOR
a,
b,
player1,
player2,
game3;