2048.html
changeset 189 44cb6fbad74d
parent 188 754796e567ab
child 190 d1b12b602915
equal deleted inserted replaced
188:754796e567ab 189:44cb6fbad74d
   543         return false;
   543         return false;
   544       }
   544       }
   545       return true;
   545       return true;
   546     }
   546     }
   547 
   547 
   548     ui.game.prepare = function() {
   548     ui.game.prepareStep = function() {
   549       ui.suggestion.clear();
   549       ui.suggestion.clear();
   550       ui.game.clearMessage();
   550       ui.game.clearMessage();
   551       if (ui.game.checkGameOver())
   551       if (ui.game.checkGameOver())
   552         return false;
   552         return false;
   553       return true;
   553       return true;
   619       event.preventDefault(); event.stopPropagation();
   619       event.preventDefault(); event.stopPropagation();
   620       if ( ! ui.ai.current) {
   620       if ( ! ui.ai.current) {
   621         ui.game.setMessage('Select AI!');
   621         ui.game.setMessage('Select AI!');
   622         return;
   622         return;
   623       }
   623       }
   624       if ( ! ui.game.prepare())
   624       if ( ! ui.game.prepareStep())
   625         return;
   625         return;
   626       var tmpBrd = board.create();
   626       var tmpBrd = board.create();
   627       board.copy(ui.board.position, tmpBrd);
   627       board.copy(ui.board.position, tmpBrd);
   628       var move = ui.ai.current.analyse(tmpBrd);
   628       var move = ui.ai.current.analyse(tmpBrd);
   629       ui.ai.current.cleanup();
   629       ui.ai.current.cleanup();
   635     ui.action.step = function() {
   635     ui.action.step = function() {
   636       if ( ! ui.ai.current) {
   636       if ( ! ui.ai.current) {
   637         ui.game.setMessage('Select AI!');
   637         ui.game.setMessage('Select AI!');
   638         return;
   638         return;
   639       }
   639       }
   640       if ( ! ui.game.prepare())
   640       if ( ! ui.game.prepareStep())
   641         return;
   641         return;
   642       var tmpBrd = board.create();
   642       var tmpBrd = board.create();
   643       board.copy(ui.board.position, tmpBrd);
   643       board.copy(ui.board.position, tmpBrd);
   644       var move = ui.ai.current.analyse(tmpBrd);
   644       var move = ui.ai.current.analyse(tmpBrd);
   645       ui.ai.current.cleanup();
   645       ui.ai.current.cleanup();
   649       ui.game.finishStep();
   649       ui.game.finishStep();
   650     }
   650     }
   651     document.getElementById("step").addEventListener("click", ui.action.step, false);
   651     document.getElementById("step").addEventListener("click", ui.action.step, false);
   652 
   652 
   653     ui.action.visualFinishAux = function() {
   653     ui.action.visualFinishAux = function() {
   654       if ( ! ui.game.prepare())
   654       if ( ! ui.game.prepareStep())
   655         return;
   655         return;
   656       var brd = board.create();
   656       var brd = board.create();
   657       board.copy(ui.board.position, brd);
   657       board.copy(ui.board.position, brd);
   658       var move = ui.ai.current.analyse(brd);
   658       var move = ui.ai.current.analyse(brd);
   659       if ( ! ui.game.checkMoveValid(move))
   659       if ( ! ui.game.checkMoveValid(move))
   677         console.profile();
   677         console.profile();
   678       if ( ! ui.ai.current) {
   678       if ( ! ui.ai.current) {
   679         ui.game.setMessage('Select AI!');
   679         ui.game.setMessage('Select AI!');
   680         return;
   680         return;
   681       }
   681       }
   682       ui.game.prepare();
   682       ui.game.prepareStep();
   683       var step = 0;
   683       var step = 0;
   684       var safeBdr = board.create();
   684       var safeBdr = board.create();
   685       var tsFrom = new Date().getTime();
   685       var tsFrom = new Date().getTime();
   686       while (!board.gameOver(ui.board.position)) {
   686       while (!board.gameOver(ui.board.position)) {
   687         board.copy(ui.board.position, safeBdr);
   687         board.copy(ui.board.position, safeBdr);
   715     ui.action.until = function() {
   715     ui.action.until = function() {
   716       if ( ! ui.ai.current) {
   716       if ( ! ui.ai.current) {
   717         ui.game.setMessage('Select AI!');
   717         ui.game.setMessage('Select AI!');
   718         return;
   718         return;
   719       }
   719       }
   720       if ( ! ui.game.prepare())
   720       if ( ! ui.game.prepareStep())
   721         return;
   721         return;
   722       var step = 0;
   722       var step = 0;
   723       var safeBdr = board.create();
   723       var safeBdr = board.create();
   724       var tsFrom = new Date().getTime();
   724       var tsFrom = new Date().getTime();
   725       var scoreLimit = parseInt(document.getElementById("until-score").value);
   725       var scoreLimit = parseInt(document.getElementById("until-score").value);