<commit_before>
'use strict';

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

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


const gameSession = require('./domain/game-session');
const playerStatus = require('./domain/player-status');

const shouldBet = require('./domain-utils/should-bet');
const shouldBreak = require('./domain-utils/should-break');


const asyncFrom = require('./lib/loop-from-async');



/**
 * @function
 * @name betLoop
 * @desc
 *  It's the generator that controls the betting loop.
 *  It's completed after the "river", or when all the players but one have folded
 *
 * @param {Object} gs:
 *  the gamestate object
 *
 * @returns {void}
 */
exports = module.exports = function* betLoop(gs){

  logger.info('Hand %d/%d, starting betting session', gs.gameProgressiveId, gs.handProgressiveId, { tag: gs.handUniqueId });


  const deck_ = Symbol.for('cards-deck');
  const hasBB_ = Symbol.for('has-big-blind');
  const hasDB_ = Symbol.for('has-dealer-button');



  // the betting loop continues until
  // all the community cards are shown
  // and there are more than an active player
  while (gs.commonCards.length <= 5 && gs.activePlayers.length > 1){



    // track the current hand session
    gs.session = getGameSession(gs.commonCards.length);



    logger.log('debug', 'Hand %d/%d, %s', gs.gameProgressiveId, gs.handProgressiveId, gs.session, { tag: gs.handUniqueId });
    logger.log('debug', getPlayerStatusLogMessage(gs.players), { tag: gs.handUniqueId });



    // count the number of time that players had already have the possibility
    // to bet in the current session.
    gs.spinCount = 0;

    const starterButton = gs.session == gameSession.pre ? hasBB_ : hasDB_;
    const startIndex = gs.players.findIndex(player => player[starterButton]);

    do {

      yield* asyncFrom(gs.players, startIndex, shouldBreak.bind(null, gs),
        player => shouldBet(gs, player, player => player.talk(gs).then(player.payBet.bind(player, gs))));

      gs.spinCount++;

    } while(!isBetRoundFinished(gs.activePlayers, gs.callAmount));


    // when a betting round ends
    // raise data should be cleared
    gs.lastRaiseAmount = 0;
    gs.lastRaiserId = null





    // when execution reach this line,
    // all players have defined their bet for the current session.

    const activePlayers = gs.activePlayers;<commit_msg>reset has-talked when bet-loop ends<commit_after>
'use strict';

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

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


const gameSession = require('./domain/game-session');
const playerStatus = require('./domain/player-status');

const shouldBet = require('./domain-utils/should-bet');
const shouldBreak = require('./domain-utils/should-break');


const asyncFrom = require('./lib/loop-from-async');



/**
 * @function
 * @name betLoop
 * @desc
 *  It's the generator that controls the betting loop.
 *  It's completed after the "river", or when all the players but one have folded
 *
 * @param {Object} gs:
 *  the gamestate object
 *
 * @returns {void}
 */
exports = module.exports = function* betLoop(gs){

  logger.info('Hand %d/%d, starting betting session', gs.gameProgressiveId, gs.handProgressiveId, { tag: gs.handUniqueId });


  const deck_ = Symbol.for('cards-deck');
  const hasBB_ = Symbol.for('has-big-blind');
  const hasDB_ = Symbol.for('has-dealer-button');
  const hasTalked_ = Symbol.for('has-talked');



  // the betting loop continues until
  // all the community cards are shown
  // and there are more than an active player
  while (gs.commonCards.length <= 5 && gs.activePlayers.length > 1){



    // track the current hand session
    gs.session = getGameSession(gs.commonCards.length);



    logger.log('debug', 'Hand %d/%d, %s', gs.gameProgressiveId, gs.handProgressiveId, gs.session, { tag: gs.handUniqueId });
    logger.log('debug', getPlayerStatusLogMessage(gs.players), { tag: gs.handUniqueId });



    // count the number of time that players had already have the possibility
    // to bet in the current session.
    gs.spinCount = 0;

    const starterButton = gs.session == gameSession.pre ? hasBB_ : hasDB_;
    const startIndex = gs.players.findIndex(player => player[starterButton]);

    do {

      yield* asyncFrom(gs.players, startIndex, shouldBreak.bind(null, gs),
        player => shouldBet(gs, player, player => player.talk(gs).then(player.payBet.bind(player, gs))));

      gs.spinCount++;

    } while(!isBetRoundFinished(gs.activePlayers, gs.callAmount));


    // when a betting round ends
    // raise data should be cleared
    gs.lastRaiseAmount = 0;

    // ... and the pot should be re-opened
    // for the next iteration
    gs.players.forEach(player => delete(player[hasTalked_]));





    // when execution reach this line,
    // all players have defined their bet for the current session.

    const activePlayers = gs.activePlayers;
{'fraction_non_alphanumeric': 0.1374398073836276, 'fraction_numerical': 0.0016051364365971107, 'mean_word_length': 3.5153985507246377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '5866964', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1470, 'n_words': 424}