Пример #1
0
        public static Vector3 Surface(ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float t)
        {
            Vector3 pos = new Vector3();

            switch (n)
            {
            case UnityRandom.Normalization.STDNORMAL:
                pos = GetPointOnCubeSurface(
                    (float)NormalDistribution.Normalize(_rand.NextSingle(true), t),
                    (float)NormalDistribution.Normalize(_rand.NextSingle(true), t),
                    _rand.Next(5));
                break;

            case UnityRandom.Normalization.POWERLAW:
                pos = GetPointOnCubeSurface(
                    (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1),
                    (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1),
                    _rand.Next(5));
                break;

            default:
                pos = GetPointOnCubeSurface(_rand.NextSingle(true), _rand.NextSingle(true), _rand.Next(5));
                break;
            }

            // Move to -1, 1 space as for CIRCLE and SPHERE
            return(new Vector3((2 * pos.x) - 1, (2 * pos.y) - 1, (2 * pos.z) - 1));
        }
Пример #2
0
        // CIRCLE with R=1
        public static Vector2 Circle(ref NPack.MersenneTwister _rand)
        {
            float t    = (float)_rand.Next();
            float _2pi = (float)Math.PI * 2;
            float a    = SpecialFunctions.ScaleFloatToRange(t, 0, _2pi, 0, Int32.MaxValue);

            return(new Vector2((float)Math.Cos(a), (float)Math.Sin(a)));
        }
Пример #3
0
        // INIT
        private void init(int size, DiceType type, ref NPack.MersenneTwister _rand)
        {
            _result    = new int[size];
            _dice_type = type;
            _size      = size;

            for (int i = 0; i < _size; i++)
            {
                // Cast enum to int to get the value
                _result[i] = _rand.Next(1, (int)type);
            }
        }
Пример #4
0
        public static Vector2 Circle(ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float t)
        {
            float r;

            switch (n)
            {
            case UnityRandom.Normalization.STDNORMAL:
                r = SpecialFunctions.ScaleFloatToRange((float)NormalDistribution.Normalize(_rand.NextSingle(true), t), 0, Int32.MaxValue, 0, 1);
                break;

            case UnityRandom.Normalization.POWERLAW:
                r = (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, Int32.MaxValue);
                break;

            default:
                r = (float)_rand.Next();
                break;
            }
            float _2pi = (float)Math.PI * 2;
            float a    = SpecialFunctions.ScaleFloatToRange(r, 0, _2pi, 0, Int32.MaxValue);

            return(new Vector2((float)Math.Cos(a), (float)Math.Sin(a)));
        }
Пример #5
0
        static void CompareStrategies2()
        {
            Random masterRandom = new NPack.MersenneTwister();


            Rules rules = new Rules {
                Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3
            };

            int    max_bet       = 5000;
            double pp_multiplier = 4.0;
            double ev_cutoff     = 0.0015;

            SuperOptStrategy b1 = new SuperOptStrategy(max_bet, ev_cutoff, pp_multiplier);
            OptStrategy      b2 = new OptStrategy(max_bet, ev_cutoff, pp_multiplier);
            BasicStrategy    b3 = new BasicStrategy(max_bet, ev_cutoff, pp_multiplier);

            Game game1 = new Game(rules, b1, pp_multiplier, new NPack.MersenneTwister());
            Game game2 = new Game(rules, b2, pp_multiplier, new NPack.MersenneTwister());
            Game game3 = new Game(rules, b3, pp_multiplier, new NPack.MersenneTwister());

            int    runs     = 0;
            double expected = 0;

            while (true)
            {
                if (runs % 10000 == 0)
                {
                    double total1 = TotalMoney(game1);
                    double total2 = TotalMoney(game2);
                    double total3 = TotalMoney(game3);

                    Console.WriteLine();
                    Console.WriteLine("Runs:           {0}", runs);
                    Console.WriteLine("Expected total: $ {0:0.00}", expected);
                    Console.WriteLine("SuperOpt total: $ {1:0.00} ({2:0.00} c/hand)", b1.GetType(), total1, total1 * 100.0 / (double)runs);
                    Console.WriteLine("Opt total:      $ {1:0.00} ({2:0.00} c/hand)", b2.GetType(), total2, total2 * 100.0 / (double)runs);
                    Console.WriteLine("Basic total:    $ {1:0.00} ({2:0.00} c/hand)", b3.GetType(), total3, total3 * 100.0 / (double)runs);

                    TextWriter writer = new StreamWriter("compare.txt", true);

                    writer.WriteLine(string.Format("{0} {1} {2} {3} {4}", runs, expected, total1, total2, total3));

                    writer.Close();
                }

                int seed = masterRandom.Next();

                game1.Random = new NPack.MersenneTwister(seed);
                game2.Random = new NPack.MersenneTwister(seed);
                game3.Random = new NPack.MersenneTwister(seed);

                game1.ResetShoe();
                game2.ResetShoe();
                game3.ResetShoe();

                int remove_count = masterRandom.Next(84);

                game1.RemoveCards(remove_count);
                game2.RemoveCards(remove_count);
                game3.RemoveCards(remove_count);

                expected += b1.ShoeEV() * b1.Bet(game1) / 100.0;

                game1.StartRound();
                game2.StartRound();
                game3.StartRound();

                game1.DealRound();
                game2.DealRound();
                game3.DealRound();

                runs++;
            }
        }
Пример #6
0
        static void CompareStrategies()
        {
            Random masterRandom = new NPack.MersenneTwister();
            Random random1      = new NPack.MersenneTwister();
            Random random2      = new NPack.MersenneTwister();


            Rules rules = new Rules {
                Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3
            };

            int    max_bet       = 5000;
            double pp_multiplier = 4.0;
            double ev_cutoff     = 0.0015;

            DiffStrategy b1 = new DiffStrategy(
                new SuperOptStrategy(max_bet, ev_cutoff, pp_multiplier),
                new OptStrategy(max_bet, ev_cutoff, pp_multiplier)
                );
            OptStrategy b2 = new OptStrategy(max_bet, ev_cutoff, pp_multiplier);

            Game game1 = new Game(rules, b1, pp_multiplier, random1);
            Game game2 = new Game(rules, b2, pp_multiplier, random2);

            int    runs          = 0;
            double expected      = 0;
            double expected_diff = 0;
            int    diff_count    = 0;

            while (true)
            {
                if (runs % 1000 == 0)
                {
                    double total1 = TotalMoney(game1);
                    double total2 = TotalMoney(game2);

                    Console.WriteLine();
                    Console.WriteLine("Runs:                {0}", runs);
                    Console.WriteLine("Expected total:      $ {0:0.00}", expected);
                    Console.WriteLine("SuperOpt total:      $ {1:0.00} ({2:0.00} c/hand)", b1.GetType(), total1, total1 * 100.0 / (double)runs);
                    Console.WriteLine("Opt total:           $ {1:0.00} ({2:0.00} c/hand)", b2.GetType(), total2, total2 * 100.0 / (double)runs);
                    Console.WriteLine("Different choices:   {0:0} ({1:0.00}%)", diff_count, 100.0 * diff_count / (double)runs);
                    Console.WriteLine("Difference:          $ {0:0.00}", total1 - total2);
                    Console.WriteLine("Expected difference: $ {0:0.00}", expected_diff);

                    TextWriter writer = new StreamWriter("compare.txt", true);

                    writer.WriteLine(string.Format("{0} {1} {2} {3}", runs, expected, TotalMoney(game1), TotalMoney(game2)));

                    writer.Close();
                }

                int seed = masterRandom.Next();

                game1.Random = new NPack.MersenneTwister(seed);
                game2.Random = new NPack.MersenneTwister(seed);

                game1.ResetShoe();
                game2.ResetShoe();

                int remove_count = masterRandom.Next(84);

                game1.RemoveCards(remove_count);
                game2.RemoveCards(remove_count);

                expected += b1.ShoeEV() * b1.Bet(game1) / 100.0;

                game1.StartRound();
                game2.StartRound();

                game1.DealRound();
                game2.DealRound();

                if (b1.IsDiff)
                {
                    expected_diff += game1.Bet * b1.Diff / 100.0;
                    diff_count++;
                    b1.IsDiff = false;
                }

                runs++;
            }
        }
Пример #7
0
        static void CompareStrategies()
        {
            Random masterRandom = new NPack.MersenneTwister();
            Random random1 = new NPack.MersenneTwister();
            Random random2 = new NPack.MersenneTwister();

            Rules rules = new Rules { Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3 };

            int max_bet = 5000;
            double pp_multiplier = 4.0;
            double ev_cutoff = 0.0015;

            DiffStrategy b1 = new DiffStrategy(
                new SuperOptStrategy(max_bet, ev_cutoff, pp_multiplier),
                new OptStrategy(max_bet, ev_cutoff, pp_multiplier)
                );
            OptStrategy b2 = new OptStrategy(max_bet, ev_cutoff, pp_multiplier);

            Game game1 = new Game(rules, b1, pp_multiplier, random1);
            Game game2 = new Game(rules, b2, pp_multiplier, random2);

            int runs = 0;
            double expected = 0;
            double expected_diff = 0;
            int diff_count = 0;

            while (true)
            {
                if (runs % 1000 == 0)
                {
                    double total1 = TotalMoney(game1);
                    double total2 = TotalMoney(game2);

                    Console.WriteLine();
                    Console.WriteLine("Runs:                {0}", runs);
                    Console.WriteLine("Expected total:      $ {0:0.00}", expected);
                    Console.WriteLine("SuperOpt total:      $ {1:0.00} ({2:0.00} c/hand)", b1.GetType(), total1, total1 * 100.0 / (double)runs);
                    Console.WriteLine("Opt total:           $ {1:0.00} ({2:0.00} c/hand)", b2.GetType(), total2, total2 * 100.0 / (double)runs);
                    Console.WriteLine("Different choices:   {0:0} ({1:0.00}%)", diff_count, 100.0 * diff_count / (double)runs);
                    Console.WriteLine("Difference:          $ {0:0.00}", total1 - total2);
                    Console.WriteLine("Expected difference: $ {0:0.00}", expected_diff);

                    TextWriter writer = new StreamWriter("compare.txt", true);

                    writer.WriteLine(string.Format("{0} {1} {2} {3}", runs, expected, TotalMoney(game1), TotalMoney(game2)));

                    writer.Close();
                }

                int seed = masterRandom.Next();

                game1.Random = new NPack.MersenneTwister(seed);
                game2.Random = new NPack.MersenneTwister(seed);

                game1.ResetShoe();
                game2.ResetShoe();

                int remove_count = masterRandom.Next(84);

                game1.RemoveCards(remove_count);
                game2.RemoveCards(remove_count);

                expected += b1.ShoeEV() * b1.Bet(game1) / 100.0;

                game1.StartRound();
                game2.StartRound();

                game1.DealRound();
                game2.DealRound();

                if (b1.IsDiff)
                {
                    expected_diff += game1.Bet * b1.Diff / 100.0;
                    diff_count++;
                    b1.IsDiff = false;
                }

                runs++;
            }
        }
Пример #8
0
        static void CompareStrategies2()
        {
            Random masterRandom = new NPack.MersenneTwister();

            Rules rules = new Rules { Decks = 8, MinBet = 100, MaxBet = 20000, Splits = 3 };

            int max_bet = 5000;
            double pp_multiplier = 4.0;
            double ev_cutoff = 0.0015;

            SuperOptStrategy b1 = new SuperOptStrategy(max_bet, ev_cutoff, pp_multiplier);
            OptStrategy b2 = new OptStrategy(max_bet, ev_cutoff, pp_multiplier);
            BasicStrategy b3 = new BasicStrategy(max_bet, ev_cutoff, pp_multiplier);

            Game game1 = new Game(rules, b1, pp_multiplier, new NPack.MersenneTwister());
            Game game2 = new Game(rules, b2, pp_multiplier, new NPack.MersenneTwister());
            Game game3 = new Game(rules, b3, pp_multiplier, new NPack.MersenneTwister());

            int runs = 0;
            double expected = 0;

            while (true)
            {
                if (runs % 10000 == 0)
                {
                    double total1 = TotalMoney(game1);
                    double total2 = TotalMoney(game2);
                    double total3 = TotalMoney(game3);

                    Console.WriteLine();
                    Console.WriteLine("Runs:           {0}", runs);
                    Console.WriteLine("Expected total: $ {0:0.00}", expected);
                    Console.WriteLine("SuperOpt total: $ {1:0.00} ({2:0.00} c/hand)", b1.GetType(), total1, total1 * 100.0 / (double)runs);
                    Console.WriteLine("Opt total:      $ {1:0.00} ({2:0.00} c/hand)", b2.GetType(), total2, total2 * 100.0 / (double)runs);
                    Console.WriteLine("Basic total:    $ {1:0.00} ({2:0.00} c/hand)", b3.GetType(), total3, total3 * 100.0 / (double)runs);

                    TextWriter writer = new StreamWriter("compare.txt", true);

                    writer.WriteLine(string.Format("{0} {1} {2} {3} {4}", runs, expected, total1, total2, total3));

                    writer.Close();
                }

                int seed = masterRandom.Next();

                game1.Random = new NPack.MersenneTwister(seed);
                game2.Random = new NPack.MersenneTwister(seed);
                game3.Random = new NPack.MersenneTwister(seed);

                game1.ResetShoe();
                game2.ResetShoe();
                game3.ResetShoe();

                int remove_count = masterRandom.Next(84);

                game1.RemoveCards(remove_count);
                game2.RemoveCards(remove_count);
                game3.RemoveCards(remove_count);

                expected += b1.ShoeEV() * b1.Bet(game1) / 100.0;

                game1.StartRound();
                game2.StartRound();
                game3.StartRound();

                game1.DealRound();
                game2.DealRound();
                game3.DealRound();

                runs++;
            }
        }
Пример #9
0
        public static Vector3 Surface(ref NPack.MersenneTwister _rand)
        {
            // Move to -1, 1 space as for CIRCLE and SPHERE
            Vector3 pos = GetPointOnCubeSurface(_rand.NextSingle(true), _rand.NextSingle(true), _rand.Next(5));

            return(new Vector3((2 * pos.x) - 1, (2 * pos.y) - 1, (2 * pos.z) - 1));
        }