<commit_before>var xoffs;
var yoffs;

var heightPx;
var widthPx;

var height;
var width;

var circles;
var colors = ["#0099CC", "#444444", "#00DB4A", "#BB1D00", "#FF8300"];
var stage;
var gameState;

function drawCoordinates() {
  for (i = 0; i < width; i++) {
    var text = new createjs.Text(String.fromCharCode(65 + i), scale / 24 + "px Helvetica", "#000000");
    text.x = scale / 15 + (scale / 12) * i + xoffs;
    text.y = 0 + yoffs;
    stage.addChild(text);
  }
  stage.update();
}

function createCircle(x, y, color) {
  circles[y][x] = new createjs.Shape();
  circles[y][x].graphics.beginFill(colors[color]).drawCircle(0, 0, scale / 24);
  circles[y][x].x = x*(scale / 12) + (scale / 12) + xoffs;
  circles[y][x].y = y*(scale / 12) + (scale / 12) + yoffs;
  circles[y][x].distance = 0;
  stage.addChild(circles[y][x]);
}

function drawCircles() {
  for (i = 0; i < height; i++) {
    circles.push([]);
  }

  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      if (gameState[i][j] == -1)
        continue;
      createCircle(j, i, gameState[i][j]);
    }
  }
}

function init() {
  stage = new createjs.Stage("diaCanvas");

  function resize() {
    var wishAspect = 16/9;
    var curAspect = window.innerWidth / window.innerHeight;

    if (wishAspect > curAspect) {
        widthPx = window.innerWidth;
        heightPx = window.innerWidth / wishAspect;
        scale = heightPx * wishAspect;
        xoffs = 0;
        yoffs = (window.innerHeight - heightPx) / 2;
    } else {
        widthPx = window.innerHeight * wishAspect;
        heightPx = window.innerHeight;
        scale = widthPx;
        xoffs = (window.innerWidth - widthPx) / 2;
        yoffs = 0;
    }

    stage.canvas.width = window.innerWidth;
    stage.canvas.height = window.innerHeight;

    stage.removeAllChildren();
    drawCoordinates();
    drawCircles();
    stage.update();
  }
  resize();
  window.addEventListener('resize', resize, false);

  var socket = io();

  socket.on('gameState', function(gs) {
      stage.removeAllChildren();

      gameState = gs;
      circles = [];

      height = gameState.length;
      width = gameState[0].length;

      drawCoordinates();

      createjs.Ticker.on("tick", tick);
      createjs.Ticker.setFPS(60);
 
      drawCircles();

      stage.update();
  });

  socket.on('doMove', function(move) {
    createCircle(move.x, move.y, move.color);
    circles[move.y][move.x].distance = move.y * (scale / 12) + (scale / 12);
    circles[move.y][move.x].y = 0;
    stage.update();
  });

  socket.on('clearLine', function() {
      gameState.unshift(Array.apply(null, Array(width)).map(Number.prototype.valueOf, -1));
      gameState.pop();
      stage.removeAllChildren();
      drawCoordinates();
      drawCircles();
      stage.update();
  });
}

function tick(event) {

  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      if (circles[i][j] == undefined)
        continue;
      if (circles[i][j].distance > 0) {
        circles[i][j].distance -= (event.delta)/1000*1000;
        circles[i][j].y += (event.delta)/1000*1000;
        if (circles[i][j].distance < 0) {
          circles[i][j].y += circles[i][j].distance;
          circles[i][j].distance = 0;
        }
      }
    }<commit_msg>Fixed scope of for variables<commit_after>var xoffs;
var yoffs;

var heightPx;
var widthPx;

var height;
var width;

var circles;
var colors = ["#0099CC", "#444444", "#00DB4A", "#BB1D00", "#FF8300"];
var stage;
var gameState;

function drawCoordinates() {
  for (var i = 0; i < width; i++) {
    var text = new createjs.Text(String.fromCharCode(65 + i), scale / 24 + "px Helvetica", "#000000");
    text.x = scale / 15 + (scale / 12) * i + xoffs;
    text.y = 0 + yoffs;
    stage.addChild(text);
  }
  stage.update();
}

function createCircle(x, y, color) {
  circles[y][x] = new createjs.Shape();
  circles[y][x].graphics.beginFill(colors[color]).drawCircle(0, 0, scale / 24);
  circles[y][x].x = x*(scale / 12) + (scale / 12) + xoffs;
  circles[y][x].y = y*(scale / 12) + (scale / 12) + yoffs;
  circles[y][x].distance = 0;
  stage.addChild(circles[y][x]);
}

function drawCircles() {
  for (var i = 0; i < height; i++) {
    circles.push([]);
  }

  for (var i = 0; i < height; i++) {
    for (var j = 0; j < width; j++) {
      if (gameState[i][j] == -1)
        continue;
      createCircle(j, i, gameState[i][j]);
    }
  }
}

function init() {
  stage = new createjs.Stage("diaCanvas");

  function resize() {
    var wishAspect = 16/9;
    var curAspect = window.innerWidth / window.innerHeight;

    if (wishAspect > curAspect) {
        widthPx = window.innerWidth;
        heightPx = window.innerWidth / wishAspect;
        scale = heightPx * wishAspect;
        xoffs = 0;
        yoffs = (window.innerHeight - heightPx) / 2;
    } else {
        widthPx = window.innerHeight * wishAspect;
        heightPx = window.innerHeight;
        scale = widthPx;
        xoffs = (window.innerWidth - widthPx) / 2;
        yoffs = 0;
    }

    stage.canvas.width = window.innerWidth;
    stage.canvas.height = window.innerHeight;

    stage.removeAllChildren();
    drawCoordinates();
    drawCircles();
    stage.update();
  }
  resize();
  window.addEventListener('resize', resize, false);

  var socket = io();

  socket.on('gameState', function(gs) {
      stage.removeAllChildren();

      gameState = gs;
      circles = [];

      height = gameState.length;
      width = gameState[0].length;

      drawCoordinates();

      createjs.Ticker.on("tick", tick);
      createjs.Ticker.setFPS(60);

      drawCircles();

      stage.update();
  });

  socket.on('doMove', function(move) {
    createCircle(move.x, move.y, move.color);
    circles[move.y][move.x].distance = move.y * (scale / 12) + (scale / 12);
    circles[move.y][move.x].y = 0;
    stage.update();
  });

  socket.on('clearLine', function() {
      gameState.unshift(Array.apply(null, Array(width)).map(Number.prototype.valueOf, -1));
      gameState.pop();
      stage.removeAllChildren();
      drawCoordinates();
      drawCircles();
      stage.update();
  });
}

function tick(event) {

  for (var i = 0; i < height; i++) {
    for (var j = 0; j < width; j++) {
      if (circles[i][j] == undefined)
        continue;
      if (circles[i][j].distance > 0) {
        circles[i][j].distance -= (event.delta)/1000*1000;
        circles[i][j].y += (event.delta)/1000*1000;
        if (circles[i][j].distance < 0) {
          circles[i][j].y += circles[i][j].distance;
          circles[i][j].distance = 0;
        }
      }
    }
{'fraction_non_alphanumeric': 0.1758442348646182, 'fraction_numerical': 0.027380590203833283, 'mean_word_length': 2.6366150442477876, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, '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': '1019319', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2331, 'n_words': 492}