Tuesday, January 31, 2012

Source code

In case anyone is feeling especially masochistic you can take a look at my source code, hosted at github, and licensed under the GNU GPL. I chose the GPL mostly because this is just a hobby project for me and I don't want anyone using my code in a commercial project without also sharing their code back.

Link to the repository: https://github.com/mghiggins/bgtd

That said, I'm fairly sure no one will ever look at it, so it almost certainly doesn't matter. Really I use github just to let me share development easily across my laptop and my desktop.

Some comments on the source:

  • It's C++. I chose C++ mostly because I know it and it's fast for execution. In an ideal world I'd wrap up the fast stuff in a C++ library and do the legwork using Python, but I didn't take the time to figure out how to do that yet.
  • I develop on a Mac using XCode, so it's got some XCode configuration files also included.
  • It uses boost threads for parallel computing, so needs to be linked against boost libraries.
  • It's reasonably well commented, I think. Mostly so I remember why I did what I did when I look at the code after months away from it.

A simple example to do something interesting:

#include <iostream>
#include "game.h"
#include "strategytdmult.h"
#include "strategypubeval.h"

using namespace std;

int main( int argc, char * argv [] )
    // Player 2.4 strategy, loading saved weights 
    // and benchmark dbs
    strategytdmult s1( "benchmark", "player24" );
    // PubEval strategy
    strategyPubEval s2;
    // initialize game with s1 as the player and 
    // s2 as the opponent with RNG seed 1
    game g( &s1, &s2, 1 ); 
    // step to the end of the game
    // print out the board after the game is over
    // g.winner(): 0 == player, 1 == opponent
    cout << "Winner is " << g.winner() << endl; 
    // score is 1, 2, or 3
    cout << "Winner points = " << g.winnerScore() << endl; 

    return 0;

This example defines a pair of strategies - a Player 2.4 strategy and a PubEval strategy - and plays them against each other for a single (cubeless money) game. When the game is over it prints out the board layout and the result.

This won't actually work for you because the Player 2.4 strategy needs to load its saved weights, and those are in a set of files in my filesystem. It also loads one-sided bearoff databases and an escape probability database (used in the Berliner primes inputs), which are just on my machine. But you get the idea. If anyone does really want to try to compile my code I'd be happy to send you the files you need.

No comments:

Post a Comment