<commit_before>// One single match
//
var
  sys       = require('sys'),
  events    = require('events'),
  assert    = require('assert'),
  log       = require('./log'),
  gamelogic = require('./gamelogic');

function Match(mid, authCode, pub) {
  this.initTime = Date();
  this.mid = mid;
  this.authCode = authCode;
  this.pub = pub;
  this.game = new gamelogic.ATRobotsGame(this);

  this.speed = 0.3;

  this.timer = null;

  // field_size
  // robots
}
sys.inherits(Match, events.EventEmitter);

Match.prototype.toJSON = function() {
  return process.mixin(this.game.toJSON(),
    {
      init_time: this.initTime,
      speed: this.speed,
      'public': this.pub
    }
  );
};

Match.prototype.start = function(authCode) {
  // Start the match.
  assert.ok(authCode == this.authCode, "Incorrect authentication code.");
  // We must remove all the blank robots first.
  for (var rid in this.game.robots) {
    if (this.game.robots.hasOwnProperty(rid) &&
        this.game.robots[rid] === null) {
          this.removeSlot(rid);
      }
  }
  this.game.start();

  // We must assign something to 'this' because inside the function in
  // setTimeout, 'this' refers to the window object.
  var self = this;
  this.timer = setInterval(function() {
    self.game.pump();
  }, 1000*this.speed);
  this.emit("started", this);
};

Match.prototype.pump = function() {
    this.game.pump();<commit_msg>Guard against the repl starting two matches at once<commit_after>// One single match
//
var
  sys       = require('sys'),
  events    = require('events'),
  assert    = require('assert'),
  log       = require('./log'),
  gamelogic = require('./gamelogic');

function Match(mid, authCode, pub) {
  this.initTime = Date();
  this.mid = mid;
  this.authCode = authCode;
  this.pub = pub;
  this.game = new gamelogic.ATRobotsGame(this);

  this.speed = 0.3;

  this.timer = null;

  // field_size
  // robots
}
sys.inherits(Match, events.EventEmitter);

Match.prototype.toJSON = function() {
  return process.mixin(this.game.toJSON(),
    {
      init_time: this.initTime,
      speed: this.speed,
      'public': this.pub
    }
  );
};

Match.prototype.start = function(authCode) {
  // Start the match.
  assert.ok(authCode == this.authCode, "Incorrect authentication code.");
  assert.ok(!this.game.started, "You cannot start a started match.");
  // We must remove all the blank robots first.
  for (var rid in this.game.robots) {
    if (this.game.robots.hasOwnProperty(rid) &&
        this.game.robots[rid] === null) {
          this.removeSlot(rid);
      }
  }
  this.game.start();

  // We must assign something to 'this' because inside the function in
  // setTimeout, 'this' refers to the window object.
  var self = this;
  this.timer = setInterval(function() {
    self.game.pump();
  }, 1000*this.speed);
  this.emit("started", this);
};

Match.prototype.pump = function() {
    this.game.pump();
{'fraction_non_alphanumeric': 0.15381968341362698, 'fraction_numerical': 0.0041293874741913286, 'mean_word_length': 2.9283783783783783, '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': '5474569', 'n_tokens_mistral': 984, 'n_tokens_neox': 962, 'n_words': 229}