2048.html
changeset 130 28694f058ea4
parent 129 e0958e521716
child 131 02d7eb74bfe5
equal deleted inserted replaced
129:e0958e521716 130:28694f058ea4
   281     <h1>Reports</h1>
   281     <h1>Reports</h1>
   282     <div class="control">
   282     <div class="control">
   283       <div class="option">up to <input type="text" id="stat-count-limit" value="100"> times</div>
   283       <div class="option">up to <input type="text" id="stat-count-limit" value="100"> times</div>
   284       <div class="option">up to <input type="text" id="stat-time-limit" value="10"> sec</div>
   284       <div class="option">up to <input type="text" id="stat-time-limit" value="10"> sec</div>
   285       <button id="statistic-start">Start</button>
   285       <button id="statistic-start">Start</button>
       
   286       <button id="statistic-stop">Stop</button>
   286       <button id="statistic-clean">Clean</button>
   287       <button id="statistic-clean">Clean</button>
   287       <div class="option"><input type="checkbox" id="report-score"/> score</div>
   288       <div class="option"><input type="checkbox" id="report-score"/> score</div>
   288       <div class="option"><input type="checkbox" id="report-turn"/> turn</div>
   289       <div class="option"><input type="checkbox" id="report-turn"/> turn</div>
   289       <div class="option"><input type="checkbox" id="report-speed"/> speed</div>
   290       <div class="option"><input type="checkbox" id="report-speed"/> speed</div>
   290     </div>
   291     </div>
   887       var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) });
   888       var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) });
   888       reportDom.appendChild(tableDom);
   889       reportDom.appendChild(tableDom);
   889       reportsDom.insertBefore(reportDom, reportsDom.firstChild);
   890       reportsDom.insertBefore(reportDom, reportsDom.firstChild);
   890     }
   891     }
   891     ui.report.start = function() {
   892     ui.report.start = function() {
       
   893       ui.report.executed = true;
   892       var histo = {};
   894       var histo = {};
   893       var gameCntLimit = parseInt(document.getElementById('stat-count-limit').value);
   895       var gameCntLimit = parseInt(document.getElementById('stat-count-limit').value);
   894       if (isNaN(gameCntLimit) || !isFinite(gameCntLimit) || gameCntLimit < 1)
   896       if (isNaN(gameCntLimit) || !isFinite(gameCntLimit) || gameCntLimit < 1)
   895         gameCntLimit = 100;
   897         gameCntLimit = 100;
   896       var tsLimit = parseFloat(document.getElementById('stat-count-limit').value);
   898       var tsLimit = parseFloat(document.getElementById('stat-count-limit').value);
   924       }
   926       }
   925       var gameCnt = 0;
   927       var gameCnt = 0;
   926       var tsFrom = new Date().getTime(), tsFrame = tsFrom;
   928       var tsFrom = new Date().getTime(), tsFrame = tsFrom;
   927       function batch() {
   929       function batch() {
   928         /* console.profile(); */
   930         /* console.profile(); */
   929         while (gameCnt++ < gameCntLimit) {
   931         while (gameCnt++ < gameCntLimit && ui.report.executed) {
   930           play();
   932           play();
   931           var tsTo = new Date().getTime();
   933           var tsTo = new Date().getTime();
   932           if (tsTo - tsFrame > 7000) {
   934           if (tsTo - tsFrame > 7000) {
   933             tsFrame = tsTo;
   935             tsFrame = tsTo;
   934             break;
   936             break;
   935           }
   937           }
   936           if (tsTo - tsFrom >= tsLimit)
   938           if (tsTo - tsFrom >= tsLimit)
   937             break;
   939             break;
   938         }
   940         }
   939         /* console.profileEnd(); */
   941         /* console.profileEnd(); */
   940         if (tsTo - tsFrom >= tsLimit || gameCnt >= gameCntLimit) {
   942         if (tsTo - tsFrom >= tsLimit || gameCnt >= gameCntLimit || ! ui.report.executed) {
   941           ui.report.fix(histo);
   943           ui.report.fix(histo);
   942           ui.report.show(histo, gameCnt);
   944           ui.report.show(histo, gameCnt);
   943         } else {
   945         } else {
   944           setTimeout(batch, 10);
   946           setTimeout(batch, 10);
   945         }
   947         }
   946       }
   948       }
   947       batch();
   949       batch();
   948     }
   950     }
   949     var statisticStartBtn = document.getElementById("statistic-start");
   951     var statisticStartBtn = document.getElementById("statistic-start");
   950     statisticStartBtn.addEventListener("click", ui.report.start, false);
   952     statisticStartBtn.addEventListener("click", ui.report.start, false);
       
   953 
       
   954     ui.report.stop = function() {
       
   955       ui.report.executed = false;
       
   956     }
       
   957     var statisticStopBtn = document.getElementById("statistic-stop");
       
   958     statisticStopBtn.addEventListener("click", ui.report.stop, false);
   951 
   959 
   952     ui.report.clean = function() {
   960     ui.report.clean = function() {
   953       while (reportsDom.hasChildNodes()) {
   961       while (reportsDom.hasChildNodes()) {
   954         reportsDom.removeChild(reportsDom.lastChild);
   962         reportsDom.removeChild(reportsDom.lastChild);
   955       }
   963       }