<p id="whiteclock"><a href="javascript:prev_move()"><<<</a></p>
<p id="blackclock"><a href="javascript:next_move()">>>></a></p>
<p id="numviewers"></p>
+ <p id="gamesummary"></p>
</div>
</div>
<div id="analysis">
</tbody>
</table>
</div>
-<p id="rootgame"></p>
<!-- For faster development -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/chessboard-0.3.0.min.js"></script>
width: auto;
text-align: center;
}
+#gamesummary {
+ width: 100%;
+ text-align: center;
+}
#whiteclock {
float: left;
width: 20%;
min-width: 400px;
overflow: hidden;
}
-#rootgame {
- white-space: pre;
- font-family: monospace;
-}
/* If the board is too wide for the screen, shrink it to fit,
* and then put the analysis below. */
var moves = [];
var move_override = 0;
+var entity_map = {
+ "&": "&",
+ "<": "<",
+ ">": ">",
+ '"': '"',
+ "'": ''',
+};
+
+function escape_html(string) {
+ return String(string).replace(/[&<>"']/g, function (s) {
+ return entity_map[s];
+ });
+}
+
var get_game = function() {
var game = new Chess();
for (var i = 0; i < move_override; ++i) {
var show_lines = function(data, game) {
var moves = data['moves'];
$('#numviewers').text(data['opening']);
- $('#rootgame').text(data['root_pgn']);
+
+ if (data['root_game']) {
+ var text = escape_html(data['root_game']['white']);
+ if (data['root_game']['white_elo']) {
+ text += " (" + escape_html(data['root_game']['white_elo']) + ")";
+ }
+ text += " – " + escape_html(data['root_game']['black']);
+ if (data['root_game']['black_elo']) {
+ text += " (" + escape_html(data['root_game']['black_elo']) + ")";
+ }
+ text += " " + escape_html(data['root_game']['result']).replace(/-/, "–") + "<br />";
+ if (data['root_game']['eco']) {
+ text += "[" + escape_html(data['root_game']['eco']) + "] ";
+ }
+ text += "(" + data['root_game']['moves'] + ") ";
+ text += escape_html(data['root_game']['event']) + " " + escape_html(data['root_game']['date']);
+ $('#gamesummary').html(text);
+ }
+
var total_num = 0;
for (var i = 0; i < moves.length; ++i) {
var move = moves[i];
use lib '..';
use Position;
use IPC::Open2;
+use Chess::PGN::Parse;
our %openings = ();
read_openings();
my ($white, $draw, $black, $opening_num, $white_avg_elo, $black_avg_elo, $num_elo, $timestamp, $pgn_file_number, $pgn_start_position, @moves) = split / /, $line;
my $opening = $openings{$opening_num} // 'A00: Start position';
-my $root_pgn;
+my $root_game;
eval {
die "Missing PGN position data." if (!defined($pgn_file_number) || !defined($pgn_start_position));
- $root_pgn = read_root_pgn($pgn_file_number, $pgn_start_position);
+ my $pgntext = read_root_pgn($pgn_file_number, $pgn_start_position);
+ my $pgn = Chess::PGN::Parse->new(undef, $pgntext);
+ $pgn->read_game() or die;
+ $pgn->parse_game() or die;
+
+ my $tags = $pgn->tags;
+ $root_game = {};
+ $root_game->{'white'} = $pgn->white;
+ $root_game->{'white_elo'} = $tags->{'WhiteElo'};
+ $root_game->{'black'} = $pgn->black;
+ $root_game->{'black_elo'} = $tags->{'BlackElo'};
+ $root_game->{'event'} = $pgn->event;
+ $root_game->{'date'} = $pgn->date;
+ $root_game->{'result'} = $pgn->result;
+ $root_game->{'eco'} = $pgn->eco;
+ $root_game->{'moves'} = scalar @{$pgn->moves};
};
-if ($@) {
- $root_pgn = "Could not find root PGN. ($@)";
-}
# Explore one move out.
my @json_moves = ();
}
print $cgi->header(-type=>'application/json');
-print JSON::XS::encode_json({ moves => \@json_moves, opening => $opening, root_pgn => $root_pgn });
+print JSON::XS::encode_json({ moves => \@json_moves, opening => $opening, root_game => $root_game });
sub num {
my $x = shift;