<commit_before>(function() {

var MAXVALUE = 1000000;

var patterns = [];

var checkVersion = Dagaz.Model.checkVersion;

Dagaz.Model.checkVersion = function(design, name, value) {
  if (name == "atari-go-goal") {
      patterns[   0] = -1; // w e s n
      patterns[   3] = -1; // . . . b
      patterns[  30] = -1; // . . b .
      patterns[ 300] = -1; // . b . .
      patterns[ 303] = -1; // . b . b
      patterns[ 330] = -1; // . b b .
      patterns[3000] = -1; // b . . .
      patterns[3003] = -1; // b . . b
      patterns[3030] = -1; // b . b .
      patterns[  23] = -1; // . . e b
      patterns[ 203] = -1; // . e . b
      patterns[2003] = -1; // e . . b
      patterns[  32] = -1; // . . b e
      patterns[ 230] = -1; // . e b .
      patterns[2030] = -1; // e . b .
      patterns[ 302] = -1; // . b . e
      patterns[ 320] = -1; // . b e .
      patterns[2300] = -1; // e b . .
      patterns[3002] = -1; // b . . e
      patterns[3020] = -1; // b . e .
      patterns[3200] = -1; // b e . .
      patterns[1111] = -1; // f f f f
      patterns[1113] = -1; // f f f b
      patterns[1131] = -1; // f f b f
      patterns[1311] = -1; // f b f f
      patterns[3111] = -1; // b f f f
      patterns[ 222] = -1; // . e e e
      patterns[2022] = -1; // e . e e
      patterns[2202] = -1; // e e . e
      patterns[2220] = -1; // e e e .
      patterns[1222] = -1; // f e e e
      patterns[2122] = -1; // e f e e
      patterns[2212] = -1; // e e f e
      patterns[2221] = -1; // e e e f
      patterns[   1] =  2; // . . . f
      patterns[  10] =  2; // . . f .
      patterns[ 100] =  2; // . f . .
      patterns[1000] =  2; // f . . .
      patterns[   2] =  3; // . . . e
      patterns[  20] =  3; // . . e .
      patterns[ 200] =  3; // . e . .
      patterns[2000] =  3; // e . . .
      patterns[  11] =  4; // . . f f
      patterns[1100] =  4; // f f . .
      patterns[  22] =  5; // . . e e
      patterns[2200] =  5; // e e . .
      patterns[ 211] =  6; // . e f f
      patterns[2011] =  6; // e . f f
      patterns[2211] =  7; // e e f f
      patterns[1102] =  6; // f f . e
      patterns[1120] =  6; // f f e .
      patterns[1122] =  7; // f f e e
  } else {
      checkVersion(design, name, value);
  }
}

var getAtari = function(design, board, pos) {
  var r = null;
  _.each(design.allDirections(), function(dir) {
      if (r === null) {
          var p = design.navigate(board.player, pos, dir);
          if (p !== null) {
              var piece = board.getPiece(p);
              if (piece == null) r = p;
          }
      }
  });
  return r;
}

Dagaz.AI.eval = function(design, params, board, player) {
  var fa = null; var ea = null;
  var fp = null; var ep = null;
  _.each(design.allPositions(), function(pos) {
      var piece = board.getPiece(pos);
      if ((piece !== null) && (piece.getValue(0) !== null)) {
          var value = +piece.getValue(0);
          if (piece.player == board.player) {
              if (fa == 1) {
                  var p = getAtari(design, board, pos);
                  if (p === null) return;
                  if ((fp !== null) && (fp != p)) {
                      fa = 0;
                  }
                  fp = p;
              }
              if ((fa === null) || (fa > value)) fa = value;
          } else {
              if (ea == 1) {
                  var p = getAtari(design, board, pos);
                  if (p === null) return;
                  if ((ep !== null) && (ep != p)) {
                      ea = 0;
                  }
                  ep = p;
              }
              if ((ea === null) || (ea > value)) ea = value;
          }
      }
  });
  var r = 0;
  if ((fa !== null) && (ea !== null)) {
      if (fa <= 1) {
          fa = MAXVALUE;
          if (fa > 0) fa = (fa / 2) | 0;
      } else {
          fa = 100 - fa;
      }
      if (ea <= 1) {
          ea = MAXVALUE;
          if (ea > 0) ea = (ea / 2) | 0;
      } else {
          ea = 100 - ea;
      }
      ea = (ea / 2) | 0;
      r = ea - fa;
  }
  if (board.player != player) r = -r;
  return r;
}

Dagaz.AI.heuristic = function(ai, design, board, move) {
  var atari = 0;
  if ((move.actions.length > 0) && (move.actions[0][1] !== null)) {
      var pos = move.actions[0][1][0];
      var pattern = 0;
      _.each(design.allDirections(), function(dir) {
          var p = design.navigate(board.player, pos, dir);
          if (p !== null) {
              var piece = board.getPiece(p);
              if ((piece !== null) && (piece.getValue(0) !== null)) {
                  if (+piece.getValue(0) == 1) {
                      atari = MAXVALUE;
                      if (piece.player == board.player) atari = (atari / 2) | 0;
                      return;
                  }
                  if (piece.player == board.player) {
                      pattern += 1;
                  } else {
                      pattern += 2;
                  }
              }
          } else {
              pattern += 3;
          }
          pattern = pattern * 10;
      });
      if (atari > 0) return atari;
      if (!_.isUndefined(patterns[pattern])) {
          return patterns[pattern];
      } else {
          return 1;
      }
  } else {
      return -1;
  }
}

var checkGoals = Dagaz.Model.checkGoals;

Dagaz.Model.checkGoals = function(design, board, player) {
  if (!_.isUndefined(board.move)) {
      var captures = _.filter(board.move.actions, function(a) {
          return (a[0] !== null) && (a[1] === null);
      });
      if (captures.length > 0) {
          if (board.player == player){
              return -1;
          } else {
              return 1;<commit_msg>Atari Go (heuristic)<commit_after>(function() {

var checkVersion = Dagaz.Model.checkVersion;

Dagaz.Model.checkVersion = function(design, name, value) {
  if (name != "atari-go-goal") {
      checkVersion(design, name, value);
  }
}

Dagaz.AI.heuristic = function(ai, design, board, move) {
  if ((move.actions.length > 0) && (move.actions[0][1] !== null)) {
      var pos = move.actions[0][1][0];
      var fa  = false; var dm = 0; var eg = false;
      var fs  = 0; var fm = null; em = null; var nn = true;
      for (var dir = 0; dir < design.dirs.length; dir++) {
          var p = design.navigate(board.player, pos, dir);
          if (p !== null) {
              var piece = board.getPiece(p);
              if (piece !== null) {
                  var value = +piece.getValue(0);
                  if (value == 1) {
                      if (piece.player != board.player) return 1000;
                      fa = true;
                  }
                  if (piece.player == board.player) {
                      if ((fm == null) || (fm > value)) fm = value;
                      fs += value - 1;
                  } else {
                      if ((em == null) || (em > value)) em = value;
                  }
                  nn = false;
              } else {
                  dm++;
              }
          } else {
              eg = true;
          }
      }
      if (fa) return 500;
      if ((fm !== null) && (fm < 4) && (fs + dm > fm)) return 200 - fm;
      if ((em !== null) && (em < 4)) return 100;
      if (eg || nn) return -1;
      if (em !== null) return 100 - em;
      return 1;
  } else {
      return -1;
  }
}

var checkGoals = Dagaz.Model.checkGoals;

Dagaz.Model.checkGoals = function(design, board, player) {
  if (!_.isUndefined(board.move)) {
      var captures = _.filter(board.move.actions, function(a) {
          return (a[0] !== null) && (a[1] === null);
      });
      if (captures.length > 0) {
          if (board.player == player){
              return -1;
          } else {
              return 1;
{'fraction_non_alphanumeric': 0.1727979274611399, 'fraction_numerical': 0.041062176165803106, 'mean_word_length': 1.2347322720694645, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2128658', 'n_tokens_mistral': 2832, 'n_tokens_neox': 2643, 'n_words': 730}