<commit_before>
'use strict';

const config = require('./config');

const events = require('events');
const EventEmitter = events.EventEmitter;

const logger = require('./storage/logger');

const run = require('./utils/generator-runner').run;
const gameloop = require('./poker-engine/game-loop');

const createPlayer = require('./poker-engine/domain-utils/player-factory');

const tournamentStatus = require('./poker-engine/domain/tournament-status');




const setup_ = Symbol('setup-tournament-method');
const tournaments_ = Symbol('tournament-collection');

const gamestate = Object.create(EventEmitter.prototype, {

  /**
   * @private
   * @function
   * @name setup
   * @desc configure a tournament settings, and let the game begins
   *
   * @param {string} tournamentId:
   *  unique identifier for the current tournament
   * @param {Array} players:
   *  list of the player who play the current tournament;
   *  each player is an object with at least the following properties:
   *  - player.id
   *  - player.name
   *  - player.serviceUrl
   * @param {Number} gameId:
   *  specify from which game the tournament should start;
   *  it's different from 1 when the tournament is recovered after a crash.
   *
   * @returns void
   */
  [setup_]: {
    writable: process.env.NODE_ENV === 'test',
    value: function(tournamentId, players, gameId){
      const gs = {};
      gs.pid = process.pid;
      gs.tournamentId = tournamentId;
      gs.gameProgressiveId = gameId;
      gs.handProgressiveId = 1;

      gs.handUniqueId = `${gs.pid}_${gs.tournamentId}_${gs.gameProgressiveId}-${gs.handProgressiveId}`;


      logger.info('Setup tournament %s.', tournamentId, { tag: gs.handUniqueId });


      gs.tournamentStatus = tournamentStatus.play

      gs.players = players.map(createPlayer).filter(x => x != null);

      if (gs.players.length < 2){
        logger.info('Tournament %s cannot start cause not enough players.', tournamentId, { tag: gs.handUniqueId });
        return this.emit('tournament:aborted', { tournamentId: tournamentId });
      }

      this[tournaments_].set(tournamentId, gs);

      logger.log('debug', 'Tournament players are: %s', gs.players.map(p => p.name).toString().replace(/,/g, ', '), { tag: gs.handUniqueId });
<commit_msg>added activePlayers shortcut<commit_after>
'use strict';

const config = require('./config');

const events = require('events');
const EventEmitter = events.EventEmitter;

const logger = require('./storage/logger');

const run = require('./utils/generator-runner').run;
const gameloop = require('./poker-engine/game-loop');

const createPlayer = require('./poker-engine/domain-utils/player-factory');

const tournamentStatus = require('./poker-engine/domain/tournament-status');




const setup_ = Symbol('setup-tournament-method');
const tournaments_ = Symbol('tournament-collection');

const gamestate = Object.create(EventEmitter.prototype, {

  /**
   * @private
   * @function
   * @name setup
   * @desc configure a tournament settings, and let the game begins
   *
   * @param {string} tournamentId:
   *  unique identifier for the current tournament
   * @param {Array} players:
   *  list of the player who play the current tournament;
   *  each player is an object with at least the following properties:
   *  - player.id
   *  - player.name
   *  - player.serviceUrl
   * @param {Number} gameId:
   *  specify from which game the tournament should start;
   *  it's different from 1 when the tournament is recovered after a crash.
   *
   * @returns void
   */
  [setup_]: {
    writable: process.env.NODE_ENV === 'test',
    value: function(tournamentId, players, gameId){
      const gs = {};
      gs.pid = process.pid;
      gs.tournamentId = tournamentId;
      gs.gameProgressiveId = gameId;
      gs.handProgressiveId = 1;

      gs.handUniqueId = `${gs.pid}_${gs.tournamentId}_${gs.gameProgressiveId}-${gs.handProgressiveId}`;


      logger.info('Setup tournament %s.', tournamentId, { tag: gs.handUniqueId });


      gs.tournamentStatus = tournamentStatus.play

      gs.players = players.map(createPlayer).filter(x => x != null);

      Object.defineProperty(gs, 'activePlayers', {
        get() {
         return this.players.filter(x=>x.status=='active')
        }
      });

      if (gs.players.length < 2){
        logger.info('Tournament %s cannot start cause not enough players.', tournamentId, { tag: gs.handUniqueId });
        return this.emit('tournament:aborted', { tournamentId: tournamentId });
      }

      this[tournaments_].set(tournamentId, gs);

      logger.log('debug', 'Tournament players are: %s', gs.players.map(p => p.name).toString().replace(/,/g, ', '), { tag: gs.handUniqueId });

{'fraction_non_alphanumeric': 0.13954970263381478, 'fraction_numerical': 0.001274426508071368, 'mean_word_length': 3.434086629001883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '1125871', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1390, 'n_words': 351}