<commit_before>var renderer;
var numInRow = 6;
var numInCol = 5;
var gameRules = {
  skyfall:  true,
  moveTime: 4,
  minOrbs: 3,
}
var boardWidth = 600;
var boardHeight = 500;
var board = [];
var renderQueue = [];
var animationList = [];
var timeLeft = 0;
var orbSelected = null;
var animationRunning = false;
var orbAssets = [
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image()
];
var bgAssets = [new Image(), new Image()];
orbAssets[0].src = "assets/Orb-Fr.png";
orbAssets[1].src = "assets/Orb-Wt.png";
orbAssets[2].src = "assets/Orb-Wd.png";
orbAssets[3].src = "assets/Orb-Lt.png";
orbAssets[4].src = "assets/Orb-Dk.png";
orbAssets[5].src = "assets/Orb-Heal.png";
orbAssets[6].src = "assets/Orb-Jammer.png";
orbAssets[7].src = "assets/Orb-Poison.png";
orbAssets[8].src = "assets/Orb-MPoison.png";
orbAssets[9].src = "assets/Orb-Bomb.png";
bgAssets[0].src = "assets/bg0.png";
bgAssets[1].src = "assets/bg1.png";

function rollOrb() {
  // TODO: adjusted skyfall rate
  // Reserch skyfall rates, if 15% dark is 15/100 says dark orb spawns, or 1.15 weight on dark
  // Also account for tricolor, no-RCV and similar skyfalls 
  return {
    color:   Math.floor(Math.random() * 6),
    enhanced: false,
    locked: false,
    blind1: false, // Regular blind, slide orbs to reveal
    blind2: 0, // Duration blind, cannot see orbs until timer is over
    matched: false,
    trueX:   null,
    trueY:   null,
    offset:  0
  };
}

function refreshBoard() {
  board = [];
  for(var i = 0; i < numInCol; i++) {
  board[i] = [];
    for(var j = 0; j < numInRow; j++) {
      // TODO: actual skyfall stuff, no available combos
      board[i][j] = rollOrb();
    }
  }
};

function redraw() {
  // TODO variable frame rate
  var toDraw = renderQueue.shift();
  // Queue is empty when orbs are being moved
  if (typeof(toDraw) == "undefined") {
    animationRunning = false;
    toDraw = board;
  }
  renderer.clearRect(0, 0, boardWidth, boardHeight);
  for (var i = 0; i < numInCol; i++) {
    for (var j = 0; j < numInRow; j++) {
      // draw background
      renderer.drawImage(bgAssets[(i + j) % 2],
                         j * boardWidth / numInRow,
                         i * boardHeight / numInCol,
                         boardWidth / numInRow,
                         boardHeight / numInCol);
      // Orb id -1 means don't draw it
      if (toDraw[i][j].color >= 0 && toDraw[i][j].color < orbAssets.length) {
        if (orbSelected != null && orbSelected.row == i && orbSelected.col == j) {
	  renderer.globalAlpha = 0.5;
        }
        renderer.drawImage(orbAssets[toDraw[i][j].color],
                           boardWidth * j / numInRow,
                           boardHeight * (i - toDraw[i][j].offset) / numInCol,
                           boardWidth / numInRow,
                           boardHeight / numInCol);
        renderer.globalAlpha = 1;
      }
    }
  }
  if (orbSelected != null) {
    renderer.drawImage(orbAssets[toDraw[orbSelected.row][orbSelected.col].color],
                       toDraw[orbSelected.row][orbSelected.col].trueX,
                       toDraw[orbSelected.row][orbSelected.col].trueY,
		       boardWidth / numInRow,
                       boardHeight / numInCol);
    if (timeLeft < .5) {
      renderer.fillStyle = "#00FF00"
      renderer.fillRect(toDraw[orbSelected.row][orbSelected.col].trueX,
                        toDraw[orbSelected.row][orbSelected.col].trueY - boardHeight / 50,
                        boardWidth / numInRow * timeLeft * 2,
                        boardHeight / 50);
    }
  }
  for (var animation of animationList) {
    animation.timeLeft -= 1;
    if (animation.type == "pause") {
      break;
    }
    switch (animation.type) {
    case "erase":
      renderer.globalAlpha = animation.timeLeft / 10;
      renderer.drawImage(orbAssets[animation.color],
                         boardWidth * animation.j / numInRow,
                         boardHeight * animation.i / numInCol,
                         boardWidth / numInRow,
                         boardHeight / numInCol);
      renderer.globalAlpha = 1; 
      break;
    }
  }
  animationList = animationList.filter(function(animation) {
    return animation.timeLeft > 0;
  });
};

function cascade(skyfall) {
  for(var n = 0; n < numInCol; n++) {
    var hasCascade = false;
    for(var j = 0; j < numInRow; j++) {
      // must loop from bottom to top
      for(var i = numInCol-1; i > 0; i--) {
        if(board[i][j].color == -1 && board[i-1][j].color != -1) {
          board[i][j].color = board[i-1][j].color;
          board[i][j].enhanced = board[i-1][j].enhanced;
          board[i][j].locked = board[i-1][j].locked;
          board[i][j].blind1 = board[i-1][j].blind1;
          board[i][j].blind2 = board[i-1][j].blind2;
          board[i-1][j].color = -1;
          board[i][j].offset = 1;
          hasCascade = true;
        }
      }
      if(board[0][j].color == -1 && 
	
	) {
        board[0][j] = rollOrb();
        board[0][j].offset = 1;
        hasCascade = true;<commit_msg>Fixed accidental deletion of skyfall<commit_after>var renderer;
var numInRow = 6;
var numInCol = 5;
var gameRules = {
  skyfall:  true,
  moveTime: 4,
  minOrbs: 3,
}
var boardWidth = 600;
var boardHeight = 500;
var board = [];
var renderQueue = [];
var animationList = [];
var timeLeft = 0;
var orbSelected = null;
var animationRunning = false;
var orbAssets = [
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image(),
  new Image()
];
var bgAssets = [new Image(), new Image()];
orbAssets[0].src = "assets/Orb-Fr.png";
orbAssets[1].src = "assets/Orb-Wt.png";
orbAssets[2].src = "assets/Orb-Wd.png";
orbAssets[3].src = "assets/Orb-Lt.png";
orbAssets[4].src = "assets/Orb-Dk.png";
orbAssets[5].src = "assets/Orb-Heal.png";
orbAssets[6].src = "assets/Orb-Jammer.png";
orbAssets[7].src = "assets/Orb-Poison.png";
orbAssets[8].src = "assets/Orb-MPoison.png";
orbAssets[9].src = "assets/Orb-Bomb.png";
bgAssets[0].src = "assets/bg0.png";
bgAssets[1].src = "assets/bg1.png";

function rollOrb() {
  // TODO: adjusted skyfall rate
  // Reserch skyfall rates, if 15% dark is 15/100 says dark orb spawns, or 1.15 weight on dark
  // Also account for tricolor, no-RCV and similar skyfalls 
  return {
    color:   Math.floor(Math.random() * 6),
    enhanced: false,
    locked: false,
    blind1: false, // Regular blind, slide orbs to reveal
    blind2: 0, // Duration blind, cannot see orbs until timer is over
    matched: false,
    trueX:   null,
    trueY:   null,
    offset:  0
  };
}

function refreshBoard() {
  board = [];
  for(var i = 0; i < numInCol; i++) {
  board[i] = [];
    for(var j = 0; j < numInRow; j++) {
      // TODO: actual skyfall stuff, no available combos
      board[i][j] = rollOrb();
    }
  }
};

function redraw() {
  // TODO variable frame rate
  var toDraw = renderQueue.shift();
  // Queue is empty when orbs are being moved
  if (typeof(toDraw) == "undefined") {
    animationRunning = false;
    toDraw = board;
  }
  renderer.clearRect(0, 0, boardWidth, boardHeight);
  for (var i = 0; i < numInCol; i++) {
    for (var j = 0; j < numInRow; j++) {
      // draw background
      renderer.drawImage(bgAssets[(i + j) % 2],
                         j * boardWidth / numInRow,
                         i * boardHeight / numInCol,
                         boardWidth / numInRow,
                         boardHeight / numInCol);
      // Orb id -1 means don't draw it
      if (toDraw[i][j].color >= 0 && toDraw[i][j].color < orbAssets.length) {
        if (orbSelected != null && orbSelected.row == i && orbSelected.col == j) {
	  renderer.globalAlpha = 0.5;
        }
        renderer.drawImage(orbAssets[toDraw[i][j].color],
                           boardWidth * j / numInRow,
                           boardHeight * (i - toDraw[i][j].offset) / numInCol,
                           boardWidth / numInRow,
                           boardHeight / numInCol);
        renderer.globalAlpha = 1;
      }
    }
  }
  if (orbSelected != null) {
    renderer.drawImage(orbAssets[toDraw[orbSelected.row][orbSelected.col].color],
                       toDraw[orbSelected.row][orbSelected.col].trueX,
                       toDraw[orbSelected.row][orbSelected.col].trueY,
		       boardWidth / numInRow,
                       boardHeight / numInCol);
    if (timeLeft < .5) {
      renderer.fillStyle = "#00FF00"
      renderer.fillRect(toDraw[orbSelected.row][orbSelected.col].trueX,
                        toDraw[orbSelected.row][orbSelected.col].trueY - boardHeight / 50,
                        boardWidth / numInRow * timeLeft * 2,
                        boardHeight / 50);
    }
  }
  for (var animation of animationList) {
    animation.timeLeft -= 1;
    if (animation.type == "pause") {
      break;
    }
    switch (animation.type) {
    case "erase":
      renderer.globalAlpha = animation.timeLeft / 10;
      renderer.drawImage(orbAssets[animation.color],
                         boardWidth * animation.j / numInRow,
                         boardHeight * animation.i / numInCol,
                         boardWidth / numInRow,
                         boardHeight / numInCol);
      renderer.globalAlpha = 1; 
      break;
    }
  }
  animationList = animationList.filter(function(animation) {
    return animation.timeLeft > 0;
  });
};

function cascade(skyfall) {
  for(var n = 0; n < numInCol; n++) {
    var hasCascade = false;
    for(var j = 0; j < numInRow; j++) {
      // must loop from bottom to top
      for(var i = numInCol-1; i > 0; i--) {
        if(board[i][j].color == -1 && board[i-1][j].color != -1) {
          board[i][j].color = board[i-1][j].color;
          board[i][j].enhanced = board[i-1][j].enhanced;
          board[i][j].locked = board[i-1][j].locked;
          board[i][j].blind1 = board[i-1][j].blind1;
          board[i][j].blind2 = board[i-1][j].blind2;
          board[i-1][j].color = -1;
          board[i][j].offset = 1;
          hasCascade = true;
        }
      }
      if(board[0][j].color == -1 && skyfall) {
        board[0][j] = rollOrb();
        board[0][j].offset = 1;
        hasCascade = true;
{'fraction_non_alphanumeric': 0.1485148514851485, 'fraction_numerical': 0.017666472529605903, 'mean_word_length': 2.1079939668174963, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 9, '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': '2379349', 'n_tokens_mistral': 3599, 'n_tokens_neox': 3441, 'n_words': 788}