--- a/2048.html Thu Sep 18 00:39:41 2014 +0300
+++ b/2048.html Thu Sep 18 01:05:42 2014 +0300
@@ -58,7 +58,7 @@
div.ai.enabled {
background-color: wheat;
}
- div.ai > h5, div.report > h5 {
+ div.ai > h5 {
margin: 2px 0 2px 6em;
}
button.ai {
@@ -90,6 +90,9 @@
#test {
display: none;
}
+ div.report > h5 {
+ margin: 2px 0;
+ }
table.report-by-maxval {
border-collapse: collapse;
margin: 2px;
@@ -266,6 +269,9 @@
<div class="setting"><input type="text" id="stat-count-limit" value="100"> times</div>
<div class="setting">limit to <input type="text" id="stat-time-limit" value="10"> sec</div>
<button id="statistic">Start</button>
+ <div class="setting"><input type="checkbox" id="report-score"/> score</div>
+ <div class="setting"><input type="checkbox" id="report-turn"/> turn</div>
+ <div class="setting"><input type="checkbox" id="report-speed"/> speed</div>
<div class="clearfix"></div>
</div>
<div id="reports">
@@ -730,6 +736,9 @@
if (tsTo - tsLimitFrom >= tsLimit)
break;
}
+ var scoreChecked = document.getElementById('report-score').checked;
+ var turnChecked = document.getElementById('report-turn').checked;
+ var speedChecked = document.getElementById('report-speed').checked;
var histo = {};
for (i = stats.length-1; i >= 0; i--) {
var stat = stats[i];
@@ -737,23 +746,32 @@
histo[stat.max] = { n: 0, minSpeed: Infinity, meanSpeed: 0, maxSpeed: 0, minTurn: Infinity, meanTurn: 0, maxTurn: 0, minScore: Infinity, meanScore: 0, maxScore: 0 };
var row = histo[stat.max];
row.n++;
- var speed = (stat.turn * 1000.0) / stat.ts;
- row.minSpeed = Math.min(row.minSpeed, speed);
- row.meanSpeed += speed;
- row.maxSpeed = Math.max(row.maxSpeed, speed);
- row.minTurn = Math.min(row.minTurn, stat.turn);
- row.meanTurn += stat.turn;
- row.maxTurn = Math.max(row.maxTurn, stat.turn);
- row.minScore = Math.min(row.minScore, stat.score);
- row.meanScore += stat.score;
- row.maxScore = Math.max(row.maxScore, stat.score);
+ if (scoreChecked) {
+ row.minScore = Math.min(row.minScore, stat.score);
+ row.meanScore += stat.score;
+ row.maxScore = Math.max(row.maxScore, stat.score);
+ }
+ if (turnChecked) {
+ row.minTurn = Math.min(row.minTurn, stat.turn);
+ row.meanTurn += stat.turn;
+ row.maxTurn = Math.max(row.maxTurn, stat.turn);
+ }
+ if (speedChecked) {
+ var speed = (stat.turn * 1000.0) / stat.ts;
+ row.minSpeed = Math.min(row.minSpeed, speed);
+ row.meanSpeed += speed;
+ row.maxSpeed = Math.max(row.maxSpeed, speed);
+ }
}
for (var i in histo) {
var row = histo[i];
var n = row.n;
- row.meanSpeed = row.meanSpeed / n;
- row.meanTurn = row.meanTurn / n;
- row.meanScore = row.meanScore / n;
+ if (scoreChecked)
+ row.meanScore = row.meanScore / n;
+ if (turnChecked)
+ row.meanTurn = row.meanTurn / n;
+ if (speedChecked)
+ row.meanSpeed = row.meanSpeed / n;
}
var reportDom = document.createElement('div');
reportDom.classList.add('report');
@@ -766,13 +784,42 @@
var maxVal = maxVals[i];
var row = histo[maxVals[i]];
var perc = parseFloat((100 * row.n / gameCnt).toPrecision(3));
- var meanScore = parseFloat(row.meanScore.toPrecision(3));
- tbl.push([maxVal, row.n, perc, row.minScore, meanScore, row.maxScore]);
+ var tblRow = [maxVal, row.n, perc];
+ if (scoreChecked) {
+ tblRow.push(row.minScore);
+ var meanScore = parseFloat(row.meanScore.toPrecision(3));
+ tblRow.push(meanScore);
+ tblRow.push(row.maxScore);
+ }
+ if (turnChecked) {
+ tblRow.push(row.minTurn);
+ tblRow.push(Math.floor(row.meanTurn));
+ tblRow.push(row.maxTurn);
+ }
+ if (speedChecked) {
+ tblRow.push(parseFloat(row.minSpeed.toPrecision(3)));
+ tblRow.push(parseFloat(row.meanSpeed.toPrecision(3)));
+ tblRow.push(parseFloat(row.maxSpeed.toPrecision(3)));
+ }
+ tbl.push(tblRow);
}
- var tableDom = ui.dom.table(
- tbl,
- ['maxVal', 'n', '%', 'min score', 'mean score', 'max score'],
- { tableClass: 'report-by-maxval' });
+ var tblCols = ['maxVal', 'n', '%'];
+ if (scoreChecked) {
+ tblCols.push('min score');
+ tblCols.push('mean score');
+ tblCols.push('max score');
+ }
+ if (turnChecked) {
+ tblCols.push('min turn');
+ tblCols.push('mean turn');
+ tblCols.push('max turn');
+ }
+ if (speedChecked) {
+ tblCols.push('min speed');
+ tblCols.push('mean speed');
+ tblCols.push('max speed');
+ }
+ var tableDom = ui.dom.table(tbl, tblCols, { tableClass: 'report-by-maxval' });
reportDom.appendChild(tableDom);
reportsDom.insertBefore(reportDom, reportsDom.firstChild);
}