Parse checkbox AI config automatically.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 20 Sep 2014 23:47:48 +0300
changeset 103 54dfc3b4e7d3
parent 102 6c057ac86c97
child 104 47d42234dd5c
Parse checkbox AI config automatically.
2048.html
--- a/2048.html	Sat Sep 20 23:41:36 2014 +0300
+++ b/2048.html	Sat Sep 20 23:47:48 2014 +0300
@@ -703,6 +703,10 @@
         }
         cfg[optDoms[i].name] = val;
       }
+      var optDoms = aiDom.querySelectorAll("div.option > input[type='checkbox']");
+      for (var i = 0; i < optDoms.length; i++) {
+        cfg[optDoms[i].name] = optDoms[i].checked;
+      }
       return cfg;
     }
     ui.ai.cfgTitle = function(aiName) {
@@ -721,9 +725,7 @@
         return new ai.BlindWeightRandom(ui.brdEngine, cfg);
       },
       "ai-blind-cycle": function(aiDom) {
-        var cfg = {};
-        cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked;
-        cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked;
+        var cfg = ui.ai.parseCfg(aiDom);
         return new ai.BlindCycle(ui.brdEngine, cfg);
       },
       "ai-one-step-ahead": function(aiDom) {