<commit_before>/**
* Game.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs        :: http://sailsjs.org/#!documentation/models
*/

module.exports = {

  autoWatch: false,

  autosubscribe: ['message', 'update', 'destroy'],

  attributes: {
    active: {type: 'boolean',
             required: true,
             defaultsTo: false},
  	name: {type: 'string',
  		     required: true},
  	rooms: {collection: 'room',
  			    via: 'game'},
    startingRoom: {model: 'room',
                   required: false},
    players: {collection: 'player',
              via: 'game'},
    traitor: {model: 'player',
              required: false},
    haunt: {type: 'string',
            required: false},
  },

  checkWin: function(gameID, roomID) {
    var game;

    Game.findOne(gameID).populate('players').populate('rooms')
      .then(function(found) {
        if (found === undefined) {
          throw new Error('Game could not be found.');
        }

        game = found;

        if (game.haunt === undefined) {
          return -1;
        }

        return Item.count({stat: 'keys', game: gameID});
      })
      .then(function(keyCount) {
        if (keyCount === 0) {
          for (var i = 0; i < game.players.length; i++) {
            var p = game.players[i];
            if (!p.isTraitor && p.room !== roomID) {
              return;
            }
          }

          /* If we made it through, then the heroes won. */
          Game.message(game.id, {verb: 'heroesWon'});
        }
      })
      .catch(function(err) {
        sails.log.error(err);
      });
  },

  startHaunt: function(gameID) {
    var game;

    Game.findOne(gameID).populate('players').populate('rooms')
      .then(function(found) {
        if (found === undefined) {
          throw new Erro("Game could not be found.");
        }

        game = found;

        if (game.haunt !== undefined) {
          sails.log.info("Haunt already started.");
          throw new sails.promise.CancellationError();
        }

        var traitor = game.players[Math.floor(Math.random()
                                   * game.players.length)];<commit_msg>I cannot spell Error apparently.<commit_after>/**
* Game.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs        :: http://sailsjs.org/#!documentation/models
*/

module.exports = {

  autoWatch: false,

  autosubscribe: ['message', 'update', 'destroy'],

  attributes: {
    active: {type: 'boolean',
             required: true,
             defaultsTo: false},
  	name: {type: 'string',
  		     required: true},
  	rooms: {collection: 'room',
  			    via: 'game'},
    startingRoom: {model: 'room',
                   required: false},
    players: {collection: 'player',
              via: 'game'},
    traitor: {model: 'player',
              required: false},
    haunt: {type: 'string',
            required: false},
  },

  checkWin: function(gameID, roomID) {
    var game;

    Game.findOne(gameID).populate('players').populate('rooms')
      .then(function(found) {
        if (found === undefined) {
          throw new Error('Game could not be found.');
        }

        game = found;

        if (game.haunt === undefined) {
          return -1;
        }

        return Item.count({stat: 'keys', game: gameID});
      })
      .then(function(keyCount) {
        if (keyCount === 0) {
          for (var i = 0; i < game.players.length; i++) {
            var p = game.players[i];
            if (!p.isTraitor && p.room !== roomID) {
              return;
            }
          }

          /* If we made it through, then the heroes won. */
          Game.message(game.id, {verb: 'heroesWon'});
        }
      })
      .catch(function(err) {
        sails.log.error(err);
      });
  },

  startHaunt: function(gameID) {
    var game;

    Game.findOne(gameID).populate('players').populate('rooms')
      .then(function(found) {
        if (found === undefined) {
          throw new Error("Game could not be found.");
        }

        game = found;

        if (game.haunt !== undefined) {
          sails.log.info("Haunt already started.");
          throw new sails.promise.CancellationError();
        }

        var traitor = game.players[Math.floor(Math.random()
                                   * game.players.length)];
{'fraction_non_alphanumeric': 0.14934478084048802, 'fraction_numerical': 0.0013556258472661546, 'mean_word_length': 1.8414634146341464, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '65905', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1307, 'n_words': 324}