text: (function() {
  
  Dagaz.AI.AI_FRAME      = 1500;
  Dagaz.AI.MIN_DEEP      = 3;
  
  var MAX_FORCED_FACTOR  = 1;
  
  var strictMode = false;
  
  var checkVersion = Dagaz.Model.checkVersion;
  
  Dagaz.Model.checkVersion = function(design, name, value) {
    if (name != "turkish-extension") {
       checkVersion(design, name, value);
    }
  }
  
  Dagaz.AI.heuristic = function(ai, design, board, move) {
    var r = 1;
    _.each(move.actions, function(a) {
        if (a[0] !== null) {
            if (a[1] !== null) {
                if (design.inZone(0, board.player, a[1][0])) r += 1000;
            } else {
                var piece = board.getPiece(a[0][0]);
                if (piece !== null) {
                    r += design.price[piece.type];
                }
            }
        }
    });
    return r;
  }
  
  var getDirs = function(type) {
    if (type == 0) {
        return [0, 1, 3];
    } else {
        return [0, 1, 2, 3];
    }
  }
  
  Dagaz.AI.isForced = function(design, board, move) {
    if (_.isUndefined(move.isForced)) {
        move.isForced = false;
        var b = board.apply(move);
        var c = 0;
        _.each(design.allPositions(), function(pos) {
            var piece = b.getPiece(pos);
            if ((piece !== null) && (piece.player == b.player)) {
                _.each(getDirs(+piece.type), function(dir) {
                     var piece = b.getPiece(pos);
                     var p = design.navigate(b.player, pos, dir);
                     if (piece.type == 1) {
                         while (p !== null) {
                             if (b.getPiece(p) !== null) break;
                             p = design.navigate(b.player, p, dir);
                         }
                     }
                     if (p !== null) {
                         piece = b.getPiece(p);
                         if ((piece !== null) && (piece.type == 0) && (piece.player != b.player)) {
                              p = design.navigate(b.player, p, dir);
                              if ((p !== null) && (b.getPiece(p) === null)) c++;
                         }
                     }
                });
            }
        });
        if ((c > 0) && (c <= MAX_FORCED_FACTOR)) {
            move.isForced = true;
        }
    }
    return move.isForced;
  }
  
  Dagaz.AI.getEval = function(design, board) {
    if (_.isUndefined(board.eval)) {
        board.eval = 0;
        _.each(design.allPositions(), function(pos) {
            var piece = board.getPiece(pos);
            if (piece !== null) {
                var v = design.price[piece.type];
                if (!Dagaz.AI.isFriend(board.player, piece.player)) {
                    v = -v;
                }
                board.eval += v;
            }
        });
    }
    return board.eval;
  }
  
  Dagaz.AI.eval = function(design, params, board, player) {
    var r = Dagaz.AI.getEval(design, board);
    if (!Dagaz.AI.isFriend(player, board.player)) {
        r = -r;
    }
    return r;
  }
  
  })();
  