631 |
631 |
632 //////////////////////////////////////////////////////////////// |
632 //////////////////////////////////////////////////////////////// |
633 // Reports and statistic. |
633 // Reports and statistic. |
634 |
634 |
635 function statistic() { |
635 function statistic() { |
636 var stat = []; |
636 var stats = []; |
637 var cnt = parseInt(document.getElementById('stat-count-limit').value); |
637 var cnt = parseInt(document.getElementById('stat-count-limit').value); |
638 if (isNaN(cnt) || !isFinite(cnt) || cnt < 1) |
638 if (isNaN(cnt) || !isFinite(cnt) || cnt < 1) |
639 cnt = 100; |
639 cnt = 100; |
640 var tsLimit = parseFloat(document.getElementById('stat-count-limit').value); |
640 var tsLimit = parseFloat(document.getElementById('stat-count-limit').value); |
641 if (isNaN(tsLimit) || !isFinite(tsLimit) || tsLimit < 1 || tsLimit > 60) |
641 if (isNaN(tsLimit) || !isFinite(tsLimit) || tsLimit < 1 || tsLimit > 60) |
642 tsLimit = 1000 * 10; |
642 tsLimit = 1000 * 10; |
643 else |
643 else |
644 tsLimit = 1000 * tsLimit; |
644 tsLimit = 1000 * tsLimit; |
645 var safeBdr = board.create(); |
645 var safeBdr = board.create(); |
646 var tsFrom = new Date().getTime(); |
646 var tsLimitFrom = new Date().getTime(); |
647 for (var i = 0; i < cnt; i++) { |
647 for (var i = 0; i < cnt; i++) { |
648 var turn = 0; |
648 var turn = 0; |
649 var brd = board.create(); |
649 var brd = board.create(); |
650 board.putRandom(brd); |
650 board.putRandom(brd); |
|
651 var tsFrom = new Date().getTime(); |
651 while (!board.gameOver(brd)) { |
652 while (!board.gameOver(brd)) { |
652 board.copy(brd, safeBdr); |
653 board.copy(brd, safeBdr); |
653 var move = ui.ai.current.analyse(safeBdr); |
654 var move = ui.ai.current.analyse(safeBdr); |
654 if (ui.game.dirs.indexOf(move) < 0) { |
655 if (ui.game.dirs.indexOf(move) < 0) { |
655 ui.game.setMessage("I don't know how to move!"); |
656 ui.game.setMessage("I don't know how to move!"); |
662 } |
663 } |
663 board.putRandom(brd); |
664 board.putRandom(brd); |
664 turn++; |
665 turn++; |
665 } |
666 } |
666 var tsTo = new Date().getTime(); |
667 var tsTo = new Date().getTime(); |
667 stat.push(board.score(brd)); |
668 var stat = board.score(brd); |
668 if (tsTo - tsFrom >= tsLimit) |
669 stat.turn = turn; |
|
670 stat.ts = tsTo - tsFrom; |
|
671 stats.push(stat); |
|
672 if (tsTo - tsLimitFrom >= tsLimit) |
669 break; |
673 break; |
670 } |
674 } |
671 console.log(stat); |
675 console.log(stats); |
672 } |
676 } |
673 |
677 |
674 var statisticBtn = document.getElementById('statistic'); |
678 var statisticBtn = document.getElementById('statistic'); |
675 statisticBtn.addEventListener("click", statistic, false); |
679 statisticBtn.addEventListener("click", statistic, false); |
676 |
680 |