2010年4月9日金曜日

Support in gnubg.

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
I wrote a patch and sent to gnubg-ml.
diff --git a/backgammon.h b/backgammon.h
index 0860daa..ddaaeea 100644
--- a/backgammon.h
+++ b/backgammon.h
@@ -588,6 +588,7 @@ extern void CommandExportMatchPDF(char *);
 extern void CommandExportMatchPS(char *);
 extern void CommandExportMatchText(char *);
 extern void CommandExportPositionGammOnLine(char *);
+extern void CommandExportPositionBGbase2Clipboard(char *);
 extern void CommandExportPositionGOL2Clipboard(char *);
 extern void CommandExportPositionHtml(char *);
 extern void CommandExportPositionJF(char *);
diff --git a/commands.inc b/commands.inc
index 6ca89a5..a0cf6e1 100644
--- a/commands.inc
+++ b/commands.inc
@@ -211,6 +211,10 @@ command cER = {
       N_("Save the current position in .html format "
          "(special for GammOnLine)"), 
       szFILENAME, &cFilename },
+    { "backgammonbase2clipboard", CommandExportPositionBGbase2Clipboard,
+      N_("Save the current position in html img tag fragment to clipboard"
+         "(special for Backgammonbase)"), 
+      szFILENAME, &cFilename },
     { "gol2clipboard", CommandExportPositionGOL2Clipboard,
       N_("Copy the current position in .html format to clipboard"
          "(special for GammOnLine)"), 
diff --git a/gtkgame.c b/gtkgame.c
index ae4c81a..7b5844d 100644
--- a/gtkgame.c
+++ b/gtkgame.c
@@ -1212,6 +1212,13 @@ static void NewClicked(gpointer  p, guint n, GtkWidget * pw)
        GTKNew();
 }
 
+static void CopyAsBGbase(gpointer p, guint n, GtkWidget * pw)
+{
+
+       UserCommand("export position backgammonbase2clipboard");
+
+}
+
 static void CopyAsGOL(gpointer p, guint n, GtkWidget * pw)
 {
 
@@ -2964,6 +2971,8 @@ GtkItemFactoryEntry aife[] = {
          CommandCopy, 0, NULL, NULL },
        { N_("/_Edit/Copy as/GammOnLine (HTML)"), NULL,
          CopyAsGOL, 0, NULL, NULL },
+       { N_("/_Edit/Copy as/Backgammonbase.com (url)"), NULL,
+         CopyAsBGbase, 0, NULL, NULL },
 
        { N_("/_Edit/_Paste Position ID"), "V", PasteIDs, 0,
                "", GTK_STOCK_PASTE},
@@ -5242,6 +5251,7 @@ extern void GTKProgressValue ( int iValue, int iMax )
     gdouble frac = 1.0 * iValue / (1.0 * iMax );
     gsz = g_strdup_printf("%d/%d (%.0f%%)", iValue, iMax, 100 * frac);
     gtk_progress_bar_set_text( GTK_PROGRESS_BAR( pwProgress ), gsz);
+    printf("%d, %d, %f\n", iValue, iMax, frac);
     gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( pwProgress ), frac);
     g_free(gsz);
 
diff --git a/html.c b/html.c
index a52b80b..6a17cbc 100644
--- a/html.c
+++ b/html.c
@@ -3654,7 +3654,6 @@ extern void CommandExportPositionGammOnLine ( char *sz ) {
 
 }
 
-
 extern void CommandExportPositionGOL2Clipboard( char *sz )
 {
     char *szClipboard;
@@ -3711,3 +3710,118 @@ extern void CommandExportPositionGOL2Clipboard( char *sz )
     g_free(tmpFile);
 }
 
+/* 
+ * UGH! FIXME
+ *  find handy urlencode function to import.
+ * 
+ */
+static void
+furlencode(FILE* pf, const char * to_encode)
+{
+   int i = 0;
+   unsigned char c;
+   while ( c = to_encode[i++] ) {
+           if( (c >= '0' && c <= '9')
+           ||  (c >= 'A' && c <= 'Z')
+           ||  (c >= 'a' && c <= 'z')
+           ||  (c == '-')
+           ||  (c == '.')
+           ||  (c == '_') )
+               fprintf(pf, "%c", c);
+           else if( c == ' ' )
+               fprintf(pf, "+");
+           else
+               fprintf(pf, "%%%02X", c);
+   }
+}
+
+
+/*
+ * Print URL of position image
+ *  i.e. http://image.backgammonbase.com/image?gnubgid=4HPwATDgc%2FABMA%3AMAAAAAAAAAAA&height=300&width=400&css=minimal&format=png 
+ *
+ * Input:
+ *   pf: output file
+ *   ms: current match state
+ *
+ */
+
+static void
+ExportPositionBGbase( FILE *pf )
+{
+    int fHistory;
+    int iMove;
+    moverecord *pmr = get_current_moverecord ( &fHistory );
+    const matchstate *pms = &ms;
+    printf("ExportPositionBGbase() \n");
+
+    if (!pmr)
+    {
+           outputerrf(_("Unable to export this position"));
+           return;
+    }
+
+    fprintf(pf, "http://image.backgammonbase.com/image?gnubgid=");
+    furlencode(pf, PositionID ( (ConstTanBoard)pms->anBoard ));
+    fprintf(pf, ":");
+    furlencode(pf, MatchIDFromMatchState ( pms ));
+    fprintf(pf, "&height=300&width=400&css=nature&format=png");
+}
+
+
+extern void CommandExportPositionBGbase2Clipboard(char *sz)
+{
+    char *szClipboard;
+    long l;
+       FILE *pf;
+       char *tmpFile;
+
+    if( ms.gs == GAME_NONE ) {
+      outputl( _("No game in progress (type `new game' to start one).") );
+      return;
+    }
+    
+    /* get tmp file */
+
+       pf = GetTemporaryFile(NULL, &tmpFile);
+
+    /* generate file */
+
+    ExportPositionBGbase( pf );
+
+    /* find size of file */
+
+    if ( fseek( pf, 0L, SEEK_END ) ) {
+      outputerr( "temporary file" );
+      return;
+    }
+
+    l = ftell( pf );
+
+    if ( fseek( pf, 0L, SEEK_SET ) ) {
+      outputerr( "temporary file" );
+      return;
+    }
+
+    /* copy file to clipboard */
+
+    szClipboard = (char *) malloc ( l + 1 );
+
+    if (fread( szClipboard, 1, l, pf ) != (unsigned long) l)
+    {
+           outputerr("temporary file");
+           free(szClipboard);
+           fclose(pf);
+    }
+
+    szClipboard[ l ] = 0;
+
+    TextToClipboard( szClipboard );
+
+    free( szClipboard );
+
+    fclose( pf );
+    g_unlink(tmpFile);
+    g_free(tmpFile);
+}
+

2010年1月26日火曜日

idea

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
  • 基本・要素機能系
    • move.api.backgammonbase.comを拡張して対戦に必要な機能をそろえる。
    • mouse clickからmoveを生成する。
    • pointにあるチェッカーの数を変更する(edit機能)
    • cubeの位置、スコア、手番をeditする機能
    • double/take/pass/beaver
    • resign 1, 2, 3/accept
    • roll dice XX

  • mat file viewer
    • mat fileの中身をdiv内にcopy and pasteすると棋譜鑑賞するgadgetを実行でき

  • image.backgammonbase.comに飛んできたrequestにあるpositionを表示するpageを作る。
    • ほかの人がどんなpositionを調べているかを見る機能。

    • server側でrefererを見る。

  • 対戦サーバ
    • cometサーバとライブラリ

    • lobbyの管理アプリ

    • 対戦管理(出目の生成)

    • トーナメント管理アプリ

  • マッシュアップ
    • Facebook

    • mixi

    • ???

  • 研究ツール
    • position database

    • web越しのgnubg操作

2010年1月23日土曜日

Dynamically Loading CSS using Javascript

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
I needed to load CSS via Javascript, to make blog parts.

The main idea is a making link element with Javascript. But it is not enough, since css is not always ready when control is back. So, I put some code which prefetches css using ajax. After successful loading of css, it makes a link element for css, then it calls setTimeout to make sure css is applied to DOM.


function loadCSS(src, delay, onload, error){
$.ajax({
type: "GET",
url: src,
dataType: 'text',
success: function(data, dataType){
debug('inserting ' + src);
var link = $('<link rel="stylesheet" type="text/css" href="'+ src+ '" />');
$("head").append(link);
setTimeout(function(){
onload();
},
delay);
},
'error': error,
});
};

$(document).ready(function(){
loadCSS('some url of css', 1,
function(){
debug('do some thing using dynamically loaded css.');
},
function (XMLHttpRequest, testStatus, errorThrown){
debug('css load failed');
});

test

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
These are test cases for blog parts at Blogger.com.

4PPgAQPgc+QBIg:cAl7AAAAAAAA



Position ID: sGfwgAPbOIMDIA
Match ID: cAkxAAAAAAAA
1. Cubeful 2-ply 24/22 13/9 Eq.: -0.151
0.425 0.125 0.005 - 0.575 0.192 0.009
2-ply cubeful prune [world class]
2. Cubeful 2-ply 8/4 6/4 Eq.: -0.208 ( -0.057)
0.396 0.133 0.006 - 0.604 0.204 0.015
2-ply cubeful prune [world class]



Position ID: bbcLACC02zYEAA
Match ID: QQm2AZAASAAA
1. Rollout 13/8 5/1* Eq.: +0.8791
0.8922 0.0812 0.0043 - 0.1078 0.0096 0.0009 CL +0.9252 CF +0.8791
[0.0054 0.0055 0.0014 - 0.0054 0.0042 0.0007 CL 0.0148 CF 0.0166]
Full cubeful rollout with var.redn.
150 games, Mersenne Twister dice gen. with seed 717406193 and quasi-random dice
Play: world class 2-ply cubeful prune [world class]
keep the first 0 0-ply moves and up to 8 more moves within equity 0.16
Skip pruning for 1-ply moves.
Cube: 2-ply cubeful prune [world class]
2. Rollout 13/4 Eq.: +0.8026 ( -0.0765)
0.8893 0.0431 0.0012 - 0.1107 0.0072 0.0003 CL +0.8472 CF +0.8026
[0.0035 0.0039 0.0008 - 0.0035 0.0012 0.0003 CL 0.0110 CF 0.0130]
Full cubeful rollout with var.redn.
146 games, Mersenne Twister dice gen. with seed 717406193 and quasi-random dice
Play: world class 2-ply cubeful prune [world class]
keep the first 0 0-ply moves and up to 8 more moves within equity 0.16
Skip pruning for 1-ply moves.
Cube: 2-ply cubeful prune [world class]


2009年12月10日木曜日

time to debug server part

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
Now server is able to send updated position ids to clients.

Out:


Hover: (image is swapped to position after move of row)

2009年12月9日水曜日

Handling Hover

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
I was confused with var/scoping of JavaScript.
Now, my scripts handles hover over move list to swap board images.

2009年12月7日月曜日

API for make_move JSONP

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
This is very first edition.


- How to envoke via JSONP
use "make_move" for callback.
i.e. in jQuery,
$.ajax({
url : "http://api.backgammonbase.com/jsonp",
dataType : "jsonp",
cache : true,
jsonp : "make_move",
... snip ...
});

other parameters:
-- gnubgid
give Poisition ID + Match ID, i.e.
example: "jHPDAQXgPHgBWA:UQkyAQAAAAAA"

-- move text
give moves in text.
example: "bar/21 24/20 8/4 8/4"
use "bar" for bar, not "25" or "b"
use "off" for off. not "0" or "o"

- return values

example:

giving parameters
{
gnubgid: "jHPDAQXgPHgBWA:UQkyAQAAAAAA",
move: "bar/21 24/20 8/4 8/4"
}

U gets
{
status: true,
gnubgid: "jHPDAQXgPHgBWA:UQkyAQAAAAAA"
}

error handling is T.B.D.