Visual AI actions mode.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 24 Sep 2014 02:56:41 +0300
changeset 123 fc6019d22a38
parent 122 4cc40a51742a
child 124 4a2551dd179d
Visual AI actions mode.
2048.html
--- a/2048.html	Tue Sep 23 02:24:13 2014 +0300
+++ b/2048.html	Wed Sep 24 02:56:41 2014 +0300
@@ -155,6 +155,7 @@
     <div class="control">
       <button id="suggest">Suggest</button>
       <button id="step">Step</button>
+      <button id="visual-finish">Visual</button>
       <button id="finish">Finish</button>
     </div>
     <br>
@@ -598,6 +599,27 @@
     }
     document.getElementById("step").addEventListener("click", ui.action.step, false);
 
+    ui.action.visualFinishAux = function(brd) {
+      if ( ! ui.game.beginStep())
+        return;
+      var brd = board.create();
+      board.copy(ui.board.position, brd);
+      var move = ui.ai.current.analyse(brd);
+      if ( ! ui.game.checkMoveValid(move))
+        return;
+      board.move[move].call(null, ui.board.position);
+      ui.game.finishStep();
+      setTimeout(ui.action.visualFinishAux, 10);
+    }
+    ui.action.visualFinish = function() {
+      if ( ! ui.ai.current) {
+        ui.game.setMessage('Select AI!');
+        return;
+      }
+      ui.action.visualFinishAux();
+    };
+    document.getElementById("visual-finish").addEventListener("click", ui.action.visualFinish, false);
+
     ui.action.finish = function() {
       if ( ! ui.ai.current) {
         ui.game.setMessage('Select AI!');