[ View Thread ] [ Post Response ] [ Return to Index ] [ Read Prev Msg ] [ Read Next Msg ]

BGonline.org Forums

Let's learn more from all the data

Posted By: Michael Petch
Date: Wednesday, 18 March 2015, at 5:58 p.m.

In Response To: Let's learn more from all the data (Jason Lee)

As Keene pointed out the XG File Format was published some time ago
(2013/early 2014). I was reverse engineering the XG format and Xavier kindly
provided a document to me that I used to develop some Python code to
decompress and then parse the data. After finding some discrepancies in
Xavier's document he amended it to a point where I was able to parse all
the fields (and for each version of the file format).

The Python code really isn't a proper library yet. It was a proof of concept
to determine if the XG file format specification could be used to produce
a 3rd party library.

A git repository of the Python code can be found here.
A ZIP file snapshot of the latest code as of this posting can be retrieved
here

I know that someone successfully used the Python codes output to generate
MAT files from XG files. Although I didn't intend for it to be used that
way, it apparently can be done.

In 2014 I was approached by a number of individuals to produce a Java library.
The license is LGPL which means it can be used in proprietary/commercial code.
If you change the library then you need to make the modified library's
source available.

The Java code doesn't compute PRs or generate XGIDs but if someone wishes
to contribute back to the project I'd be happy to integrate that code
I do know of one individual who was able to compute the PRs
in their own project

I sent this email to the Java developers to get them started:

You had previously inquired about Java code to read an XG file format. I
had been too busy to work on this until this past weekend This Java code
is designed for Java 1.6 and higher. Although with some tweaking it
could be used on Java 1.5. This code will read and extract all the data
from an XG file including Rollouts, GameFile, Index, and Comments.

You can access it via my official GIT repository here via the web (You
can download a snapshot of the source code as a zip file via the web
interface):

http://vcs.capp-sysware.com/gitweb/?p=backgammon/xgdatatoolsjava.git;a=summary

If you have git you can clone via:

git clone http://vcs.capp-sysware.com/git/backgammon/xgdatatoolsjava.git

An executable copy of a jar file containing all the dependencies can be
found here:

http://www.capp-sysware.com/downloads/misc/xgdatatools-0.1.2-SNAPSHOT-jar-with-dependencies.jar

To run it you should just be able to execute with something like:

java -jar xgdatatools-0.1.2-SNAPSHOT-jar-with-dependencies.jar filename.xg

Where filename.xg is the name of a file to import from. The main class
for the jar simply Imports all the data from a specified file and pretty
prints it out to standard output.

Although I use Maven to package, one doesn't need maven to compile the
code. It can easily be imported into Eclipse (or Netbeans etc).

What is required is a copy of Apache Commons Lang v3+ on your class
path. See http://commons.apache.org/proper/commons-lang/ . The only
reason this is needed is to help pretty print the data structures. One
could modify the code (all the toString() functions to use Java's own
ToStringBuilder to remove this dependency)

Although there is no documentation I recommend taking a quick look at
com.cappsysware.xg.XGTestImport . You simply create a new XGFile object
passing in the file name to read. You then use theses methods on the
XGFile object.

getGameIndexFile() temp.xgi in the archive (index)
getGameFile() temp.xg in the archive (main game file)
getRolloutFile() temp.xgr in the archive (rollout file)
getCommentFile() temp.xgc in the archive (comment file)

Each of these objects has one method in particular that is of most use:

getListOfRecords()

This will return all the records from the file and return them as a List.

To get all the game file records from a file called neil.xg one could do
something like:

List xgFile = new
XGFile("neil.xg").getGameFile().getListOfRecords();

GameFileRecord is an abstract class that the different subclasses of
game file records inherit from.

There is also some sample code in the source tree The field names are
similar (for the post part) to Xavier's
xg_format.pas file.

Messages In This Thread

 

Post Response

Your Name:
Your E-Mail Address:
Subject:
Message:

If necessary, enter your password below:

Password:

 

 

[ View Thread ] [ Post Response ] [ Return to Index ] [ Read Prev Msg ] [ Read Next Msg ]

BGonline.org Forums is maintained by Stick with WebBBS 5.12.