示例#1
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));
        }
示例#2
0
        public ActionResult CardShuffler_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_ShuffleType:  Shuffle algorithm
        //
        // Returns
        //      The card display view
        //================================================================================================================
        {
            CardPack cardPack = null;

            // Retrieve the action to be performed and the assigned card pack
            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;

            // Connect to the database and perform the action
            SSCasino_DBContext dbCasino = null;

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

                // Perform the action
                switch (action)
                {
                case ACT_SHUFFLE:
                    // Retrieve an unshuffled pack of cards
                    cardPack = CreateCardPackModel(dbCasino, cardPackId);

                    // Shuffle the cards
                    int             shuffleType     = !string.IsNullOrEmpty(Request.Params[ARG_SHUFFLE_TYPE]) ? int.Parse(Request.Params[ARG_SHUFFLE_TYPE]) : 1;
                    int             shuffleCount    = !string.IsNullOrEmpty(Request.Params[ARG_SHUFFLE_COUNT]) ? int.Parse(Request.Params[ARG_SHUFFLE_COUNT]) : 1;
                    ShuffledPackage shuffledPackage = SiteHelpers.ShuffleCards(cardPack, (SiteHelpers.ShuffleTypes)shuffleType, shuffleCount, false);
                    cardPack = shuffledPackage.CardPack;
                    break;

                case ACT_CHANGE_CARD_PACK:
                    // Retrieve an unshuffled pack of cards
                    cardPack = CreateCardPackModel(dbCasino, cardPackId);
                    break;

                default:
                    // Get the default card pack
                    cardPack = CreateCardPackModel(dbCasino);
                    break;
                }
            }
            finally
            {
                if (dbCasino != null)
                {
                    dbCasino.Dispose();
                }
            }

            return(PartialView("_CardShuffler_DisplayCBP", cardPack.CardDeck));
        }