Node:Scripting, Next:, Previous:Training, Up:Top



Scripting

Accessing gnubg Python shell

To access the Python shell, either type > from the command line or select Windows->Python Shell(IDLE...) from the GUI.

gnubg module functions

board()

command(cmd)

evaluate()

evalcontext()

eq2mwc()

mwc2eq()

cubeinfo()

met()

positionid()

positionfromid()

positionkey()

positionfromkey()

positionbearoff()

positionfrombearoff()

navigate([next=N,[game=N]])
Match navigation.

Without any arguments, go to first move of first match.

With next == N, move forward N game records.

With game == N, move forward/backward N games.

Navigate never wraps around.

On success, returns None. If unable to complete the requsted number of moves, returns a pair of (next-remaining,game-remaining).

match([analysis=1/0, boards=1/0, statistics=0/1, verbose=0/1])
Return the current match. For example,
          > m = gnubg.match()
          

Takes the following optional keyword arguments:

analysis
When 0, discard analysis data. default is 1.
boards
When 1, add current board to move/double records. Default is 1.
statistics
When 1, include game and match statistics. Default is 0.
verbose
When 1, include derived analysis values. Default is 0.

Match description

gnubg.match() returns a dictionary containing the following items:

match-info
General match info. match-info
games
A sequence, one elemet per game. game
stats (optional)
Match statistics.

Match info

A dictionary containing the following items:

match-length

variation
One of Standard,Nackgammon, Hypergammon1, Hypergammon2 or Hypergammon3.
rules (optional)
Additional rules used. A subset of NoCube, Crawford and Jacoby.
X
O
Per player information. Each a dictionary containing rating and name.
annotator (optional)

round (optional)

place (optional)

date (optional)
Sequence of (Day,Month,Year).
event (optional)

default-eval-context
Default evaluation context. A dictionary in the same format as returned by evalcontext().
default-rollout-context
Default rollout context.

Example,

     >>> m['match-info']
     {'match-length': 25, 'rules': ('Crawford',), 'default-eval-context': {'plies': 2, 'deterministic': 1, 'reduced': 0, 'noise': 0.0, 'cubeful': 1}, 'annotator': 'GNU 0.14', 'O': {'rating': '0 (Exp 0)', 'name': 'Moshe Tissona'}, 'round': 'Final', 'place': 'Monte Carlo', 'variation': 'Standard', 'default-rollout-context': {'n-truncation': 11, 'initial-position': 0, 'trials': 0, 'stop-on-std': 0, 'variance-reduction': 1, 'late-eval': 0, 'truncated-rollouts': 0, 'truncate-bearoff2': 1, 'cubeful': 1, 'truncate-bearoffOS': 1, 'seed': 1177750272, 'quasi-random-dice': 1, 'minimum-games': 144}, 'date': (13, 7, 2003), 'X': {'rating': '0 (Exp 0)', 'name': 'Jon Royset'}, 'event': 'World Championship 2003'}
     

Python game

A dictionary containing the following items:

info
General game info. For example,
          >>> m['games'][0]['info']
          {'points-won': 1, 'score-X': 0, 'score-O': 0, 'winner': 'X', 'resigned': False}
          

If no winner is specified, winner is None.

          >>> m['games'][2]['info']
          {'score-X': 2, 'winner': None, 'score-O': 0}
          

game
A Sequence of actions. actions
stats (optional)
Game statistics. Similar entries to Analyse->Game statistics from the GUI.

Game actions

Each action is a dictionary