Exemple #1
0
 private void ResetRandomnessPage(SSCasino_DBContext dbCasino, Randomness model)
 //================================================================================================================
 // Reset the data for the randomness page
 //
 // Parameters
 //      dbCasino: Open connection to the database
 //      model:    Reference to a randomness model
 //================================================================================================================
 {
     // Reset the shuffing results
     // Get default card packs
     SiteHelpers.ClearCombinedShuffleResults();
     model.ShuffledPackageFisher.CardPack = CreateCardPackModel(dbCasino, sampleSize: SiteHelpers.SampleSizes.FourCardSample);
     model.ShuffledPackageNaive.CardPack  = CreateCardPackModel(dbCasino, sampleSize: SiteHelpers.SampleSizes.FourCardSample);
 }
Exemple #2
0
        public ActionResult Randomness_RefreshResultsGraph()
        //================================================================================================================
        // This action is invoked when the shuffling results graph needs to be refreshed.
        //
        // Event Arguments
        //      arg_Action:       Action to be performed
        //      arg_ResizeWidth:  New size of the parent container
        //
        // Returns
        //      The sguffling results grasph
        //================================================================================================================
        {
            // Retrieve the action to be performed
            string action = !string.IsNullOrEmpty(Request.Params[ARG_ACTION]) ? Request.Params[ARG_ACTION] : "";

            // Create the model
            // Get the current size of the results graph
            ShuffleResultsGraph model = new ShuffleResultsGraph();

            if (Session[SiteHelpers.ResultsGraphWidth] != null)
            {
                model.ResizeWidth  = (int)Session[SiteHelpers.ResultsGraphWidth];
                model.ResizeHeight = (int)Session[SiteHelpers.ResultsGraphHeight];
            }

            // Retrieve the shuffling results
            SSCasino_DBContext dbCasino = null;

            try
            {
                // Perform the action
                switch (action)
                {
                case ACT_RESIZE_CHART:
                    // Get the resize width and height
                    int resultsGridWidth  = !string.IsNullOrEmpty(Request.Params[ARG_RESULTS_GRAPH_WIDTH]) ? int.Parse(Request.Params[ARG_RESULTS_GRAPH_WIDTH]) : 0;
                    int resultsGridHeight = !string.IsNullOrEmpty(Request.Params[ARG_RESULTS_GRAPH_HEIGHT]) ? int.Parse(Request.Params[ARG_RESULTS_GRAPH_HEIGHT]) : 0;

                    // Calculate the new width and height of the shuffling results graph
                    // Store these values in the sesssion object for use on refeshes
                    model.ResizeWidth  = ((resultsGridWidth == 0) ? model.DeafultWidth : resultsGridWidth);
                    model.ResizeHeight = ((resultsGridHeight == 0) ? model.DefaultHeight : resultsGridHeight);
                    Session[SiteHelpers.ResultsGraphWidth]  = model.ResizeWidth;
                    Session[SiteHelpers.ResultsGraphHeight] = model.ResizeHeight;
                    break;

                case ACT_CHANGE_SAMPLE_SIZE:
                    // Reset the shuffing results
                    SiteHelpers.ClearCombinedShuffleResults();
                    break;

                case ACT_RESET:
                    // Reset the shuffing results
                    SiteHelpers.ClearCombinedShuffleResults();
                    break;
                }

                // Always get the results
                GetShuffleResults(model);
            }
            finally
            {
                if (dbCasino != null)
                {
                    dbCasino.Dispose();
                }
            }

            return(PartialView("_Randomness_ResultsGraph", model));
        }
Exemple #3
0
        public ActionResult Randomness_PerformAction()
        //================================================================================================================
        // This action is invoked when the card display area is performing an action on the cards.
        //
        // Event Arguments
        //      arg_Action:       Action to be performed
        //      arg_CardPackId:   Unique id of a card pack
        //      arg_ShuffleCount: Number of time to shuffle
        //      arg_SampleSize:   Sample size of cards to shuffle
        //
        // Returns
        //      The card display view
        //================================================================================================================
        {
            // Retrieve the action to be performed and the event arguments
            string action       = !string.IsNullOrEmpty(Request.Params[ARG_ACTION]) ? Request.Params[ARG_ACTION] : "";
            int    cardPackId   = !string.IsNullOrEmpty(Request.Params[ARG_CARD_PACK_ID]) ? int.Parse(Request.Params[ARG_CARD_PACK_ID]) : 0;
            int    shuffleCount = !string.IsNullOrEmpty(Request.Params[ARG_SHUFFLE_COUNT]) ? int.Parse(Request.Params[ARG_SHUFFLE_COUNT]) : 0;
            int    sampleSize   = !string.IsNullOrEmpty(Request.Params[ARG_SAMPLE_SIZE]) ? int.Parse(Request.Params[ARG_SAMPLE_SIZE]) : 0;

            // Create the model
            Randomness model = new Randomness();

            // Perform the action
            SSCasino_DBContext dbCasino = null;

            try
            {
                // Connect the the database
                dbCasino = new SSCasino_DBContext();

                // Perform the action
                switch (action)
                {
                case ACT_SHUFFLE:
                    // Get card packs for the shuffler
                    model.ShuffledPackageFisher.CardPack = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);
                    model.ShuffledPackageNaive.CardPack  = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);

                    // Shuffle the cards
                    model.ShuffledPackageFisher = SiteHelpers.ShuffleCards(model.ShuffledPackageFisher.CardPack, SiteHelpers.ShuffleTypes.FisherYates, shuffleCount, true);
                    model.ShuffledPackageNaive  = SiteHelpers.ShuffleCards(model.ShuffledPackageNaive.CardPack, SiteHelpers.ShuffleTypes.Naive, shuffleCount, true);

                    // Merge the Fisher-Yates and Naive shuffle results
                    SiteHelpers.CombinedShuffleResults = (ICollection <ShuffleResult>)model.ShuffledPackageFisher.ShuffleResults.Concat <ShuffleResult>(model.ShuffledPackageNaive.ShuffleResults).ToList();
                    break;

                case ACT_CHANGE_CARD_PACK:
                    // Get card packs for the shuffler
                    model.ShuffledPackageFisher.CardPack = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);
                    model.ShuffledPackageNaive.CardPack  = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);
                    break;

                case ACT_CHANGE_SAMPLE_SIZE:
                    // Reset the shuffing results
                    // Get card packs based on sample size
                    SiteHelpers.ClearCombinedShuffleResults();
                    model.ShuffledPackageFisher.CardPack = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);
                    model.ShuffledPackageNaive.CardPack  = CreateCardPackModel(dbCasino, cardPackId, (SiteHelpers.SampleSizes)sampleSize);
                    break;

                default:
                    // Get default data for the page
                    ResetRandomnessPage(dbCasino, model);
                    break;
                }

                // Always get the number of shuffles and the aggregated shuffle results
                model.ShuffleResultsData.ResizeWidth  = (int)Session[SiteHelpers.ResultsGraphWidth];
                model.ShuffleResultsData.ResizeHeight = (int)Session[SiteHelpers.ResultsGraphHeight];
                GetShuffleResults(model.ShuffleResultsData);
            }
            finally
            {
                if (dbCasino != null)
                {
                    dbCasino.Dispose();
                }
            }

            return(PartialView("_Randomness_DisplayCBP", model));
        }