Make engine URL, move source and similar values dynamic instead of hard-coding them...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 Jun 2015 00:10:55 +0000 (02:10 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 28 Jun 2015 00:11:11 +0000 (02:11 +0200)
Also change 'id' to 'engine' in a long-standing cleanup, and remove the unused author information.

config.pm
remoteglot.pl
www/css/remoteglot.css
www/index.html
www/js/remoteglot.js

index 3a57206..77fa74e 100644 (file)
--- a/config.pm
+++ b/config.pm
@@ -66,6 +66,12 @@ our @masters = (
 # you probably need specific prior permission to use this.
 our $tb_serial_key = undef;
 
 # you probably need specific prior permission to use this.
 our $tb_serial_key = undef;
 
+# Credits to show in the footer.
+our $engine_url = "http://www.stockfishchess.org/";
+our $engine_details = undef;  # For hardware.
+our $move_source = "FICS";
+our $move_source_url = "http://www.freechess.org/";
+
 # Postgres configuration.
 our $dbistr = "dbi:Pg:dbname=remoteglot";
 our $dbiuser = undef;
 # Postgres configuration.
 our $dbistr = "dbi:Pg:dbname=remoteglot";
 our $dbiuser = undef;
index 5a5d4c5..d4a0d73 100755 (executable)
@@ -482,10 +482,9 @@ sub parse_ids {
        my ($engine, @x) = @_;
 
        while (scalar @x > 0) {
        my ($engine, @x) = @_;
 
        while (scalar @x > 0) {
-               if ($x[0] =~ /^(name|author)$/) {
-                       my $key = shift @x;
+               if ($x[0] eq 'name') {
                        my $value = join(' ', @x);
                        my $value = join(' ', @x);
-                       $engine->{'id'}{$key} = $value;
+                       $engine->{'id'}{'author'} = $value;
                        last;
                }
 
                        last;
                }
 
@@ -738,10 +737,23 @@ sub output_json {
 
        my $json = {};
        $json->{'position'} = $pos_calculating->to_json_hash();
 
        my $json = {};
        $json->{'position'} = $pos_calculating->to_json_hash();
-       $json->{'id'} = $engine->{'id'};
+       $json->{'engine'} = $engine->{'id'};
+       if (defined($remoteglotconf::engine_url)) {
+               $json->{'engine'}{'url'} = $remoteglotconf::engine_url;
+       }
+       if (defined($remoteglotconf::engine_details)) {
+               $json->{'engine'}{'details'} = $remoteglotconf::engine_details;
+       }
+       if (defined($remoteglotconf::move_source)) {
+               $json->{'move_source'} = $remoteglotconf::move_source;
+       }
+       if (defined($remoteglotconf::move_source_url)) {
+               $json->{'move_source_url'} = $remoteglotconf::move_source_url;
+       }
        $json->{'score'} = long_score($info, $pos_calculating, '');
        $json->{'short_score'} = short_score($info, $pos_calculating, '');
        $json->{'plot_score'} = plot_score($info, $pos_calculating, '');
        $json->{'score'} = long_score($info, $pos_calculating, '');
        $json->{'short_score'} = short_score($info, $pos_calculating, '');
        $json->{'plot_score'} = plot_score($info, $pos_calculating, '');
+       $json->{'using_lomonosov'} = defined($remoteglotconf::tb_serial_key);
 
        $json->{'nodes'} = $info->{'nodes'};
        $json->{'nps'} = $info->{'nps'};
 
        $json->{'nodes'} = $info->{'nodes'};
        $json->{'nps'} = $info->{'nps'};
@@ -875,7 +887,7 @@ sub output_json {
                my $new_depth = $json->{'depth'} // 0;
                my $new_nodes = $json->{'nodes'} // 0;
                if (!defined($old_engine) ||
                my $new_depth = $json->{'depth'} // 0;
                my $new_nodes = $json->{'nodes'} // 0;
                if (!defined($old_engine) ||
-                   $old_engine ne $json->{'id'}{'name'} ||
+                   $old_engine ne $json->{'engine'}{'name'} ||
                    $new_depth > $old_depth ||
                    ($new_depth == $old_depth && $new_nodes >= $old_nodes)) {
                        atomic_set_contents($filename, $encoded);
                    $new_depth > $old_depth ||
                    ($new_depth == $old_depth && $new_nodes >= $old_nodes)) {
                        atomic_set_contents($filename, $encoded);
@@ -884,7 +896,7 @@ sub output_json {
                                $dbh->do('DELETE FROM scores WHERE id=?', undef, $id);
                                $dbh->do('INSERT INTO scores (id, plot_score, short_score, engine, depth, nodes) VALUES (?,?,?,?,?,?)', undef,
                                        $id, $json->{'plot_score'}, $json->{'short_score'},
                                $dbh->do('DELETE FROM scores WHERE id=?', undef, $id);
                                $dbh->do('INSERT INTO scores (id, plot_score, short_score, engine, depth, nodes) VALUES (?,?,?,?,?,?)', undef,
                                        $id, $json->{'plot_score'}, $json->{'short_score'},
-                                       $json->{'id'}{'name'}, $new_depth, $new_nodes);
+                                       $json->{'engine'}{'name'}, $new_depth, $new_nodes);
                                $dbh->commit;
                        }
                }
                                $dbh->commit;
                        }
                }
index 21a3a85..09b6b08 100644 (file)
@@ -178,6 +178,9 @@ a.move:hover {
 #linenav {
        display: none;
 }
 #linenav {
        display: none;
 }
+#lomonosov {
+       display: none;
+}
 
 #games {
        font-size: smaller;
 
 #games {
        font-size: smaller;
index 3c1eb85..72b017e 100644 (file)
 </ul>
 <p id="credits"><a href="http://git.sesse.net/?p=remoteglot;a=summary">remoteglot</a>
   &copy; 2007&ndash;2015 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.
 </ul>
 <p id="credits"><a href="http://git.sesse.net/?p=remoteglot;a=summary">remoteglot</a>
   &copy; 2007&ndash;2015 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.
-  Chess analysis by <a href="http://stockfishchess.org/" id="engineid">Stockfish</a> (main analysis: 20x2.3GHz Haswell-EP,
-  multi-PV search: 16x2.4GHz Haswell-EP).
-  Moves provided by <a href="http://live.fide.com/sochi/">FIDE</a>.
-  Hosting and multi-PV analysis hardware by <a href="http://www.samfundet.no/">Studentersamfundet i Trondhjem</a>.
+  Chess analysis by <a href="http://stockfishchess.org/" id="engineid">Stockfish</a><span id="enginedetails"></span>.
+  <span id="movesource"></span>
+  Hosting and additional analysis hardware by <a href="http://www.samfundet.no/">Studentersamfundet i Trondhjem</a>.
   JavaScript chessboard powered by <a href="http://chessboardjs.com/">chessboard.js</a>
   and <a href="https://github.com/jhlywa/chess.js">chess.js</a>.
   Ding sound by <a href="https://www.freesound.org/people/Aiwha/sounds/196106/">Aiwha</a> (CC-BY-3.0).
   JavaScript chessboard powered by <a href="http://chessboardjs.com/">chessboard.js</a>
   and <a href="https://github.com/jhlywa/chess.js">chess.js</a>.
   Ding sound by <a href="https://www.freesound.org/people/Aiwha/sounds/196106/">Aiwha</a> (CC-BY-3.0).
-  7-man Lomonosov tablebase lookup by <a href="http://tb7.chessok.com/">ChessOK</a>.</p>
+  <span id="lomonosov">7-man Lomonosov tablebase lookup by <a href="http://tb7.chessok.com/">ChessOK</a>.</span></p>
 
 <!-- For faster development -->
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 
 <!-- For faster development -->
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
index 0462252..673fd12 100644 (file)
@@ -771,6 +771,50 @@ var update_board = function(current_data, display_data) {
                headline = 'Analysis';
        }
 
                headline = 'Analysis';
        }
 
+       // Credits, where applicable. Note that we don't want the footer to change a lot
+       // when e.g. viewing history, so if any of these changed during the game,
+       // use the current one still.
+       if (current_data['using_lomonosov']) {
+               $("#lomonosov").show();
+       } else {
+               $("#lomonosov").hide();
+       }
+
+       // Credits: The engine name/version.
+       if (current_data['engine'] && current_data['engine']['name'] !== null) {
+               $("#engineid").text(current_data['engine']['name']);
+       }
+
+       // Credits: The engine URL.
+       if (current_data['engine'] && current_data['engine']['url']) {
+               $("#engineid").attr("href", current_data['engine']['url']);
+       } else {
+               $("#engineid").removeAttr("href");
+       }
+
+       // Credits: Engine details.
+       if (current_data['engine'] && current_data['engine']['details']) {
+               $("#enginedetails").text(" (" + current_data['engine']['details'] + ")");
+       } else {
+               $("#enginedetails").text("");
+       }
+
+       // Credits: Move source, possibly with URL.
+       if (current_data['move_source'] && current_data['move_source_url']) {
+               $("#movesource").text("Moves provided by ");
+               var movesource_a = document.createElement("a");
+               movesource_a.setAttribute("href", current_data['move_source_url']);
+               var movesource_text = document.createTextNode(current_data['move_source']);
+               movesource_a.appendChild(movesource_text);
+               var movesource_period = document.createTextNode(".");
+               document.getElementById("movesource").appendChild(movesource_a);
+               document.getElementById("movesource").appendChild(movesource_period);
+       } else if (current_data['move_source']) {
+               $("#movesource").text("Moves provided by " + current_data['move_source'] + ".");
+       } else {
+               $("#movesource").text("");
+       }
+
        var last_move;
        if (display_data) {
                // Displaying some non-current position, pick out the last move
        var last_move;
        if (display_data) {
                // Displaying some non-current position, pick out the last move
@@ -839,11 +883,6 @@ var update_board = function(current_data, display_data) {
 
        update_clock();
 
 
        update_clock();
 
-       // The engine id.
-       if (data['id'] && data['id']['name'] !== null) {
-               $("#engineid").text(data['id']['name']);
-       }
-
        // The score.
        if (data['score'] !== null) {
                $("#score").text(data['score']);
        // The score.
        if (data['score'] !== null) {
                $("#score").text(data['score']);