<commit_before>// exports.handler = function(event, context) { eventHandler(event, context) };

function eventHandler(event, context) {
  try {
    if (event.request.type === 'LaunchRequest') {
      welcome(function callback(speechletResponse) {
        context.succeed(buildResponse(event.session.attributes, speechletResponse));
      });
    } else if (event.request.type === 'IntentRequest') {
      intentHandler(event.request, function callback(speechletResponse) {
        context.succeed(buildResponse(event.session.attributes, speechletResponse));
      });
    }
  } catch (e) {
    context.fail('Exception: ' + e);
  }
}

function welcome(callback) {
  this.game = new Game(3);
  callback(buildSpeechResponse('welcome to tic tac toe', 'select a cell by row and column .  for example top left or middle right or bottom middle', false));
}

function intentHandler(intentRequest, callback) {
  var intentName = intentRequest.intent.name;
  var row = intentRequest.intent.slots.row.value;
  var column = intentRequest.intent.slots.column.value;
  if (intentName == 'PlayIntent') {
    this.game.playerPlay(row, column, callback);
  } else {
    throw 'Invalid intent';
  }
}

Game.prototype.playerPlay = function(row, column, callback) {
  var rows = {top: 0, middle: 1, bottom: 2};
  var columns = {left: 0, middle: 1, right: 2};
  if(this._board.grid()[rows[row]][columns[column]] !== '') {
    this.explainMistake(callback);
  } else {
    this._board.take(rows[row], columns[column], this._player.symbol());
    if(this._board.hasWon('x')) {
      callback(buildSpeechResponse('you played ' + row + ' ' + column + '.  you won.', '', 'true'));
    } else if(this._board.isFull()) {
      callback(buildSpeechResponse('you played ' + row + ' ' + column + '.  the game is a draw.', '', 'true'));    
    } else {
      this.robotPlay(rows[row], columns[column], callback);
    }
  }
};

Game.prototype.explainMistake = function(callback) {
  callback(buildSpeechResponse('that cell is already taken', '', 'false'));
};

Game.prototype.robotPlay = function(playerRow, playerColumn, callback) {<commit_msg>extract outcomes function from playerPlay function<commit_after>// exports.handler = function(event, context) { eventHandler(event, context) };

function eventHandler(event, context) {
  try {
    if (event.request.type === 'LaunchRequest') {
      welcome(function callback(speechletResponse) {
        context.succeed(buildResponse(event.session.attributes, speechletResponse));
      });
    } else if (event.request.type === 'IntentRequest') {
      intentHandler(event.request, function callback(speechletResponse) {
        context.succeed(buildResponse(event.session.attributes, speechletResponse));
      });
    }
  } catch (e) {
    context.fail('Exception: ' + e);
  }
}

function welcome(callback) {
  this.game = new Game(3);
  callback(buildSpeechResponse('welcome to tic tac toe', 'select a cell by row and column .  for example top left or middle right or bottom middle', false));
}

function intentHandler(intentRequest, callback) {
  var intentName = intentRequest.intent.name;
  var row = intentRequest.intent.slots.row.value;
  var column = intentRequest.intent.slots.column.value;
  if (intentName == 'PlayIntent') {
    this.game.playerPlay(row, column, callback);
  } else {
    throw 'Invalid intent';
  }
}

Game.prototype.playerPlay = function(row, column, callback) {
  var rows = {top: 0, middle: 1, bottom: 2};
  var columns = {left: 0, middle: 1, right: 2};
  if(this._board.grid()[rows[row]][columns[column]] !== '') {
    this.explainMistake(callback);
  } else {
    this._board.take(rows[row], columns[column], this._player.symbol());
    this.playerPlayOutcomes(row, column, callback);
  }
};

Game.prototype.playerPlayOutcomes = function(row, column, callback) {
  if(this._board.hasWon('x')) {
    callback(buildSpeechResponse('you played ' + row + ' ' + column + '.  you won.', '', 'true'));
  } else if(this._board.isFull()) {
    callback(buildSpeechResponse('you played ' + row + ' ' + column + '.  the game is a draw.', '', 'true'));
  } else {
    this.robotPlay(row, column, callback);
  }
};

Game.prototype.explainMistake = function(callback) {
  callback(buildSpeechResponse('that cell is already taken', '', 'false'));
};

Game.prototype.robotPlay = function(playerRow, playerColumn, callback) {
{'fraction_non_alphanumeric': 0.15335169880624427, 'fraction_numerical': 0.0032139577594123047, 'mean_word_length': 4.1379716981132075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4280859', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1316, 'n_words': 296}