Gnubg Hints
Using a SQLite Database III
by ace on Aug.05, 2008, under Backgammon, Gnubg Hints
What about getting a terminal output like this?
No Length Result Luck_Adjusted FIBS Snowie Date ------ ------- ------- ------------- ------- ------- ---------- 1 1 1.0 79.68 1802.4 2.99 2008-08-04 2 1 0.0 51.06 1719.1 3.67 2008-08-04 3 1 0.0 37.48 1975.4 0.58 2008-08-04 4 3 1.0 56.9 1912.7 3.27 2008-08-04 5 3 0.0 52.47 2014.2 0.54 2008-08-04 6 3 1.0 68.69 1853.1 6.35 2008-08-04 7 3 0.0 59.16 1980.8 1.79 2008-08-04 8 1 1.0 51.58 1864.5 2.56 2008-08-04 9 1 0.0 35.92 1455.7 8.35 2008-08-04 10 1 1.0 56.21 1967.7 0.89 2008-08-04 Result secret_player (2): 165.0 win(s) in 276 matches. Snowie error rate: 3.68
Unfortunately for the moment this is only possible on MacOS or Unix/Linux systems. I provided a script "query_player.sh" which allows you to query your database using search patterns. A script call could be:
#: query_player.sh goodguy
and the script would give you an output like shown above. Perhaps someone with deeper MSWindows knowledge is able to convert the script. You can find it either in the repository of GNU Backgammon or here (be careful, the content may change from time to time and will not always work perfectly).
There are two adjustment you have to make:
# Put the path to your database here:
DATABASE=/Users/good_player/.gnubg/gnubg.db
...
# only for getting your number of games correctly, usually you have the id 1 or 2.
if [ ${NAME_ID_RESULT} = 2 ]
then PLAYER_ID="player_id1"
else PLAYER_ID="player_id0"
fi
[Update]
The script now works with error rates and names of opponents. Output is slightly different to the table above.
Using a SQLite Database II
by ace on Aug.04, 2008, under Backgammon, Gnubg Hints
In the first part I showed some general information about the sqlite database in GNU Backgammon. We now start some useful queries:
sqlite> select a.session_id as No, b.length as Length, a.actual_result+0.5 as Result, round(a.luck_adjusted_result*100,2) as Luck_Adjusted, round(a.snowie_error_rate_per_move*1000,2) as Snowie, date(b.added) as Date from matchstat a, session b where a.session_id = b.session_id and a.player_id = 2 group by a.session_id limit 10;
No Length Result Luck_Adjusted Snowie Date ------ ------- ---------- ------------- ---------- ------------ 1 1 1.0 29.68 2.99 2008-08-04 2 1 0.0 1.06 3.67 2008-08-04 3 1 0.0 -12.52 0.58 2008-08-04 4 3 1.0 6.9 3.27 2008-08-04 5 3 0.0 2.47 0.54 2008-08-04 6 3 1.0 18.69 6.35 2008-08-04 7 3 0.0 9.16 1.79 2008-08-04 8 1 1.0 1.58 2.56 2008-08-04 9 1 0.0 -14.08 8.35 2008-08-04 10 1 1.0 6.21 0.89 2008-08-04
Explanations:
| round(…*100,2) | = | change output into percentages, round up and restrict number to 2 digits after decimal point |
| round(…*1000,2) | = | round up and restrict number to 2 digits after decimal point |
| date(…) | = | print only the date, not hours, minutes and seconds |
| limit 10 | = | restrict the output to the first ten lines |
A more sophisticated query with nicer output could be the following:
sqlite>select a.session_id as No, b.length as Length, round(a.actual_result+0.5) as Result, round(50+a.luck_adjusted_result*100,2) as Luck_Adjusted, round(a.error_based_fibs_rating,1) as FIBS, round(a.snowie_error_rate_per_move*1000,2) as Snowie, date(b.added) as Date from matchstat a, session b where a.session_id = b.session_id and a.player_id = 2 group by a.session_id;
No Length Result Luck_Adjusted FIBS Snowie Date ------- -------- -------- ------------- ------- -------- ---------- 267 1 0.0 53.53 1947.8 0.52 2008-08-04 268 1 1.0 44.78 1691.9 4.01 2008-08-04 269 1 1.0 37.92 1491.0 6.2 2008-08-04 270 1 1.0 49.63 1726.4 4.45 2008-08-04 271 1 1.0 58.7 1720.4 4.34 2008-08-04 272 3 1.0 36.64 1883.4 4.01 2008-08-04 273 1 1.0 67.96 1878.3 2.16 2008-08-04 274 1 1.0 57.63 1888.9 1.92 2008-08-04 275 1 1.0 61.18 1861.5 2.61 2008-08-04 276 3 1.0 57.31 1883.9 4.54 2008-08-04
Using a SQLite Database I
by ace on Aug.04, 2008, under Backgammon, Gnubg Hints
GNU Backgammon provides relational database support. Besides mysql and postgresql the standard database is sqlite. After the installation of gnubg you’ll find the database file in your home directory (~/.gnubg/gnubg.db on Linux and MacOS). You find the menu entry for using the database in "Analyze" – "Relational Database".
Besides getting information by the GUI of gnubg you can also put queries directly into the database. I’ll describe some important stuff for terminal usage here. If you work on MSWindows systems either get a sqlite browser or the Firefox Addon "Sqlite Manager."
In a terminal you start sqlite with:
#: sqlite .gnubg/gnubg.db (or wherever your database is located sqlite>Loading resources from /Users/ace/.sqliterc SQLite version 3.4.0 Enter ".help" for instructions sqlite>
Important sqlite commands:
| sqlite>.help | = | show help |
| sqlite>.tables | = | show tables |
| sqlite>.headers ON|OFF | = | set table headers on|off |
| sqlite>.mode | = | set output mode |
| sqlite>.exit | = | exit program |
Gnubg stores all data into five tables (actually there is a 6th table called "control", but forget about that for now):
- game
- gamestat
- matchstat
- player
- session
sqlite>.mode line sqlite> select * from player limit 1; player_id = 73 name = cdforex notes = sqlite> select * from game limit 1; game_id = 1 session_id = 1 player_id0 = 1 player_id1 = 2 score_0 = 0 score_1 = 0 result = 1 added = 02:00:22 game_number = 1 crawford = 0 sqlite> select * from session limit 1; session_id = 80 checksum = 112f66856248c6b6a6b0f211071b5d3d player_id0 = 73 player_id1 = 74 result = 0 length = 1 added = 2008-08-04 05:50:07 rating0 = NULL rating1 = NULL event = NULL round = NULL place = NULL annotator = NULL comment = NULL date = 2008-04-01
".mode" and "limit 1" are only set for displaying it here on the webpage more conveniently. The other three tables look similar but with much more rows:
game: game_id session_id player_id0 player_id1 score_0 score_1 result added game_number crawford
gamestat: gamestat_id game_id player_id total_moves unforced_moves unmarked_moves good_moves doubtful_moves bad_moves very_bad_moves chequer_error_total_normalised chequer_error_total chequer_error_per_move_normalised chequer_error_per_move chequer_rating very_lucky_rolls lucky_rolls unmarked_rolls unlucky_rolls very_unlucky_rolls luck_total_normalised luck_total luck_per_move_normalised luck_per_move luck_rating total_cube_decisions close_cube_decisions doubles takes passes missed_doubles_below_cp missed_doubles_above_cp wrong_doubles_below_dp wrong_doubles_above_tg wrong_takes wrong_passes error_missed_doubles_below_cp_normalised error_missed_doubles_above_cp_normalised error_wrong_doubles_below_dp_normalised error_wrong_doubles_above_tg_normalised error_wrong_takes_normalised error_wrong_passes_normalised error_missed_doubles_below_cp error_missed_doubles_above_cp error_wrong_doubles_below_dp error_wrong_doubles_above_tg error_wrong_takes error_wrong_passes cube_error_total_normalised cube_error_total cube_error_per_move_normalised cube_error_per_move cube_rating overall_error_total_normalised overall_error_total overall_error_per_move_normalised overall_error_per_move overall_rating actual_result luck_adjusted_result snowie_moves snowie_error_rate_per_move luck_based_fibs_rating_diff error_based_fibs_rating chequer_rating_loss cube_rating_loss actual_advantage actual_advantage_ci luck_adjusted_advantage luck_adjusted_advantage_ci time_penalties time_penalty_loss_normalised time_penalty_loss
matchstat: matchstat_id session_id player_id total_moves unforced_moves unmarked_moves good_moves doubtful_moves bad_moves very_bad_moves chequer_error_total_normalised chequer_error_total chequer_error_per_move_normalised chequer_error_per_move chequer_rating very_lucky_rolls lucky_rolls unmarked_rolls unlucky_rolls very_unlucky_rolls luck_total_normalised luck_total luck_per_move_normalised luck_per_move luck_rating total_cube_decisions close_cube_decisions doubles takes passes missed_doubles_below_cp missed_doubles_above_cp wrong_doubles_below_dp wrong_doubles_above_tg wrong_takes wrong_passes error_missed_doubles_below_cp_normalised error_missed_doubles_above_cp_normalised error_wrong_doubles_below_dp_normalised error_wrong_doubles_above_tg_normalised error_wrong_takes_normalised error_wrong_passes_normalised error_missed_doubles_below_cp error_missed_doubles_above_cp error_wrong_doubles_below_dp error_wrong_doubles_above_tg error_wrong_takes error_wrong_passes cube_error_total_normalised cube_error_total cube_error_per_move_normalised cube_error_per_move cube_rating overall_error_total_normalised overall_error_total overall_error_per_move_normalised overall_error_per_move overall_rating actual_result luck_adjusted_result snowie_moves snowie_error_rate_per_move luck_based_fibs_rating_diff error_based_fibs_rating chequer_rating_loss cube_rating_loss actual_advantage actual_advantage_ci luck_adjusted_advantage luck_adjusted_advantage_ci time_penalties time_penalty_loss_normalised time_penalty_loss
A simple query could now be:
sqlite> select * from player where name = "ace"; player_id name notes ---------- ---------- ---------- 12 ace
And now you have one of the most important information about a player, his "player_id" which is necessary for further queries. It’s also possible to deliver a search string:
sqlite> select * from player where name like "%ace%"; player_id name notes ---------- ---------- ---------- 12 ace 26 Acepoint
As you can see the search is not case sensitive.
Batch Rollouts
by ace on Jul.27, 2008, under Backgammon, Gnubg Hints
If you want gnubg doing some batch rollouts you can prepare a file like:
set gnubg Position ID ... rollout =cube export position html filename.html set gnubg Position ID ... hint rollout =1 =2 =3 export position html filename.htm ... and start gnubg with the following command: #: gnubg -t -c [file].txt
Set Position
by ace on Jul.25, 2008, under Backgammon, Gnubg Hints
Command line
Setup a position:
set board simple 0 2 4 2 2 3 0 0 -1 0 0 0 0 0 1 0 -2 0 -2 -2 -3 -3 1 0 -1 1
| 0 | bottom players checker on the bar | |
| 2 4 2 2 3 0 | bottom players homeboard | |
| 0 -1 0 0 0 0 | bottom players outer board | |
| 0 1 0 -2 0 -2 | top players outer board | |
| -2 -3 -3 1 0 -1 | top players homeboard | |
| 1 | top players checker on the bar |
GNU Backgammon Position ID: cbcZIEB72wEECA Match ID : cAngAAAAAAAA +13-14-15-16-17-18------19-20-21-22-23-24-+ O: gnubg | X O O | O | O O O X O | 0 points | O O | | O O O | | | | O O | | | | | | | | | | |BAR| | 7 point match (Cube: 1) | | | | | | | X | | | | X X | | | | X X X X X | On roll | O | | X X X X X | 0 points +12-11-10--9--8--7-------6--5--4--3--2--1-+ X: ace