WOLFRAM

A Whole New Ball Game: Game Theory in Wolfram Language 14.2

A Whole New Ball Game: Game Theory in Wolfram Language 14.2

Do you want to make optimal decisions against competition? Do you want to analyze competitive contexts and predict outcomes of competitive events? Do you need to elaborate strategies and plans against adversity and test the effectiveness of those strategies? Or are you simply an undergraduate student struggling to cope with a required course on game theory at your college?

Wolfram’s new suite of game theory functions will enable you to generate, play with, test, solve and visualize any event using game theory.

History of Game Theory

Originally, game theory was limited to simple games of chance. These have a few common characteristics: only two players are involved at a time and either one player wins and the other loses or both players have a zero payoff. These games are known today as two-player, zero-sum games.

If we define game theory based on the elaboration of optimal strategies, game theory may be as old as games of chance. We owe this early analysis (and probability theory!) to the famous polymath and gambler, Girolamo Cardano. Alternatively, if we define it on the analysis of games based on the possible actions of all players, then we may attribute its origins to James Waldegrave, for the analysis of the Le Her game in 1713, where minimax strategy solutions were given.

Of course, games can be more than just entertaining. After all, few games can claim to have a player base as big as the game of economics. Antoine-Augustin Cournot, in his 1838 research of the mathematical principles in the theory of wealth (Recherches sur les principes mathématiques de la théorie des richesses), discovered solutions to the price competition that would later be called Nash equilibria.

However, most of these discoveries are somewhat isolated and are usually considered as mere precursors to the modern subject. Game theory officially starts with John von Neumann’s 1944 book Theory of Games and Economic Behavior, where the term “game theory” was coined and the axioms of game theory were determined—thus establishing its own field. This overview of game theory history would be incomplete without mention of John Nash, whose existence theorem for Nash equilibria transformed game theory only a few years later in 1950.

As you may imagine, this field of study has grown tremendously since then. Modern game theory is best summarized as the mathematics of decision making. At its heart, it studies the behavior of human, animal and artificial players in all forms of competition. Herbert Gintis said it best:

“Game theory is about how people cooperate as much as how they compete… Game theory is about the emergence, transformation, diffusion and stabilization of forms of behavior.”

Engage with the code in this post by downloading the Wolfram Notebook

Matrix Games: Cat and Mouse

Matrix games are also known as simultaneous games. Indeed, these games are characterized by the simultaneity of the actions of all players. As the name implies, matrix games are based on matrices. To be precise, any matrix game of n players may be expressed by an n + 1-dimensional array, where the last dimension is a vector of payoffs for all players.

Matrix games can be generated using the new MatrixGame function in Version 14.2. For example, here is a two-player game in which each player has a choice of two actions:

game = MatrixGame

This game is a zero-sum game, as can be seen from the Dataset representing the payoffs for each player:

game ["Dataset"]

We use a payoff of 1 to represent winning, and a payoff of –1 to represent losing. As such, in this game, the first player wins when the actions of both players are matching, and the second player wins when the actions of both players aren’t.

While simultaneous games are usually expressed in terms of matrices, these rapidly became difficult to read as the number of players and actions increase. Hence, our team developed MatrixGamePlot for visualizing this class of games:

MatrixGamePlot [game]

MatrixGamePlot and other functions are designed to work for games with any number of players. You may find that "SplitSquare" is a more intuitive layout for games with two players, while games with more than two players are better visualized using the default "BarChart":

{MatrixGamePlot [game, PlotLayout

As good as these visualizations may be, it is difficult to infer the story behind this game just from general visualizations. For ease of interpretation, consider two players: a cat and a mouse. The cat can either search the house or the yard, and the mouse can hide in the house or the yard. Of course, the cat wins if it is in the same place as the mouse and if they are not in the same place, the mouse wins.

Cat and mouse illustration

The dataset and plot for the cat-and-mouse version of the game may be more easily read by specifying GamePlayerLabels and GameActionLabels in this game:

CatAndMouse = MatrixGame

{CatAndMouse ["Dataset"]

Of course, cats are lazy. It seems most likely that our cat is too sedentary to choose to go out of the house (🏠) for a mere mouse. Knowing this, an opportunistic mouse should choose to always go to the yard (🌿), as this should lead to a higher payoff. To verify this, the mouse should use MatrixGamePayoff on this game and strategy, which allows it to calculate the expected payoffs of a game based on a given strategy:

MatrixGamePayoff [game

But what if the cat isn’t lazy? Some cats have those mystical eyes, unpredictable, a perfect poker face. To our mouse, it seems this cat will do whatever is necessary to win. The mouse must revisit its strategy, making it stable and strong, making sure it is at least as likely to win as the cat. The mouse uses VerifyMatrixGameStrategy to test all strategies where each animal chooses either the house or the yard, and to verify if a particular strategy is a Nash equilibrium. Unfortunately, it seems that all cases are unstable and the cat may be at an advantage:

Table [VerifyMatrixGameStrategy

Our mouse has one last ace up its sleeve: FindMatrixGameStrategies! This powerful function is our game solver, computing Nash equilibria, that is, strategies that both players have no interest in changing. Using this tool, the mouse realizes its salvation lies in randomness:

FindMatrixGameStrategies [game]

This strategy is mixed, where the probability of some actions is not 0 or 1. In this case, the mouse will have to do a coin flip: if head, stay in the house, if tails, go to the yard. Note that the cat cannot take advantage of this strategy, so its best strategy is also a 50/50.

Granted, the game so far is a bit unrealistic. The mouse likely has many more places to hide, and the cat has many more places to search. This would imply that each player has more than two actions and indeed there are other games for which this happens. For example, in the Morra game, each player has 50 possible actions. All previously seen features are generalizable to this or any number of actions:

MatrixGamePlot [GameTheoryData ["Morra"]]

Of course, it’s hardly a party when only two players play at one time. You can also specify matrix games such as El Farol Bar with any number of players, although I wouldn’t wish that many mice on even my worst enemy:

MatrixGamePlot [GameTheoryData ["ElFarolBar"

Here, we use GameTheoryData, a helpful tool for classical games that will be explained later.

Tree Games: A Game-Changing Revolution

Outdoor chess matchesTree games are also known as sequential games. In these games, there are multiple actions, each taken by a single player in a given order. Like a decision tree, each decision reduces the number of possible actions until an end node is reached, where all players have a given payoff. As the name implies, tree games are based on Tree data structures. As such, they can be generated using nested lists following the structure of trees. Tree games are a big revolution in game theory, as, instead of a single event, they allow the analysis of a group of asynchronous interconnected decisions. This extends the applicability of game theory to many complex phenomena, otherwise out of reach using matrix games. Chess, for example, is a tree game, although an extremely large one, making its direct analysis as a tree game impractical.

Calling something a game usually implies that it is done for entertainment and not to be taken too seriously. That’s not the case in game theory, where a game refers to an event consisting of one or multiple decisions. Indeed, by that definition, almost everything that ever happened is a game, from throwing a rock into a lake to overthrowing a monarchy. Consider the latter as a “game,” where a colony has the choice to either rebel or concede, and in return, if there is rebellion, the country may grant independence or suppress the rebellion, and if the colony concedes, the country may tax or not. This situation can be represented using TreeGame:

game = TreeGame [{"Colony"

Classically, tree games are represented as trees. As such, the use of the "Tree" property may be sufficient for basic tree games. However, to have more control over the plotting and to represent accurately more advanced tree games, TreeGamePlot is likely a better visualization:

{game ["Tree"]

If the colony rebels, the country has the choice to either grant independence or suppress rebellion. Since losing a colony is costly, the country always has greater interest in suppressing rebellion, as shown by comparing the second payoff of each outcome:

TreeGamePayoff [game,

TreeGamePayoff [game,

Even only in terms of game theory, it is evident the country is advantaged in this game. Often in tree games, it is the player that plays last that is advantaged, as the payoff is chosen directly. In this case, whatever the colony employs, the country can ensure a positive payoff by simply choosing to suppress and tax depending on the action of the colony:

game = TreeGame [{"Colony"

It turns out that being taxed is better than being suppressed for this colony. Thus, even though this may not satisfy both players, the subgame perfect equilibrium is found when the country taxes the colony. This can be shown by solving the tree game using FindTreeGameStrategies:

FindTreeGameStrategies [game]

Of course, tree games can have more than just two consecutive actions. For example, consider this game called Centipede, for which the name choice is still a mystery to me:

TreeGamePlot [GameTheoryData["Centipede"

Tree games aren’t limited to two players either. For example, consider an inheritance game where we track the inherited golden cactus belonging to grandfather Zubair through his entire family:

TreeGamePlot [SetDelayed

Game Data: A Numbers Game

Game theory is plagued with a seemingly limitless number of named games. Without playing the blame game, let’s just say it makes the subject unreasonably daunting to beginners. Truth be told, with a decent understanding of matrix and tree games, you’ll generally be able to understand 99% of all named games. Whether you need a game quick and easy or you’d like to analyze a game you’ve never heard of before, GameTheoryData can help you. GameTheoryData currently has nearly 50 curated games:

GameTheoryData []

Length

It turns out it is quite difficult to infer the meaning and utility of a game just from a list of payoffs. Since each game has its own story, origin, quirks and properties, we wanted to allow users to explore the richness of game theory with well-curated games right within the language. Thus, each game has handy features enabling anyone to understand, research and characterize it. You can find a textual description of the game:

GameTheoryData ["ElFarolBar", "Description"]

Learn about its origins in the literature:

GameTheoryData ["ElFarolBar", "Source"]

Find the game classes it belongs to:

GameTheoryData ["ElFarolBar", "Classes"]

And, of course, play with it:

MatrixGamePlot [GameTheoryData

Ahead of the Game

We know that game theory can be a bit obtuse to the uninitiated. In this respect, our first goal with these game theory features is to ease the process of constructing and playing with games, keeping it accurate and useful. Using extensive and approachable documentation, all these features have been kept in line with the fun and interesting character of games:

Wolfram documentation page MatrixGame

In fact, we’ve poured a lot of effort into the documentation of these functions. The number of examples, explanations and extensive consideration of even minute features goes far beyond the typical documentation for new features at launch. This level of documentation should enable you to pick up game theory in a matter of minutes:

Wolfram documentation page GameTheoryData

Links to all these resources are readily available in one place to enable users to have a complete overview of these functionalities:

Wolfram documentation page Game Theory

Game Over

Our current game theory features cater to learners of game theory more than other clientele, but don’t worry. We won’t declare “game over” early. We have many ideas for the future of Wolfram’s game theory suite. We know Wolfram features aren’t complete without vast generalizability. It may take some time, but we hope some generalizations of current functions may lead to great applicability to research and professional contexts. Most importantly, we’d love to get some feedback about what our users would like to see in the next iteration of these features.

Don’t be late to the game and try out these new features for yourself!

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.