<commit_before>(function() {

Dagaz.Model.WIN_CNT = 49;
Dagaz.Model.SIZE    = 15;
Dagaz.Model.HALF    = 7;

Dagaz.View.DX       = 0;
Dagaz.View.DY       = 0;
Dagaz.View.MX       = 25;

var cache = [];

var isMikul    = false;
var isMatiBela = false;
var isSimulate = false;
var isSimple   = false;

var checkVersion = Dagaz.Model.checkVersion;

Dagaz.Model.checkVersion = function(design, name, value) {
  if (name == "dakon-extension") {
      if (value == "mikul")     isMikul    = true;
      if (value == "mati-bela") isMatiBela = true;
      if (value == "simulate")  isSimulate = true;
      if (value == "simple")    isSimple   = true;
  } else {
      checkVersion(design, name, value);
  }
}

var createPiece = function(design, player, value) {
  if (value != 0) {
      if (!_.isUndefined(cache[player]) && !_.isUndefined(cache[player][value])) {
          return cache[player][value];
      }
      var r = Dagaz.Model.createPiece(0, player).setValue(0, value);
      if (_.isUndefined(cache[player])) {
          cache[player] = [];
      }
      cache[player][value] = r;
      return r;
  } else {
      return null;
  }
}

var addReserve = function(x, y) {
  var r = Math.abs(x) + y;
  if (x < 0) {
      return -r;
  } else {
      return r;
  }
}

var toReserve = function(design, board, player, move, cnt) {
  var pos = design.navigate(player, 0, 2);
  if ((cnt != 0) && (pos !== null)) {
      piece = board.getPiece(pos);
      if (piece === null) {
          piece = Dagaz.Model.createPiece(0, player);
          piece = piece.setValue(0, cnt);
          move.dropPiece(pos, piece);
      } else {
          cnt = addReserve(cnt, Math.abs(+piece.getValue(0)));
          piece = piece.setValue(0, cnt);
          move.movePiece(pos, pos, piece);
      }
  }
}

var CheckInvariants = Dagaz.Model.CheckInvariants;

Dagaz.Model.CheckInvariants = function(board) {
  var design = Dagaz.Model.design;  
  var noCapturing = false;
  if (_.isUndefined(board.noInitial) && isSimulate) {
      noCapturing = (board.parent === null);
  }
  _.each(board.moves, function(move) {
      var isPool = false;
      var fr  = 0;
      var dir = 0;
      if (move.mode != 0) {
          dir = 6;
      }
      if (move.isSimpleMove()) {
          var pos = move.actions[0][0][0];
          if (design.inZone(1, board.player, pos)) {
              move.failed = true;
              return;
          }
          var piece = board.getPiece(pos);
          var cnt = Math.abs(+piece.getValue(0));
          if (_.isUndefined(cache[piece.player])) {
              cache[piece.player] = [];
              cache[piece.player][cnt] = piece;
          }
          var positions = [];
          var result = [];
          result.push(0);
          for (var ix = 1; cnt > 0; cnt--, ix++) {
               pos = design.navigate(board.player, pos, dir);
               positions.push(pos);
               if (pos === null) {
                   move.failed = true;
                   return;
               }
               if (ix >= Dagaz.Model.SIZE) {
                   ix = 0;
               }
               piece = board.getPiece(pos);
               if (ix < result.length) {
                   result[ix]++;
               } else {
                   if (piece === null) {
                       result.push(1);
                   } else {
                       result.push(Math.abs(+piece.getValue(0)) + 1);
                   }
               }
          }
          ix--;
          var captured = [];
          isPool = design.inZone(1, board.player, pos);
          if (noCapturing) {
              var start = _.random(0, Dagaz.Model.HALF - 1);
              var ps = _.indexOf(positions, start);
              if (ps < 0) {
                  while (pos != start) {
                     pos = design.navigate(board.player, pos, dir);
                     if ((pos === null) || !design.inZone(0, 2, pos)) {
                         move.failed = true;
                         return;
                     }
                     positions.push(pos);
                     ix++;
                     var piece = board.getPiece(pos);
                     if (piece === null) {
                         result.push(0);
                     } else {
                         result.push(Math.abs(+piece.getValue(0)));
                     }
                  }
              } else {
                  pos = positions[ps];
                  x = ps;
              }
              result[ix] -= Dagaz.Model.HALF;
              for (var i = 0; i < Dagaz.Model.HALF; i++) {
                   pos = design.navigate(2, pos, dir);
                   if (pos === null) {
                       move.failed = true;
                       return;
                   }
                   if (design.inZone(1, 2, pos)) {
                       var piece = Dagaz.Model.createPiece(0, 2).setValue(0, 1);
                       move.dropPiece(pos, piece);
                       continue;
                   }
                   ix++;
                   if (ix >= Dagaz.Model.SIZE) {
                       ix = 0;
                   }
                   var piece = board.getPiece(pos);
                   if (ix < result.length) {
                       result[ix]++;
                   } else {
                       if (piece === null) {
                           result.push(1);
                       } else {
                           result.push(Math.abs(+piece.getValue(0)) + 1);
                       }
                   }
              }
              console.log(result);
          } else {
              if ((!isSimple && (result[ix] > 1)) || isPool) {
                  result[ix] = -result[ix];
              } else {
                  if (!isPool) {
                      if (design.inZone(0, board.player, pos)) {
                          pos = design.navigate(board.player, pos, 4);
                          if (pos !== null) {<commit_msg>Kalah (fix)<commit_after>(function() {

Dagaz.Model.WIN_CNT = 49;
Dagaz.Model.SIZE    = 15;
Dagaz.Model.HALF    = 7;

Dagaz.View.DX       = 0;
Dagaz.View.DY       = 0;
Dagaz.View.MX       = 25;

var cache = [];

var isMikul    = false;
var isMatiBela = false;
var isSimulate = false;
var isSimple   = false;

var checkVersion = Dagaz.Model.checkVersion;

Dagaz.Model.checkVersion = function(design, name, value) {
  if (name == "dakon-extension") {
      if (value == "mikul")     isMikul    = true;
      if (value == "mati-bela") isMatiBela = true;
      if (value == "simulate")  isSimulate = true;
      if (value == "simple")    isSimple   = true;
  } else {
      checkVersion(design, name, value);
  }
}

var createPiece = function(design, player, value) {
  if (value != 0) {
      if (!_.isUndefined(cache[player]) && !_.isUndefined(cache[player][value])) {
          return cache[player][value];
      }
      var r = Dagaz.Model.createPiece(0, player).setValue(0, value);
      if (_.isUndefined(cache[player])) {
          cache[player] = [];
      }
      cache[player][value] = r;
      return r;
  } else {
      return null;
  }
}

var addReserve = function(x, y) {
  var r = Math.abs(x) + y;
  if (x < 0) {
      return -r;
  } else {
      return r;
  }
}

var toReserve = function(design, board, player, move, cnt) {
  var pos = design.navigate(player, 0, 2);
  if ((cnt != 0) && (pos !== null)) {
      piece = board.getPiece(pos);
      if (piece === null) {
          piece = Dagaz.Model.createPiece(0, player);
          piece = piece.setValue(0, cnt);
          move.dropPiece(pos, piece);
      } else {
          cnt = addReserve(cnt, Math.abs(+piece.getValue(0)));
          piece = piece.setValue(0, cnt);
          move.movePiece(pos, pos, piece);
      }
  }
}

var CheckInvariants = Dagaz.Model.CheckInvariants;

Dagaz.Model.CheckInvariants = function(board) {
  var design = Dagaz.Model.design;  
  var noCapturing = false;
  if (_.isUndefined(board.noInitial) && isSimulate) {
      noCapturing = (board.parent === null);
  }
  _.each(board.moves, function(move) {
      var isPool = false;
      var fr  = 0;
      var dir = 0;
      if (move.mode != 0) {
          dir = 6;
      }
      if (move.isSimpleMove()) {
          var pos = move.actions[0][0][0];
          if (design.inZone(1, board.player, pos)) {
              move.failed = true;
              return;
          }
          var piece = board.getPiece(pos);
          var cnt = Math.abs(+piece.getValue(0));
          if (_.isUndefined(cache[piece.player])) {
              cache[piece.player] = [];
              cache[piece.player][cnt] = piece;
          }
          var positions = [];
          var result = [];
          result.push(0);
          for (var ix = 1; cnt > 0; cnt--, ix++) {
               pos = design.navigate(board.player, pos, dir);
               positions.push(pos);
               if (pos === null) {
                   move.failed = true;
                   return;
               }
               if (ix >= Dagaz.Model.SIZE) {
                   ix = 0;
               }
               piece = board.getPiece(pos);
               if (ix < result.length) {
                   result[ix]++;
               } else {
                   if (piece === null) {
                       result.push(1);
                   } else {
                       result.push(Math.abs(+piece.getValue(0)) + 1);
                   }
               }
          }
          ix--;
          var captured = [];
          isPool = design.inZone(1, board.player, pos);
          if (noCapturing) {
              var start = _.random(0, Dagaz.Model.HALF - 1);
              var ps = _.indexOf(positions, start);
              if (ps < 0) {
                  while (pos != start) {
                     pos = design.navigate(board.player, pos, dir);
                     if ((pos === null) || !design.inZone(0, 2, pos)) {
                         move.failed = true;
                         return;
                     }
                     positions.push(pos);
                     ix++;
                     var piece = board.getPiece(pos);
                     if (piece === null) {
                         result.push(0);
                     } else {
                         result.push(Math.abs(+piece.getValue(0)));
                     }
                  }
              } else {
                  pos = positions[ps];
                  x = ps;
              }
              result[ix] -= Dagaz.Model.HALF;
              for (var i = 0; i < Dagaz.Model.HALF; i++) {
                   pos = design.navigate(2, pos, dir);
                   if (pos === null) {
                       move.failed = true;
                       return;
                   }
                   if (design.inZone(1, 2, pos)) {
                       var piece = Dagaz.Model.createPiece(0, 2).setValue(0, 1);
                       move.dropPiece(pos, piece);
                       continue;
                   }
                   ix++;
                   if (ix >= Dagaz.Model.SIZE) {
                       ix = 0;
                   }
                   var piece = board.getPiece(pos);
                   if (ix < result.length) {
                       result[ix]++;
                   } else {
                       if (piece === null) {
                           result.push(1);
                       } else {
                           result.push(Math.abs(+piece.getValue(0)) + 1);
                       }
                   }
              }
              console.log(result);
          } else {
              if ((!isSimple && (result[ix] > 1)) || isPool) {
                  result[ix] = -result[ix];
              } else {
                  if (!isPool) {
                      if (design.inZone(0, board.player, pos) && (result[ix] == 1)) {
                          pos = design.navigate(board.player, pos, 4);
                          if (pos !== null) {
{'fraction_non_alphanumeric': 0.13596307175828787, 'fraction_numerical': 0.009987410826689047, 'mean_word_length': 1.1816184547784694, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4132553', 'n_tokens_mistral': 3660, 'n_tokens_neox': 3454, 'n_words': 747}