226 </div> |
226 </div> |
227 |
227 |
228 <div id="report-area" class="area"> |
228 <div id="report-area" class="area"> |
229 <h1>Reports</h1> |
229 <h1>Reports</h1> |
230 <div class="settings"> |
230 <div class="settings"> |
231 <div class="setting"><input type="text" id="count-limit" value="10"> times</div> |
231 <div class="setting"><input type="text" id="stat-count-limit" value="10"> times</div> |
232 <div class="setting">limit to <input type="text" id="time-limit" value="10"> sec</div> |
232 <div class="setting">limit to <input type="text" id="stat-time-limit" value="10"> sec</div> |
233 <button id="statistic">Start</button> |
233 <button id="statistic">Start</button> |
234 <div class="clearfix"></div> |
234 <div class="clearfix"></div> |
235 </div> |
235 </div> |
236 <div class="report"> |
236 <div class="report"> |
237 <div class="name">next max score</div> |
237 <div class="name">next max score</div> |
627 |
627 |
628 //////////////////////////////////////////////////////////////// |
628 //////////////////////////////////////////////////////////////// |
629 // Reports and statistic. |
629 // Reports and statistic. |
630 |
630 |
631 function statistic() { |
631 function statistic() { |
632 |
632 console.log('xxx'); |
|
633 var stat = []; |
|
634 var cnt = parseInt(document.getElementById('stat-count-limit').value); |
|
635 if (isNaN(cnt) || !isFinite(cnt) || cnt < 1) |
|
636 cnt = 100; |
|
637 var tsLimit = parseFloat(document.getElementById('stat-count-limit').value); |
|
638 if (isNaN(tsLimit) || !isFinite(tsLimit) || tsLimit < 1 || tsLimit > 60) |
|
639 tsLimit = 1000 * 10; |
|
640 else |
|
641 tsLimit = 1000 * tsLimit; |
|
642 var tmpBrd = board.create(); |
|
643 var tsFrom = new Date().getTime(); |
|
644 for (var i = 0; i < cnt; i++) { |
|
645 var turn = 0; |
|
646 var brd = board.create(); |
|
647 board.putRandom(brd); |
|
648 while (!board.gameOver(brd)) { |
|
649 board.copy(brd, tmpBrd); |
|
650 var move = ui.ai.current.analyse(tmpBrd); |
|
651 if (ui.game.dirs.indexOf(move) < 0) { |
|
652 ui.game.setMessage("I don't know how to move!"); |
|
653 return; |
|
654 } |
|
655 var updated = board.move[move].call(null, brd); |
|
656 if (!updated) { |
|
657 ui.game.setMessage("Wrong move!"); |
|
658 return; |
|
659 } |
|
660 board.putRandom(brd); |
|
661 turn++; |
|
662 } |
|
663 var tsTo = new Date().getTime(); |
|
664 stat.push(board.score(brd)); |
|
665 if (tsTo - tsFrom >= tsLimit) |
|
666 break; |
|
667 } |
|
668 console.log(stat); |
633 } |
669 } |
634 |
670 |
635 var statisticBtn = document.getElementById('statistic'); |
671 var statisticBtn = document.getElementById('statistic'); |
636 statisticBtn.addEventListener("click", statistic); |
672 statisticBtn.addEventListener("click", statistic); |
637 |
673 |