Chapter 4. Overview of the Gambit API

Gambit is written in C++. This chapter gives an overview of the underlying library of classes which represent and manipulate games.

This chapter does not go into exhaustive detail about all functions and classes implemented in libgambit. Programmers interested in using the library in their own applications should consult the Doxygen-generated source documentation available from the Documentation page of the Gambit website, as well as the sample programs.

Gambit also provides an interface to the library for scripting languages by the use of SWIG (http://www.swig.org). Currently, only an interface for Python (http://www.python.org) is available. The SWIG wrapper should be easily modifiable to create interfaces for the other languages SWIG supports.

4.1. General concepts and terminology

The file libgambit/libgambit.h includes all the header files for all classes and functions. To help play nice with other libraries, all classes and functions in libgambit are contained in the namespace Gambit.

The development of much of Gambit occurred during 1994 and 1995. As this predates the formal standardization of the Standard Template Library (and, in fact, C++ itself), as well as other standard libraries for reusable container and similar classes, Gambit has its own implementation of some of these classes. This section outlines those facilities. In the longer term, the goal is to evolve these classes to be more compatible with STL and/or with another standard library, and to possibly migrate fully to such a library. Table 4-1 lists the generic container classes provided by the library.

Table 4-1. Container classes in libgambit

ClassDescription
ArrayA basic bounds-checked array
ListA doubly-linked list
MapA sorted associative container
VectorA mathematical vector
PVectorA singly-partitioned vector
DVectorA doubly-partitioned vector
RectArrayA basic bounds-checked rectangular array
MatrixA mathematical matrix
SquareMatrixA mathematical square matrix

The Array and List classes are the basic generic one-dimensional containers; they have identical interfaces, and as such may be used interchangeably. Thus, List is similar to the STL's list. Array is parallel to STL's vector; note that Gambit reserves Vector to represent mathematical objects of that name (i.e., they are Arrays which have the standard mathematical operations defined on them). The third generic container is Map, which is similar to STL's map, which associates a key to a value.

Note

For historical reasons, and in contrast to STL and indexing conventions in C, C++, Python, and most languages, the List class starts indexing the first element at one, not zero. The Array class defaults to this behavior, but allows any index to be used as the first index. It is planned to migrate the library to using zero-based indexing; therefore, it is recommended to write code as generically as possible, especially using the iterator idioms provided, to make this migration easier.