gnubg python scripting: gnubg.findbestmove ()

Let gnubg calculate the best move!

This is the position of the Akasaka regular meeting one day. I was a 4-0 / 5p Crawford in red. How do you move the blue 54? IMG_20160717_131509.jpg

board

First, specify the checker placement in the tuple list. It seems that you should enter the number of checkers at each point in order. The 25th item seems to be the number of on-the-bar checkers.

In [1]: board = ((0, 0, 0, 2, 2, 3, 2, 0, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),
   ...:  (0, 0, 0, 0, 0, 5, 2, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0))

cubeinfo

Specify the length of the match, the score, and whether it is Crawford or not. I don't know gammonprice, so I'll set it to 0 for now.

In [2]: cubeinfo = {'beavers': 0,
   ...:  'bgv': 0,
   ...:  'crawford': 1,
   ...:  'cube': 1,
   ...:  'cubeowner': -1,
   ...:  'gammonprice': ((0.0, 0.0), (0.0, 0.0)),
   ...:  'jacoby': 0,
   ...:  'matchto': 5,
   ...:  'move': 0,
   ...:  'score': (0, 4)}

There is a method called calcgammonprice so you can calculate the gammon price.

In [3]: cubeinfo = gnubg.calcgammonprice(cubeinfo)

In [4]: cubeinfo
Out[4]: 
{'beavers': 0,
 'bgv': 0,
 'crawford': 1,
 'cube': 1,
 'cubeowner': -1,
 'gammonprice': ((0.06355762481689453, 1.1390838623046875), (0.0, 0.0)),
 'jacoby': 0,
 'matchto': 5,
 'move': 0,
 'score': (0, 4)}

posinfo

Specify the outcome and which turn it is.

In [5]: posinfo = {'dice': (5, 4), 'doubled': 0, 'gamestate': 1, 'resigned': 0, 'turn': 0}

gnubgid

I will use it later, so I will make something called gnubgid.

In [6]: gnubgid = gnubg.gnubgid(board, cubeinfo, posinfo)

In [7]: gnubgid
Out[7]: u'2G4cAwTg2wkAKw:sIGyAAAAIAAE'

If you specify gnubgid with the set gnubgid command, you will be in the phase you have set so far.

In [8]: gnubg.command('set gnubgid 2G4cAwTg2wkAKw:sIGyAAAAIAAE')
The dice have been set to 5 and 4.
 GNU Backgammon  Position ID: 4HPwATDgc/ABMA
                 Match ID   : sIGyAAAAIAAE
 +12-11-10--9--8--7-------6--5--4--3--2--1-+     O: gnubg
 | X           O    |   | O              X |0 points
 | X           O    |   | O              X |Roll the dice 54
 | X           O    |   | O                |     
 | X                |   | O                |     
 | X                |   | O                |    
^|                  |BAR|                  |5 point match(Cube: 1)
 | O                |   | X                |    
 | O                |   | X                |     
 | O           X    |   | X                |     
 | O           X    |   | X              O |     
 | O           X    |   | X              O |4 points
 +13-14-15-16-17-18------19-20-21-22-23-24-+     X: mkisono

 GNU Backgammon  Position ID: 2G4cAwTg2wkAKw
                 Match ID   : sIGyAAAAIAAE
 +12-11-10--9--8--7-------6--5--4--3--2--1-+     O: gnubg
 | X     O     O  O |   | O     X          |0 points
 | X           O  O |   | O                |Roll the dice 54
 |             O    |   | O                |     
 |                  |   | O                |     
 |                  |   | O                |    
^|                  |BAR|                  |5 point match(Cube: 1)
 |                  |   |                  |    
 |                  |   |                  |     
 |       X          |   | X                |     
 |       X        X |   | X  X  X  O       |     
 |       X        X |   | X  X  X  O  O  O |4 points
 +13-14-15-16-17-18------19-20-21-22-23-24-+     X: mkisono

Setting GNUbg ID 2G4cAwTg2wkAKw:sIGyAAAAIAAE

findbestmove

Let's finally find out the best move!

In [9]: gnubg.findbestmove()
Out[9]: (10, 5, 8, 4)

10/5, 8/4 * That's right. I can't find any other good move like this. Blots are scattered on the inner, but if you hit red here and take the second anchor, it will look like a back game.

You can use the hint command to get more information.

In [10]: gnubg.hint()
Out[10]: 
{'gnubgid': u'2G4cAwTg2wkAKw:sIGyAAAAIAAE',
 'hint': [{'context': {'cubeful': 1,
    'deterministic': 1,
    'noise': 0.0,
    'plies': 2,
    'prune': 1},
   'details': {'probs': (0.28211891651153564,
     0.03484905883669853,
     0.001164137851446867,
     0.38557541370391846,
     0.0413915291428566),
    'score': -0.4322209358215332},
   'eqdiff': 0.0,
   'equity': -0.4322209358215332,
   'move': '10/5 8/4*',
   'movenum': 1,
   'type': 'eval'},
  {'context': {'cubeful': 1,
    'deterministic': 1,
    'noise': 0.0,
    'plies': 2,
    'prune': 1},
   'details': {'probs': (0.2639846205711365,
     0.03448880836367607,
     0.0010329540818929672,
     0.41944432258605957,
     0.05380573496222496),
    'score': -0.46866169571876526},
   'eqdiff': -0.036440759897232056,
   'equity': -0.46866169571876526,
   'move': '8/4* 8/3',
   'movenum': 2,
   'type': 'eval'},

Articles so far

Recommended Posts

gnubg python scripting: gnubg.findbestmove ()
gnubg python scripting
gnubg python scripting: gnubg.match ()
gnubg python scripting: set threads
Python