This file is indexed.

/usr/share/gnubg/scripts/matchseries.py is in gnubg-data 1.04.000-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# matchseries.py
#
# Martin Janke <lists@janke.net>, 2004
# Achim Mueller <ace@gnubg.org>, 2004
# Joern Thyssen <jth@gnubg.org>, 2004
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Play an arbitray number of matches.
#
# For example, the script could be used to play gnubg 0-ply using
# the Snowie MET against gnubg 0-ply using the Woolsey-Heinrich MET.
# This is achieved by using the external player interface.
#
# gnubg -t << EOF
# set matchequitytable "met/snowie.xml"
# set evaluation chequerplay eval plies 0
# set evaluation cubed eval plies 0
# external localhost:10000
# EOF
#
# gnubg -t << EOF
# set matchequitytable "met/woolsey.xml"
# set player 1 gnu
# set player 1 chequerplay evaluation plies 0
# set player 1 cubedecision evaluation plies 0
# set player 0 external localhost:10000
# >
# from matchseries import *
# playMatchSeries (matchLength = 3, noOfMatches = 1000,
#                  statsFile = "statistics.txt", sgfBasePath = None,
#                  matBasePath = None)
# EOF
#
# $Id: matchseries.py,v 1.5 2014/08/08 04:50:26 mdpetch Exp $
#

import gnubg


def playMatchSeries(statsFile=None,  # log file
                    matchLength=7,
                    noOfMatches=100,
                    sgfBasePath=None,  # optional
                    matBasePath=None):  # optional
    """Starts noOfMatches matchLength pointers. For every match
    the running score, gammoms (g) and backgammons (b) and the match winner
    is written to 'statsFile':
    g       gammon
    b       backgammon
    (g)     gammon, but not relevsnt (end of match)
    (b)     backgammon, but not relevant
    g(b)    backgammon, but gammon would have been enough to win the match

    If the optional parameters 'sgfBasePath' and 'matBasePath' are set to a
    path, the matches are saved as sgf or mat file."""

    for i in range(0, noOfMatches):

        if not statsFile:
            raise ValueError('Parameter "statsFile" is mandatory')

        gnubg.command('new match ' + str(matchLength))

        matchInfo = formatMatchInfo(gnubg.match(analysis=0, boards=0))

        f = open(statsFile, 'a')
        f.write(matchInfo)
        f.close

        if sgfBasePath:
            gnubg.command('save match ' + sgfBasePath +
                          str(i) + '.sgf')
        if matBasePath:
            gnubg.command('export match mat ' + matBasePath +
                          str(i) + '.mat')


def formatMatchInfo(matchInfo):
    tempS = ''
    outString = ''
    score = [0, 0]
    matchLength = matchInfo['match-info']['match-length']

    for game in matchInfo['games']:
        pw = game['info']['points-won']
        if game['info']['winner'] == 'O':
            winner = 1
        else:
            winner = 0
        oldScore = score[winner]
        score[winner] += pw

        cube = getCube(game)
        print ('cube: ', cube)

        if pw == cube:
            gammon = ''
        elif pw == 2 * cube:
            gammon = 'g'
            if (cube + oldScore) >= matchLength:  # gammon not relevant
                gammon = '(g)'

        elif pw == 3 * cube:
            gammon = 'b'

            if (cube + oldScore) >= matchLength:  # backgammon not relevant
                gammon = '(b)'
            elif (2 * cube + oldScore) >= matchLength:
                # backgammon not relevant, but gammon
                gammon = 'g(b)'

        outString += ',%d:%d%s' % (score[0], score[1], gammon)

    outString = str(winner) + outString + '\n'

    return outString


def getCube(game):
    """returns the cube value of the game"""
    doubled = 0
    cube = 1
    for turn in game['game']:
        if turn['action'] == 'double':
            doubled = 1
            continue

        if doubled:
            if turn['action'] == 'take':
                cube *= 2
                doubled = 0
            else:  # dropped
                break
    return cube