2048.html
changeset 55 8ba9dc89be87
parent 53 ee53cd2cb69a
child 59 28613a54c71c
--- a/2048.html	Thu Sep 11 19:57:44 2014 +0300
+++ b/2048.html	Thu Sep 11 20:01:09 2014 +0300
@@ -77,7 +77,7 @@
       border: 1px solid tan;
       border-radius: 4px;
     }
-    div.ai > div.option > input.int {
+    div.ai > div.option > input.positive {
       text-align: right;
       max-width: 4em;
       margin-rght: 2px;
@@ -161,16 +161,16 @@
         <button class="ai">enable</button>
         <h5>bling weight random</h5>
         <div class="option">
-          <input type="text" name="left" class="int" pattern="[0-9]*" value="1"/> left weight
+          <input type="text" name="left" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> left weight
         </div>
         <div class="option">
-          <input type="text" name="right" class="int" pattern="[0-9]*" value="1"/> right weight
+          <input type="text" name="right" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> right weight
         </div>
         <div class="option">
-          <input type="text" name="up" class="int" pattern="[0-9]*" value="1"/> up weight
+          <input type="text" name="up" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> up weight
         </div>
         <div class="option">
-          <input type="text" name="down" class="int" pattern="[0-9]*" value="1"/> down weight
+          <input type="text" name="down" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> down weight
         </div>
         <div class="clearfix"></div>
       </div>
@@ -189,19 +189,19 @@
         <button class="ai">enable</button>
         <h5>next merge makes max value</h5>
         <div class="option">
-          <input type="text" name="scoreCoef" class="int" pattern="[0-9]*" value="1"/> score weight
+          <input type="text" name="scoreCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> score weight
         </div>
         <div class="option">
-          <input type="text" name="maxValCoef" class="int" pattern="[0-9]*" value="0"/> max value weight
+          <input type="text" name="maxValCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value weight
         </div>
         <div class="option">
-          <input type="text" name="cornerBonus" class="int" pattern="[0-9]*" value="100"/> max value at corner bonus
+          <input type="text" name="cornerBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="100"/> max value at corner bonus
         </div>
         <div class="option">
-          <input type="text" name="edgeBonus" class="int" pattern="[0-9]*" value="0"/> max value at edge bonus
+          <input type="text" name="edgeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value at edge bonus
         </div>
         <div class="option">
-          <input type="text" name="freeBonus" class="int" pattern="[0-9]*" value="10"/> free cell coefficient
+          <input type="text" name="freeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> free cell coefficient
         </div>
         <div class="clearfix"></div>
       </div>
@@ -545,27 +545,26 @@
     ui.ai = {};
     ui.ai.current = null;
     ui.ai.parseCfg = function(aiDom, cfg) {
-      var optDoms = aiDom.querySelectorAll("div.option > input.int[type='text']");
+      var optDoms = aiDom.querySelectorAll("div.option > input.positive[type='text']");
       for (var i = 0; i < optDoms.length; i++) {
         var val = parseFloat(optDoms[i].value);
-        if (val === NaN) {
-          ui.game.setMessage('' + optDoms[i].name + ' setting is not a number!');
+        if (val === NaN || val < 0) {
+          ui.game.setMessage('' + optDoms[i].name + ' is not a positive number!');
+          cfg[optDoms[i].name] = 1;
           continue;
         }
         cfg[optDoms[i].name] = val;
       }
     }
+
     ui.ai.algList = {
       "ai-blind-random": function() {
         return new ai.blindRandom(ui.brdEngine);
       },
       "ai-blind-weight-random": function(aiDom) {
         var cfg = {};
-        cfg.left = aiDom.querySelectorAll("input[name='left']")[0].value;
-        cfg.right = aiDom.querySelectorAll("input[name='right']")[0].value;
-        cfg.up = aiDom.querySelectorAll("input[name='up']")[0].value;
-        cfg.down = aiDom.querySelectorAll("input[name='down']")[0].value;
-        return new ai.blindWeightRandom(ui.brdEngine);
+        ui.ai.parseCfg(aiDom, cfg);
+        return new ai.blindWeightRandom(ui.brdEngine, cfg);
       },
       "ai-blind-cycle": function(aiDom) {
         var cfg = {};
@@ -576,7 +575,6 @@
       "ai-one-step-deep": function(aiDom) {
         var cfg = {};
         ui.ai.parseCfg(aiDom, cfg);
-        console.log(cfg);
         return new ai.oneStepDeep(ui.brdEngine, cfg);
       },
       "ai-deep-max-score": function() {