On 28/06/2013 3:56 PM, Backgammon Melbourne wrote: > Hi > > Where can I find help/advice/examplesof how to create bots and clients > that use the gnubg code for analysis, board rendering etc. >
If you are creating bots that only need to ask the question "Give me the best play (cube or move) for a given FIBS position" without need for full analysis data then I would suggest GNUBG's external interface. About the only thing it doesn't handle is analysing resignations. If you know anything about Perl there is a project by Guido Flohr that created a FIBS compatible server with bots simulating players. He uses the external socket interface. https://www.ohloh.net/p/baldlies . You can use git to retrieve the source or browse the source code in your browser. There is a thread on the GNUBG mailing list about the external interface here: http://lists.gnu.org/archive/html/bug-gnubg/2008-02/msg00046.html Whatever you do make sure player names don't contain spaces. The other approach people have taken is to forgo Python and the external socket interface, launch gnubg from another application, redirect stdin/stdout and then feed commands directly and parse the output. I know one bot developer who did that, and things broke one time when the output changed slightly. As for using GNUBG to render a board (embedding) it definitely isn't suited for that. Most people who end up putting a new front end on GNUBG end up building a GUI-less variant of GNUBG with core functionality and then create wrappers to existing functions so that their own GUI can interact with GNUBG's core internals. > We'll be using python and perhaps C. > I use the Python interface a fair amount and there are some limitations (that I am currently looking to rectify). The Python interface has one key thing lacking and that is a "hint" and "getanalysis" feature that retruns back a Python object (data structure.) The only way to get complete hint information for a given GNUBGID is for the Python code to redirect GNUBG's own output to a file, parse it and then return back a Python data structure representing the data (which I have had to d in the past). Of course if the output ever changes then the parsing has to change, and you have to be careful about language settings. I recently committed a change to the regular hint code in GNUBG to support external access (ie from Python) that returns such a structure without all the intermediate steps. I just didn't put away a Python based hint command, I am currently still working on it. I may release an incomplete (but functional version) today. At the moment my new unreleased code allows one to do this (Not for cube, but for checker play at present). gnubg.command ('set gnubgid %s' % ('6d0kBgBaq7MBAA:UQlnABAAEAAE')) data = gnubg.hint(-1); The data structure returned will look something like: [{'context': {'cubeful': 1, 'deterministic': 1, 'noise': 0.0, 'plies': 2, 'prune': 1}, 'eqdiff': 0.0, 'equity': -0.2894556522369385, 'move': '11/5 7/6', 'movenum': 1, 'type': 'eval'}, {'context': {'cubeful': 1, 'deterministic': 1, 'noise': 0.0, 'plies': 2, 'prune': 1}, 'eqdiff': -0.0007007122039794922, 'equity': -0.29015636444091797, 'move': '10/4 7/6', 'movenum': 2, 'type': 'eval'}, [snip] {'context': {'cubeful': 1, 'deterministic': 1, 'noise': 0.0, 'plies': 0, 'prune': 1}, 'eqdiff': -0.0489192008972168, 'equity': -0.3383748531341553, 'move': '7/1 2/1', 'movenum': 33, 'type': 'eval'}] The -1 as a parameter says to dump all the possibilities and their equities (in this case there were 33). You could in theory use such a mechanism to take an arbitrary GNUBGID (set gnubgid command also accepts XGIDs) and get the complete hint data to be used by a Python program. At some point I want a getanalysis function that returns a similar structure for a position that may have already been analysed. One thing to note about GNUBG's Python interface - in order for it to work you need to run GNUBG and use the embedded interpreter that accesses the GNUBG internals. You can access it at the terminal by using a ">" by itself on the GNUGB command line or by using the -p parameter to launch GNUBG with a python script to execute. You can't run a python program outside of GNUBG and then hope to do "import gnubg" and have the functionality present. The embedded Python directly interfaces with GNUBG's internals as it runs. To get some help on the existing Python module and functions, using gnubg-cli.exe on Windows (or gnubg -t on *nix) you can issue this command in the interactive interpreter: help(gnubg) That displays all the functions in the gnubg module and their help. You can get help on a specific function like this: help(gnubg.evaluate) help(gnubg.gnubgid) etc. The python scripts (batch.py for example) that come with GNUBG can also give you an idea and examples of usage. -- Michael Petch GNU Backgammon Maintainer / Developer OpenPGP FingerPrint=D81C 6A0D 987E 7DA5 3219 6715 466A 2ACE 5CAE 3304 _______________________________________________ Bug-gnubg mailing list Bug-gnubg@gnu.org https://lists.gnu.org/mailman/listinfo/bug-gnubg