<commit_before>var io;
var socket;
var players = [];
var host = [];
var request = require("request");
// #GowriImport the model to use its database functions
var player = require("../../models/playerModels.js");
require('dotenv').config({ path: '../../dotenv.env' });
//var currentURL = window.location.origin;

// An object that holds the global variables for the game that the host machine needs to track
// #SRM More key/value pairs get created as needed in the initialization
//#Gowri moved global var from hostmachine to game.js
//#Gowri added host array and added this variable to anywhere the host gets referred
var hostGlobalVar = {
    currentGreenCard: null,
    currentGreenCardIndex: 0,
    currentLeaderIndex: 0,
    dealerTracker: 0,
    greenDeck: [],
    hostArray: [],
    playersArray: [],
    playerDecks: [],
    roundsNum: 2,
    roundsTracker: 1,
    submittedCards: [],
    winningCards: [],
    playersNum: 0
};

// #Amanda when a connection is created a new game instance is created
exports.initGame = function(sio, sock) {
    io = sio;
    socket = sock;
    socket.emit('connected', { message: "You are connected!" });

    //#Gowri when a user clicks start a game and there are already 5 players then room full message will display
    socket.on("can player join", function() {
        if (players.length >= 5) {
            socket.emit('player limit reached', "landing");
        } //#Gowri else display the player page
        else {
            socket.emit('display player');
        }
    })

    socket.on('set user', setUser);

    // #Gowri when start button is clicked this listener will start the game by building the deck for each players
    socket.on('start game', function() {
        hostGlobalVar.greenCardsTotal = (hostGlobalVar.playersNum * hostGlobalVar.roundsNum);
        hostGlobalVar.redCardsTotal = (((hostGlobalVar.playersNum * 4) * hostGlobalVar.roundsNum) + (((hostGlobalVar.playersNum - 1) * (hostGlobalVar.playersNum)) * hostGlobalVar.roundsNum));
        hostGlobalVar.deckArray = hostBuildDeck();

    })
}


/*============================================================================
    
    #SRM 
    HOST FUNCTIONS
    #Moved all host functions from Host Machine to Game.js
============================================================================*/
function hostBuildDeck() {

    hostDrawGreenCards(hostGlobalVar.greenCardsTotal, 7471, 9951);
    hostDrawRedCards(hostGlobalVar.redCardsTotal, 1, 7461);

}

//function makes an AJAX call and sets global variable so our host Machine can access this array later;
function hostDrawGreenCards(cardsNum, startId, endId) {

    // #SRM AJAX call to grab an array of all the red cards that all players will need for the game
-        // #SRM Create a shuffled array of all red card ids in our db, then splice it to match our game length, and turn it into a string        
-    player.selectAllWithinIdList(hostGenerateIdArray( endId+1, startId ).splice( 0, cardsNum ).toString(),
-    function(data){
-        console.log("i am in host draw green")
-        hostGlobalVar.greenDeck = data;
-        //console.log(hostGlobalVar.greenDeck);
-        
-        // Prepare the first green card to be revealed
-        hostGlobalVar.currentGreenCard = hostGlobalVar.greenDeck[hostGlobalVar.currentGreenCardIndex];
-        //#Gowri emitting green cards to the host
-        io.to(hostGlobalVar.hostArray[0].playerId).emit('green cards', hostGlobalVar.greenDeck);
-    });

}

function hostDrawRedCards(cardsNum, startId, endId) {
   // console.log(hostGenerateIdArray(endId + 1, startId).splice(0, cardsNum).toString());
    player.selectAllWithinIdList(hostGenerateIdArray(endId + 1, startId).splice(0, cardsNum).toString(),<commit_msg>REALLY, REALLY FIXED MERGE CONFLICTS THIS TIME<commit_after>var io;
var socket;
var players = [];
var host = [];
var request = require("request");
// #GowriImport the model to use its database functions
var player = require("../../models/playerModels.js");
require('dotenv').config({ path: '../../dotenv.env' });
//var currentURL = window.location.origin;

// An object that holds the global variables for the game that the host machine needs to track
// #SRM More key/value pairs get created as needed in the initialization
//#Gowri moved global var from hostmachine to game.js
//#Gowri added host array and added this variable to anywhere the host gets referred
var hostGlobalVar = {
    currentGreenCard: null,
    currentGreenCardIndex: 0,
    currentLeaderIndex: 0,
    dealerTracker: 0,
    greenDeck: [],
    hostArray: [],
    playersArray: [],
    playerDecks: [],
    roundsNum: 2,
    roundsTracker: 1,
    submittedCards: [],
    winningCards: [],
    playersNum: 0
};

// #Amanda when a connection is created a new game instance is created
exports.initGame = function(sio, sock) {
    io = sio;
    socket = sock;
    socket.emit('connected', { message: "You are connected!" });

    //#Gowri when a user clicks start a game and there are already 5 players then room full message will display
    socket.on("can player join", function() {
        if (players.length >= 5) {
            socket.emit('player limit reached', "landing");
        } //#Gowri else display the player page
        else {
            socket.emit('display player');
        }
    })

    socket.on('set user', setUser);

    // #Gowri when start button is clicked this listener will start the game by building the deck for each players
    socket.on('start game', function() {
        hostGlobalVar.greenCardsTotal = (hostGlobalVar.playersNum * hostGlobalVar.roundsNum);
        hostGlobalVar.redCardsTotal = (((hostGlobalVar.playersNum * 4) * hostGlobalVar.roundsNum) + (((hostGlobalVar.playersNum - 1) * (hostGlobalVar.playersNum)) * hostGlobalVar.roundsNum));
        hostGlobalVar.deckArray = hostBuildDeck();

    })
}


/*============================================================================
    
    #SRM 
    HOST FUNCTIONS
    #Moved all host functions from Host Machine to Game.js
============================================================================*/
function hostBuildDeck() {

    hostDrawGreenCards(hostGlobalVar.greenCardsTotal, 7471, 9951);
    hostDrawRedCards(hostGlobalVar.redCardsTotal, 1, 7461);

}

//function makes an AJAX call and sets global variable so our host Machine can access this array later;
function hostDrawGreenCards(cardsNum, startId, endId) {

    // #SRM AJAX call to grab an array of all the red cards that all players will need for the game
        // #SRM Create a shuffled array of all red card ids in our db, then splice it to match our game length, and turn it into a string        
    player.selectAllWithinIdList(hostGenerateIdArray( endId+1, startId ).splice( 0, cardsNum ).toString(),
    function(data){
      //console.log("i am in host draw green");
      hostGlobalVar.greenDeck = data;
       //console.log(hostGlobalVar.greenDeck);
       
       // Prepare the first green card to be revealed
       hostGlobalVar.currentGreenCard = hostGlobalVar.greenDeck[hostGlobalVar.currentGreenCardIndex];
        //#Gowri emitting green cards to the host
        io.to(hostGlobalVar.hostArray[0].playerId).emit('green cards', hostGlobalVar.greenDeck);
    });

}

function hostDrawRedCards(cardsNum, startId, endId) {
   // console.log(hostGenerateIdArray(endId + 1, startId).splice(0, cardsNum).toString());
    player.selectAllWithinIdList(hostGenerateIdArray(endId + 1, startId).splice(0, cardsNum).toString(),
{'fraction_non_alphanumeric': 0.14437932871603623, 'fraction_numerical': 0.007991475759190196, 'mean_word_length': 3.553668890236507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '569304', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2086, 'n_words': 685}