303 divDom.classList.add("clearfix"); |
303 divDom.classList.add("clearfix"); |
304 return divDom; |
304 return divDom; |
305 } |
305 } |
306 ui.dom.table = function(tbl, cols, cfg) { |
306 ui.dom.table = function(tbl, cols, cfg) { |
307 var tableDom = document.createElement('table'); |
307 var tableDom = document.createElement('table'); |
308 if (typeof cfg.tableClass === 'string') |
308 if (typeof cfg.tblClass === 'string') |
309 tableDom.classList.add(cfg.tableClass); |
309 tableDom.classList.add(cfg.tblClass); |
|
310 if (typeof cfg.tblTitle === 'string') |
|
311 tableDom.title = cfg.tblTitle; |
310 var trDom = document.createElement('tr'); |
312 var trDom = document.createElement('tr'); |
311 for (var i = 0; i < cols.length; i++) { |
313 for (var i = 0; i < cols.length; i++) { |
312 var thDom = document.createElement('td'); |
314 var thDom = document.createElement('td'); |
313 thDom.appendChild(document.createTextNode(cols[i])); |
315 thDom.appendChild(document.createTextNode(cols[i])); |
314 trDom.appendChild(thDom); |
316 trDom.appendChild(thDom); |
688 // Register AIs. |
690 // Register AIs. |
689 |
691 |
690 ui.ai = {}; |
692 ui.ai = {}; |
691 ui.ai.current = null; |
693 ui.ai.current = null; |
692 ui.ai.parseCfg = function(aiDom, cfg) { |
694 ui.ai.parseCfg = function(aiDom, cfg) { |
|
695 cfg = cfg || {}; |
693 var optDoms = aiDom.querySelectorAll("div.option > input.positive[type='text']"); |
696 var optDoms = aiDom.querySelectorAll("div.option > input.positive[type='text']"); |
694 for (var i = 0; i < optDoms.length; i++) { |
697 for (var i = 0; i < optDoms.length; i++) { |
695 var val = parseFloat(optDoms[i].value); |
698 var val = parseFloat(optDoms[i].value); |
696 if (val === NaN || val < 0) { |
699 if (val === NaN || val < 0) { |
697 ui.game.setMessage('' + optDoms[i].name + ' is not a positive number!'); |
700 ui.game.setMessage('' + optDoms[i].name + ' is not a positive number!'); |
698 cfg[optDoms[i].name] = 1; |
701 cfg[optDoms[i].name] = 1; |
699 continue; |
702 continue; |
700 } |
703 } |
701 cfg[optDoms[i].name] = val; |
704 cfg[optDoms[i].name] = val; |
702 } |
705 } |
|
706 return cfg; |
|
707 } |
|
708 ui.ai.cfgTitle = function(aiName) { |
|
709 var title = JSON.stringify(ui.ai.parseCfg(document.getElementById(aiName))).replace(":", ": ", "g").replace(",", "\n", "g"); |
|
710 title = title.substr(1); |
|
711 title = title.substr(0, title.length-1); |
|
712 return title; |
703 } |
713 } |
704 |
714 |
705 ui.ai.algList = { |
715 ui.ai.algList = { |
706 "ai-blind-random": function() { |
716 "ai-blind-random": function() { |
707 return new ai.BlindRandom(ui.brdEngine); |
717 return new ai.BlindRandom(ui.brdEngine); |
708 }, |
718 }, |
709 "ai-blind-weight-random": function(aiDom) { |
719 "ai-blind-weight-random": function(aiDom) { |
710 var cfg = {}; |
720 var cfg = ui.ai.parseCfg(aiDom); |
711 ui.ai.parseCfg(aiDom, cfg); |
|
712 return new ai.BlindWeightRandom(ui.brdEngine, cfg); |
721 return new ai.BlindWeightRandom(ui.brdEngine, cfg); |
713 }, |
722 }, |
714 "ai-blind-cycle": function(aiDom) { |
723 "ai-blind-cycle": function(aiDom) { |
715 var cfg = {}; |
724 var cfg = {}; |
716 cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked; |
725 cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked; |
717 cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked; |
726 cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked; |
718 return new ai.BlindCycle(ui.brdEngine, cfg); |
727 return new ai.BlindCycle(ui.brdEngine, cfg); |
719 }, |
728 }, |
720 "ai-one-step-ahead": function(aiDom) { |
729 "ai-one-step-ahead": function(aiDom) { |
721 var cfg = {}; |
730 var cfg = ui.ai.parseCfg(aiDom); |
722 ui.ai.parseCfg(aiDom, cfg); |
|
723 return new ai.OneStepAhead(ui.brdEngine, cfg); |
731 return new ai.OneStepAhead(ui.brdEngine, cfg); |
724 }, |
732 }, |
725 "ai-deep-max-score": function() { |
733 "ai-deep-max-score": function() { |
726 return new ai.DeepMaxScore(ui.brdEngine); |
734 return new ai.DeepMaxScore(ui.brdEngine); |
727 }, |
735 }, |
728 "ai-deep-max-score-corner": function() { |
736 "ai-deep-max-score-corner": function() { |
729 return new ai.DeepMaxScoreCorner(ui.brdEngine); |
737 return new ai.DeepMaxScoreCorner(ui.brdEngine); |
730 }, |
738 }, |
731 "ai-expectimax": function(aiDom) { |
739 "ai-expectimax": function(aiDom) { |
732 var cfg = {}; |
740 var cfg = ui.ai.parseCfg(aiDom); |
733 ui.ai.parseCfg(aiDom, cfg); |
|
734 return new ai.expectimax(ui.brdEngine, cfg); |
741 return new ai.expectimax(ui.brdEngine, cfg); |
735 }, |
742 }, |
736 // "": function() { |
743 // "": function() { |
737 // return new ai.(ui.brdEngine); |
744 // return new ai.(ui.brdEngine); |
738 // }, |
745 // }, |
891 if (speedChecked) { |
898 if (speedChecked) { |
892 tblCols.push('min speed'); |
899 tblCols.push('min speed'); |
893 tblCols.push('mean speed'); |
900 tblCols.push('mean speed'); |
894 tblCols.push('max speed'); |
901 tblCols.push('max speed'); |
895 } |
902 } |
896 var tableDom = ui.dom.table(tbl, tblCols, { tableClass: 'report-by-maxval' }); |
903 var tableDom = ui.dom.table(tbl, tblCols, { tblClass: 'report-by-maxval', tblTitle: ui.ai.cfgTitle(ui.ai.currentName) }); |
897 reportDom.appendChild(tableDom); |
904 reportDom.appendChild(tableDom); |
898 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
905 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
899 } |
906 } |
900 var statisticBtn = document.getElementById('statistic'); |
907 var statisticBtn = document.getElementById('statistic'); |
901 statisticBtn.addEventListener("click", ui.report.stat, false); |
908 statisticBtn.addEventListener("click", ui.report.stat, false); |