159 </div> |
159 </div> |
160 <div class="ai" id="ai-blind-weight-random"> |
160 <div class="ai" id="ai-blind-weight-random"> |
161 <button class="ai">enable</button> |
161 <button class="ai">enable</button> |
162 <h5>bling weight random</h5> |
162 <h5>bling weight random</h5> |
163 <div class="option"> |
163 <div class="option"> |
164 <input type="text" name="left" class="int" pattern="[0-9]*" value="1"/> left weight |
164 <input type="text" name="left" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> left weight |
165 </div> |
165 </div> |
166 <div class="option"> |
166 <div class="option"> |
167 <input type="text" name="right" class="int" pattern="[0-9]*" value="1"/> right weight |
167 <input type="text" name="right" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> right weight |
168 </div> |
168 </div> |
169 <div class="option"> |
169 <div class="option"> |
170 <input type="text" name="up" class="int" pattern="[0-9]*" value="1"/> up weight |
170 <input type="text" name="up" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> up weight |
171 </div> |
171 </div> |
172 <div class="option"> |
172 <div class="option"> |
173 <input type="text" name="down" class="int" pattern="[0-9]*" value="1"/> down weight |
173 <input type="text" name="down" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> down weight |
174 </div> |
174 </div> |
175 <div class="clearfix"></div> |
175 <div class="clearfix"></div> |
176 </div> |
176 </div> |
177 <div class="ai" id="ai-blind-cycle"> |
177 <div class="ai" id="ai-blind-cycle"> |
178 <button class="ai">enable</button> |
178 <button class="ai">enable</button> |
187 </div> |
187 </div> |
188 <div class="ai" id="ai-one-step-deep"> |
188 <div class="ai" id="ai-one-step-deep"> |
189 <button class="ai">enable</button> |
189 <button class="ai">enable</button> |
190 <h5>next merge makes max value</h5> |
190 <h5>next merge makes max value</h5> |
191 <div class="option"> |
191 <div class="option"> |
192 <input type="text" name="scoreCoef" class="int" pattern="[0-9]*" value="1"/> score weight |
192 <input type="text" name="scoreCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="1"/> score weight |
193 </div> |
193 </div> |
194 <div class="option"> |
194 <div class="option"> |
195 <input type="text" name="maxValCoef" class="int" pattern="[0-9]*" value="0"/> max value weight |
195 <input type="text" name="maxValCoef" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value weight |
196 </div> |
196 </div> |
197 <div class="option"> |
197 <div class="option"> |
198 <input type="text" name="cornerBonus" class="int" pattern="[0-9]*" value="100"/> max value at corner bonus |
198 <input type="text" name="cornerBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="100"/> max value at corner bonus |
199 </div> |
199 </div> |
200 <div class="option"> |
200 <div class="option"> |
201 <input type="text" name="edgeBonus" class="int" pattern="[0-9]*" value="0"/> max value at edge bonus |
201 <input type="text" name="edgeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="0"/> max value at edge bonus |
202 </div> |
202 </div> |
203 <div class="option"> |
203 <div class="option"> |
204 <input type="text" name="freeBonus" class="int" pattern="[0-9]*" value="10"/> free cell coefficient |
204 <input type="text" name="freeBonus" class="positive" pattern="[0-9]*[.]?[0-9]*" value="10"/> free cell coefficient |
205 </div> |
205 </div> |
206 <div class="clearfix"></div> |
206 <div class="clearfix"></div> |
207 </div> |
207 </div> |
208 <div class="ai" id="ai-deep-max-score"> |
208 <div class="ai" id="ai-deep-max-score"> |
209 <button class="ai">enable</button> |
209 <button class="ai">enable</button> |
543 // Register AIs. |
543 // Register AIs. |
544 |
544 |
545 ui.ai = {}; |
545 ui.ai = {}; |
546 ui.ai.current = null; |
546 ui.ai.current = null; |
547 ui.ai.parseCfg = function(aiDom, cfg) { |
547 ui.ai.parseCfg = function(aiDom, cfg) { |
548 var optDoms = aiDom.querySelectorAll("div.option > input.int[type='text']"); |
548 var optDoms = aiDom.querySelectorAll("div.option > input.positive[type='text']"); |
549 for (var i = 0; i < optDoms.length; i++) { |
549 for (var i = 0; i < optDoms.length; i++) { |
550 var val = parseFloat(optDoms[i].value); |
550 var val = parseFloat(optDoms[i].value); |
551 if (val === NaN) { |
551 if (val === NaN || val < 0) { |
552 ui.game.setMessage('' + optDoms[i].name + ' setting is not a number!'); |
552 ui.game.setMessage('' + optDoms[i].name + ' is not a positive number!'); |
|
553 cfg[optDoms[i].name] = 1; |
553 continue; |
554 continue; |
554 } |
555 } |
555 cfg[optDoms[i].name] = val; |
556 cfg[optDoms[i].name] = val; |
556 } |
557 } |
557 } |
558 } |
|
559 |
558 ui.ai.algList = { |
560 ui.ai.algList = { |
559 "ai-blind-random": function() { |
561 "ai-blind-random": function() { |
560 return new ai.blindRandom(ui.brdEngine); |
562 return new ai.blindRandom(ui.brdEngine); |
561 }, |
563 }, |
562 "ai-blind-weight-random": function(aiDom) { |
564 "ai-blind-weight-random": function(aiDom) { |
563 var cfg = {}; |
565 var cfg = {}; |
564 cfg.left = aiDom.querySelectorAll("input[name='left']")[0].value; |
566 ui.ai.parseCfg(aiDom, cfg); |
565 cfg.right = aiDom.querySelectorAll("input[name='right']")[0].value; |
567 return new ai.blindWeightRandom(ui.brdEngine, cfg); |
566 cfg.up = aiDom.querySelectorAll("input[name='up']")[0].value; |
|
567 cfg.down = aiDom.querySelectorAll("input[name='down']")[0].value; |
|
568 return new ai.blindWeightRandom(ui.brdEngine); |
|
569 }, |
568 }, |
570 "ai-blind-cycle": function(aiDom) { |
569 "ai-blind-cycle": function(aiDom) { |
571 var cfg = {}; |
570 var cfg = {}; |
572 cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked; |
571 cfg.clockwise = aiDom.querySelectorAll("input[name='clockwise']")[0].checked; |
573 cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked; |
572 cfg.whilePossible = aiDom.querySelectorAll("input[name='whilePossible']")[0].checked; |
574 return new ai.blindCycle(ui.brdEngine, cfg); |
573 return new ai.blindCycle(ui.brdEngine, cfg); |
575 }, |
574 }, |
576 "ai-one-step-deep": function(aiDom) { |
575 "ai-one-step-deep": function(aiDom) { |
577 var cfg = {}; |
576 var cfg = {}; |
578 ui.ai.parseCfg(aiDom, cfg); |
577 ui.ai.parseCfg(aiDom, cfg); |
579 console.log(cfg); |
|
580 return new ai.oneStepDeep(ui.brdEngine, cfg); |
578 return new ai.oneStepDeep(ui.brdEngine, cfg); |
581 }, |
579 }, |
582 "ai-deep-max-score": function() { |
580 "ai-deep-max-score": function() { |
583 return new ai.deepMaxScore(ui.brdEngine); |
581 return new ai.deepMaxScore(ui.brdEngine); |
584 }, |
582 }, |