DEV Community

Mehfila A Parkkulthil
Mehfila A Parkkulthil

Posted on • Edited on

How Gambit Represents Games

The challenge isn't playing the game — it's representing it in a way a computer can reason about.That's exactly what Gambit does.
Gambit is an open-source software toolkit for computing and analyzing game-theoretic models.
At its core, it gives you two main ways to describe a strategic situation: the normal form (also called the strategic form) and the extensive form. Each has its use, and understanding when to use which one is half the battle.

Normal Form Games

A normal form game flattens everything into a matrix. You have players, each player has a set of strategies, and the outcome is a payoff for every combination of choices. That's it.

Think of two coffee shops deciding whether to run a discount this week. Shop A can either run a promotion or hold prices. Shop B faces the same choice. The resulting 2x2 matrix captures what each shop earns depending on what the other does. In Gambit, you'd represent this as a Game object with two players, two strategies each, and four payoff entries.

import pygambit as gbt

g = gbt.Game.new_table([2, 2])
g.title = "Coffee Shop Pricing"
g.players[0].label = "Shop A"
g.players[1].label = "Shop B"

g.players[0].strategies[0].label = "Discount"
g.players[0].strategies[1].label = "Hold"
g.players[1].strategies[0].label = "Discount"
g.players[1].strategies[1].label = "Hold"

# Payoffs: (Shop A, Shop B)
g[0, 0][0], g[0, 0][1] = 3, 3   # Both discount
g[0, 1][0], g[0, 1][1] = 5, 1   # A discounts, B holds
g[1, 0][0], g[1, 0][1] = 1, 5   # A holds, B discounts
g[1, 1][0], g[1, 1][1] = 4, 4   # Both hold
Enter fullscreen mode Exit fullscreen mode

Top comments (0)