<commit_before>(function(data, lineMath){
  'use strict';
  
  console.log(data);
  console.log(lineMath);
  
  data = data['gameone'];
  
  var wordfinder = {
    
    state: 'ready', // ready, resigned, completed
    
    init: function(){
      console.log('init');
      wordfinder.wordlist.create();
      wordfinder.gameboard.create();
      wordfinder.canvas.create();
      wordfinder.controls.create();
      wordfinder.resultsboard.create();
    },
    
    /**
     * basic game controls
     */
    controls:{
      
      create: function(){
        $('#resign').show();
        $('#reset').off().on('click', wordfinder.controls.reset);
        $('#resign').off().on('click', wordfinder.controls.resign);
      },
      
      reset: function(){
        console.log('reset');
        
        function reset(){
          wordfinder.state = 'ready';
          wordfinder.wordlist.reset();
          $("#wordlist-subcontainer").empty();
          $("#gameboard-subcontainer").empty();
          $("#results-container").empty();
          wordfinder.init();        
        }
        
        if(wordfinder.state == 'resigned' ||
          wordfinder.state == 'completed'){
          reset();
          return;
        }
        
        var r = confirm("You want to reset the game? All found words will be erased.");
        if (r === true) {
          reset();
        }
      },
      
      resign: function(){
        console.log('resign');
        var r = confirm("You want to resign the game?");
        if (r === true) {
          wordfinder.state = 'resigned';
          wordfinder.resultsboard.indicateResigned();
          wordfinder.gameboard.lock();
        }        
      },
      
      gameCompleted: function(){
        console.log('game-completed');
      },
      
      disableResign: function(){
        $('#resign').hide();
      }
    
    },
    
    resultsboard: {
 
       create: function(){
        console.log('create results board');
        
        var display = $('<div></div>')
                        .attr('id', 'results');
        $('#results-container')
          .append(display);

        this.clear();

      },
      
      update: function(update){
        $("#results").html(update);
      },

      clear: function(){
        $('#results').removeClass();
        this.update('Ready to Play!');
      },
      
      indicateComplete: function(){
        wordfinder.gameboard.lock();
        this.update('You found all the words on this puzzle.');
        wordfinder.state = 'completed';
        wordfinder.controls.disableResign();
        $("#results").addClass('completed');
      },
      
      indicateResigned: function(){
        var words = wordfinder.wordlist.words.length;
        var found = wordfinder.wordlist.found.length;
        var results = found+' / '+words;
        this.update('You resigned. You found '+results+' words.');
        $("#results").addClass('resigned');
      }      
      
    },

    /**
     * list of words to find
     * checks game completion
     */    
    wordlist:{
      
      words: data.wordlist,
      
      found: [],
      
      create: function(){

        var display = $('<ul></ul>')
                        .attr('id', 'wordlist');
        $('#wordlist-subcontainer')
          .append(display);

        for(var i in data.wordlist){
          var word = $('<li>'+data.wordlist[i]+'</li>')
                        .addClass('word');
          display.append(word);
        }
      },
      
      isInList: function(word){
        var index = this.words.indexOf(word);
        if(index != -1){ 
          this.found.push(word);
          return true;
        }else return false;
      },
      
      crossOffList: function(word){
        $('li.word').each(function(i, el){
          if($(el).text() == word){
            $(el).html('<strike>'+word+'</strike>');
          }
        })
      },
      
      isGameCompleted: function(){
        return this.words.length == this.found.length;
      },

      reset: function(){
        this.found = [];
      }

    },
    
    gameboard: {
      
      state: 'startup', // startup, waiting, selectA, selectB
      
      selected_a: [],
      
      selected_b: [],
      
      create: function(){
        
        this.state = 'waiting'
        
        var board = $('<table></table>')
                      .attr('id','gameboard');
        $('#gameboard-subcontainer').append(board);
          
        function makeGamesquare(x,y,letter){
          return $('<td>'+letter+'</td>')
                  .data('x',x)
                  .data('y',y)
                  .on('mousedown',  wordfinder.gameboard.selectA)
                  .on('mouseup',    wordfinder.gameboard.selectB)
                  .on('mouseenter', wordfinder.gameboard.isInLine)
                  .on('mouseleave', wordfinder.gameboard.clearInLine);       
        }
        
        for(var i in data.gameboard){
          board.append('<tr></tr>');
          
          for(var j in data.gameboard[i]){
            var letter     = data.gameboard[i][j];
            var gamesquare = makeGamesquare(j,i,letter);
            board
              .find('tr:eq('+i+')')
              .append(gamesquare);

          }
        }
        
        $('#gameboard-subcontainer')
          .css('height', $("#gameboard").height()+"px")
          .css('width', $("#gameboard").width()+"px");
        
      },
      
      selectA: function(){
          var el = $(this);
          el.addClass('selectA');
          wordfinder.gameboard.state = 'selectA';
          wordfinder.gameboard.selected_a = [el.data('x'), el.data('y')]       
      },

      selectB: function(){
          var el = $(this);
          if(el.hasClass('outofline') ||
             el.hasClass('selectA')){
            wordfinder.gameboard.resetBoard();
            return;
          }
          wordfinder.gameboard.state = 'selectB';
          wordfinder.gameboard.selected_b = [el.data('x'), el.data('y')]          
          var is_word = wordfinder.gameboard.checkWord();
          if(is_word){
            wordfinder.gameboard.state = 'waiting';
            if(wordfinder.wordlist.isGameCompleted()){
              wordfinder.resultsboard.indicateComplete();
            }
            wordfinder.gameboard.resetBoard();
          }else{
            wordfinder.gameboard.state = 'waiting';
          }        
      },

      isInLine: function(){

        var state = wordfinder.gameboard.state;

        if(state == 'waiting') return;
        
        wordfinder.gameboard.clearDraggedSelection();
        
        var selected_a = wordfinder.gameboard.selected_a;
        var thissquare = [$(this).data('x'), $(this).data('y')];

        if(selected_a[0] == thissquare[0] ||
           selected_a[1] == thissquare[1] ||
           Math.abs(selected_a[0] - thissquare[0]) == Math.abs(selected_a[1] - thissquare[1])){
          $(this).addClass('inline');
          wordfinder.gameboard.highlightDraggedSelection(selected_a,thissquare);
        }else{
          $(this).addClass('outofline');
          wordfinder.gameboard.clearDraggedSelection();
        }
        
      },

      clearInLine: function(){
        $(this).removeClass('inline');
        $(this).removeClass('outofline')
      },
      
      checkWord: function(){
        
        var selected_a = wordfinder.gameboard.selected_a;
        var selected_b = wordfinder.gameboard.selected_b;
        
        var selected_word = this.getWord(selected_a, selected_b);

        if(wordfinder.wordlist.isInList(selected_word)){
          console.log('found a word')
          wordfinder.gameboard.highlightFoundWord(selected_a, selected_b);<commit_msg>remove unneeded "is inline" class<commit_after>(function(data, lineMath){
  'use strict';
  
  console.log(data);
  console.log(lineMath);
  
  data = data['gameone'];
  
  var wordfinder = {
    
    state: 'ready', // ready, resigned, completed
    
    init: function(){
      console.log('init');
      wordfinder.wordlist.create();
      wordfinder.gameboard.create();
      wordfinder.canvas.create();
      wordfinder.controls.create();
      wordfinder.resultsboard.create();
    },
    
    /**
     * basic game controls
     */
    controls:{
      
      create: function(){
        $('#resign').show();
        $('#reset').off().on('click', wordfinder.controls.reset);
        $('#resign').off().on('click', wordfinder.controls.resign);
      },
      
      reset: function(){
        console.log('reset');
        
        function reset(){
          wordfinder.state = 'ready';
          wordfinder.wordlist.reset();
          $("#wordlist-subcontainer").empty();
          $("#gameboard-subcontainer").empty();
          $("#results-container").empty();
          wordfinder.init();        
        }
        
        if(wordfinder.state == 'resigned' ||
          wordfinder.state == 'completed'){
          reset();
          return;
        }
        
        var r = confirm("You want to reset the game? All found words will be erased.");
        if (r === true) {
          reset();
        }
      },
      
      resign: function(){
        console.log('resign');
        var r = confirm("You want to resign the game?");
        if (r === true) {
          wordfinder.state = 'resigned';
          wordfinder.resultsboard.indicateResigned();
          wordfinder.gameboard.lock();
        }        
      },
      
      gameCompleted: function(){
        console.log('game-completed');
      },
      
      disableResign: function(){
        $('#resign').hide();
      }
    
    },
    
    resultsboard: {
 
       create: function(){
        console.log('create results board');
        
        var display = $('<div></div>')
                        .attr('id', 'results');
        $('#results-container')
          .append(display);

        this.clear();

      },
      
      update: function(update){
        $("#results").html(update);
      },

      clear: function(){
        $('#results').removeClass();
        this.update('Ready to Play!');
      },
      
      indicateComplete: function(){
        wordfinder.gameboard.lock();
        this.update('You found all the words on this puzzle.');
        wordfinder.state = 'completed';
        wordfinder.controls.disableResign();
        $("#results").addClass('completed');
      },
      
      indicateResigned: function(){
        var words = wordfinder.wordlist.words.length;
        var found = wordfinder.wordlist.found.length;
        var results = found+' / '+words;
        this.update('You resigned. You found '+results+' words.');
        $("#results").addClass('resigned');
      }      
      
    },

    /**
     * list of words to find
     * checks game completion
     */    
    wordlist:{
      
      words: data.wordlist,
      
      found: [],
      
      create: function(){

        var display = $('<ul></ul>')
                        .attr('id', 'wordlist');
        $('#wordlist-subcontainer')
          .append(display);

        for(var i in data.wordlist){
          var word = $('<li>'+data.wordlist[i]+'</li>')
                        .addClass('word');
          display.append(word);
        }
      },
      
      isInList: function(word){
        var index = this.words.indexOf(word);
        if(index != -1){ 
          this.found.push(word);
          return true;
        }else return false;
      },
      
      crossOffList: function(word){
        $('li.word').each(function(i, el){
          if($(el).text() == word){
            $(el).html('<strike>'+word+'</strike>');
          }
        })
      },
      
      isGameCompleted: function(){
        return this.words.length == this.found.length;
      },

      reset: function(){
        this.found = [];
      }

    },
    
    gameboard: {
      
      state: 'startup', // startup, waiting, selectA, selectB
      
      selected_a: [],
      
      selected_b: [],
      
      create: function(){
        
        this.state = 'waiting'
        
        var board = $('<table></table>')
                      .attr('id','gameboard');
        $('#gameboard-subcontainer').append(board);
          
        function makeGamesquare(x,y,letter){
          return $('<td>'+letter+'</td>')
                  .data('x',x)
                  .data('y',y)
                  .on('mousedown',  wordfinder.gameboard.selectA)
                  .on('mouseup',    wordfinder.gameboard.selectB)
                  .on('mouseenter', wordfinder.gameboard.isInLine)
                  .on('mouseleave', wordfinder.gameboard.clearInLine);       
        }
        
        for(var i in data.gameboard){
          board.append('<tr></tr>');
          
          for(var j in data.gameboard[i]){
            var letter     = data.gameboard[i][j];
            var gamesquare = makeGamesquare(j,i,letter);
            board
              .find('tr:eq('+i+')')
              .append(gamesquare);

          }
        }
        
        $('#gameboard-subcontainer')
          .css('height', $("#gameboard").height()+"px")
          .css('width', $("#gameboard").width()+"px");
        
      },
      
      selectA: function(){
          var el = $(this);
          el.addClass('selectA');
          wordfinder.gameboard.state = 'selectA';
          wordfinder.gameboard.selected_a = [el.data('x'), el.data('y')]       
      },

      selectB: function(){
          var el = $(this);
          if(el.hasClass('outofline') ||
             el.hasClass('selectA')){
            wordfinder.gameboard.resetBoard();
            return;
          }
          wordfinder.gameboard.state = 'selectB';
          wordfinder.gameboard.selected_b = [el.data('x'), el.data('y')]          
          var is_word = wordfinder.gameboard.checkWord();
          if(is_word){
            wordfinder.gameboard.state = 'waiting';
            if(wordfinder.wordlist.isGameCompleted()){
              wordfinder.resultsboard.indicateComplete();
            }
            wordfinder.gameboard.resetBoard();
          }else{
            wordfinder.gameboard.state = 'waiting';
          }        
      },

      isInLine: function(){

        var state = wordfinder.gameboard.state;

        if(state == 'waiting') return;
        
        wordfinder.gameboard.clearDraggedSelection();
        
        var selected_a = wordfinder.gameboard.selected_a;
        var thissquare = [$(this).data('x'), $(this).data('y')];

        if(selected_a[0] == thissquare[0] ||
           selected_a[1] == thissquare[1] ||
          Math.abs(selected_a[0] - thissquare[0]) == Math.abs(selected_a[1] - thissquare[1])){
          wordfinder.gameboard.highlightDraggedSelection(selected_a,thissquare);
        }else{
          $(this).addClass('outofline');
          wordfinder.gameboard.clearDraggedSelection();
        }
        
      },

      clearInLine: function(){
        $(this).removeClass('inline');
        $(this).removeClass('outofline')
      },
      
      checkWord: function(){
        
        var selected_a = wordfinder.gameboard.selected_a;
        var selected_b = wordfinder.gameboard.selected_b;
        
        var selected_word = this.getWord(selected_a, selected_b);

        if(wordfinder.wordlist.isInList(selected_word)){
          console.log('found a word')
          wordfinder.gameboard.highlightFoundWord(selected_a, selected_b);
{'fraction_non_alphanumeric': 0.15504831074508788, 'fraction_numerical': 0.001167239478633033, 'mean_word_length': 1.6830201809324983, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '541559', 'n_tokens_mistral': 4338, 'n_tokens_neox': 4310, 'n_words': 706}