bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnubg] Python support ?


From: Joern Thyssen
Subject: Re: [Bug-gnubg] Python support ?
Date: Sat, 12 Jul 2003 18:14:33 +0000
User-agent: Mutt/1.4.1i

On Sat, Jul 12, 2003 at 05:52:13PM +0200, Øystein Johansen wrote
> Hi Jørn,
> 
> Can you tell us something about the new Python support? 

So far it is quite experimental.

On unix it should be detected automagically by configure. You should add
the following to config.h:

/* Define if you want to use Python inside gnubg */
#define USE_PYTHON 1

you should add -I/path/to/Python.h and link with libpython.a (or
whatever it's called on windows). I had to add -Wl,--export-dynamic to
the link options -- this may be linux specific, though.

> Maybe a little example?

Python runs in the terminal window so it will probably only work with
gnubg-nogui.exe so far, or ...?!

I don't know how familar you're with python. I think it started as a
language used for computer science education. At least that's how I came
across it the first time 7 or 8 years ago. It's quite easy to learn,
and it's quite powerful due to a number of built-in complex objects,
such as dictionaries (see cubeinfo and evalcontext below), tuples (see
gnubg.board()) below), and lists (see gnubg.evaluate() below). You can
read a lot more on www.python.org.

Anyway, the escape to python is >

Here's an example:

address@hidden gnubg-head2 410]$ gnubg -t
(No game) >
>>> print 1+1
2
>>> [Ctrl+D]
(No game)

Another example:
(No game) >
>>> gnubg.command("new match")
A new 7 point match has been started.
...
>>> a=gnubg.board()
>>> print a
[[0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0], [0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 2, 0]]
>>> b=gnubg.cubeinfo()
>>> print b
{'jacoby': 0, 'crawford': 0, 'move': 1, 'beavers': 0, 'cube': 1,
'matchto': 7, 'bgv': 0, 'cubeowner': -1, 'score': (0, 0), 'gammonprice':
((1.07432603836, 1.17227435112), (1.07432603836, 1.17227470875))}
>>> print b['cube']
1
>>> c=gnubg.evalcontext()
>>> print c
{'cubeful': 0, 'reduced': 0, 'noise': 0.0, 'deterministic': 1, 'plies':
0}
>>> c['cubeful']=1; c['plies']=2
>>> print c
{'cubeful': 1, 'reduced': 0, 'noise': 0.0, 'deterministic': 1, 'plies':
2}
>>> d=gnubg.evaluate(a,b,c)
>>> print d
[0.46673476696, 0.122495755553, 0.00271528656594, 0.123958788812,
0.00467116478831, -0.0703950673342, 0.493532717228]
>>> print gnubg.mwc2eq(d[6])
-0.104854889214
>>> dir(gnubg)
['__doc__', '__name__', 'board', 'command', 'cubeinfo', 'eq2mwc',
'evalcontext', 'evaluate', 'met', 'mwc2eq']
>>> [Ctrl+D]

As you can see from the "dir(gnubg)" command, I've only implemented very
few functions. A lot more need to be added, but it's quite trivial to do
so. Many of the functions will take optional arguments.

Here's a more interesting example (you need gnubgmodule.c 1.2 for this
to work!):

row=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
b={ 'jacoby': 0, 'move': 1, 'beavers': 0, 'cube': 1, 'matchto': 0, 'bgv' : 0, 
'cubeowner': -1, 'gammonprice': ((1,1),(1,1))}
c=gnubg.evalcontext()
c['cubeful']=1; c['plies']=2

for i in range(1,16):
   a=[row[0:],row[0:]]
   a[0][0]=i
   a[1][0]=i
   output=gnubg.evaluate(a,b,c)
   print i, output[6]

The result from running this script is:

1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 1.0
7 0.916670501232
8 0.916670501232
9 0.726787209511
10 0.726851701736
11 0.588584542274
12 0.611079871655
13 0.539436817169
14 0.538699746132
15 0.482966423035

That is, the cube centered money equities for bearoff positions n
chequers versus n chequers.

You can see that is going to be very powerful once all the relevant
functions have been interfaced to python.

Jørn




reply via email to

[Prev in Thread] Current Thread [Next in Thread]