ai.js
changeset 35 3d56325d7002
parent 29 30a09d50ae21
child 36 a18fc2601ce8
equal deleted inserted replaced
34:16b711a81a16 35:3d56325d7002
    11 
    11 
    12 ////////////////////////////////////////////////////////////////
    12 ////////////////////////////////////////////////////////////////
    13 // Random AI.
    13 // Random AI.
    14 ////////////////////////////////////////////////////////////////
    14 ////////////////////////////////////////////////////////////////
    15 
    15 
    16 ai.random = function(brdEngine) {
    16 ai.blindRandom = function(brdEngine) {
    17     this.brdEngine = brdEngine;
    17     this.brdEngine = brdEngine;
    18 }
    18 }
    19 ai.random.prototype.analyse = function(brd) {
    19 ai.blindRandom.prototype.analyse = function(brd) {
    20     var origBrd = new this.brdEngine(brd);
    20     var origBrd = new this.brdEngine(brd);
    21     while (true) {
    21     while (true) {
    22         var rnd = Math.floor(Math.random()*4);
    22         var rnd = Math.floor(Math.random()*4);
    23         if (origBrd[["canUp", "canDown", "canLeft", "canRight"][rnd]]())
    23         if (origBrd[["canUp", "canDown", "canLeft", "canRight"][rnd]]())
    24             return ["up", "down", "left", "right"][rnd];
    24             return ["up", "down", "left", "right"][rnd];
    25     }
    25     }
    26 }
    26 }
    27 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
    27 /* Mark that next board will be unrelated to previous, so any stored precompution can be cleared. */
    28 ai.random.prototype.cleanup = function() { }
    28 ai.blindRandom.prototype.cleanup = function() { }
    29 
    29 
    30 
    30 
    31 
    31 
    32 ////////////////////////////////////////////////////////////////
    32 ////////////////////////////////////////////////////////////////
    33 // Blind cycle AI.
    33 // Blind cycle AI.