Exemplo n.º 1
0
        public void Go(IRoundStrategy player)
        {
            string line;

            do
            {
                var sets = Dealer.Deal().ToList();
                //var set = Dealer.GetCards("SA HT CQ D2 H3 H4 S5 S6 H5 H7 HJ HQ HK");
                //sets[0] = set;
                var playerSimple = new SimpleRoundStrategy();

                var mlRounds     = player.GetBestRoundsWithScore(sets[0], 10).ToList();
                var simpleRounds = playerSimple.GetBestRounds(sets[0], 10).ToList();

                for (var i = 0; i < mlRounds.Count; i++)
                {
                    System.Console.WriteLine($"{mlRounds[i].Value,-4:0} {mlRounds[i].Key}");
                    System.Console.WriteLine($"     {simpleRounds[i]}");
                    System.Console.WriteLine("======================");
                }

                line = System.Console.ReadLine();
                System.Console.Clear();
            } while (line != "q");
        }
Exemplo n.º 2
0
        public void Four_players_should_have_scores_cancel_out()
        {
            var strategy = new SimpleRoundStrategy();
            var sets     = Dealer.Deal().ToArray();

            var calculator = new TaiwaneseScoreCalculator(new PokerStrengthStrategy());
            var scores     = calculator.GetScores(sets.Select(strategy.GetBestRound).ToList());

            Assert.Equal(0, scores.Sum(kv => kv.Value));
        }
Exemplo n.º 3
0
        protected override Dictionary <Round, int> GetPrediction(IList <Card> cards)
        {
            var rounds = new SimpleRoundStrategy().GetBestRounds(cards, int.MaxValue).ToList();
            var result = new Dictionary <Round, int>();

            for (var i = 0; i < rounds.Count; i++)
            {
                var predict = Oracle.Predict(new RoundData <float>(rounds[i], i));
                result.Add(rounds[i], (int)Math.Round(predict.Score));
            }

            return(result);
        }
Exemplo n.º 4
0
        public void Two_players_should_have_scores_cancel_out()
        {
            var strategy = new SimpleRoundStrategy();
            var sets     = Dealer.Deal().Take(2).ToArray();

            var roundA = strategy.GetBestRound(sets[0]);
            var roundB = strategy.GetBestRound(sets[1]);

            var calculator = new TaiwaneseScoreCalculator(new PokerStrengthStrategy());

            calculator.GetScore(roundA, roundB, out int scoreA, out var scoreB);

            Assert.Equal(scoreA, -scoreB);
            Assert.Equal(0, scoreA + scoreB);
        }
        protected override Dictionary <Round, int> GetPrediction(IList <Card> cards)
        {
            VBuffer <int> keys = default;

            Oracle.OutputSchema.FirstOrDefault(c => c.Name == "PredictedLabel").GetKeyValues(ref keys);
            var labelsArray = keys.DenseValues().ToArray();

            var rounds = new SimpleRoundStrategy().GetBestRounds(cards, int.MaxValue).ToList();
            var result = new Dictionary <Round, int>();

            for (var i = 0; i < rounds.Count; i++)
            {
                var predict = Oracle.Predict(new RoundData <int>(rounds[i], i));
                result.Add(rounds[i], labelsArray[predict.Score.ToList().IndexOf(predict.Score.Max())]);
            }

            return(result);
        }
Exemplo n.º 6
0
        public void Simulation(string modelPath)
        {
            var mlStrategy     = new RegressionMlStrategy(modelPath);
            var simpleStrategy = new SimpleRoundStrategy();
            var scoreKeeper    = new TaiwaneseScoreCalculator(simpleStrategy.GameHandsManager.StrengthArbiter);

            string line;

            do
            {
                var sets = Dealer.Deal().ToList();

                var round1 = mlStrategy.GetBestRound(sets[0]);
                var round0 = simpleStrategy.GetBestRound(sets[0]);
                var round2 = simpleStrategy.GetBestRound(sets[1]);
                var round3 = simpleStrategy.GetBestRound(sets[2]);
                var round4 = simpleStrategy.GetBestRound(sets[3]);

                var rounds = new[] { round1, round2, round3, round4 };
                var result = scoreKeeper.GetScores(rounds).ToList();

                for (var i = 0; i < 4; i++)
                {
                    System.Console.WriteLine($"{result[i].Key}\n{result[i].Value}");
                }

                System.Console.WriteLine("---------------------------");
                rounds = new[] { round0, round2, round3, round4 };
                result = scoreKeeper.GetScores(rounds).ToList();

                for (var i = 0; i < 4; i++)
                {
                    System.Console.WriteLine($"{result[i].Key}\n{result[i].Value}");
                }

                line = System.Console.ReadLine();
                System.Console.Clear();
            } while (line != "q");
        }
Exemplo n.º 7
0
        public void Go(string outFileName, int recordNeeded = 1_000_000)
        {
            var count       = 0;
            var strategy    = new SimpleRoundStrategy();
            var scoreKeeper = new TaiwaneseScoreCalculator(strategy.GameHandsManager.StrengthArbiter);
            var timer       = new Stopwatch();

            timer.Start();
            Writer = new StreamWriter(outFileName, true);

            var gamesNeeded = Math.Max(1, (int)Math.Round(recordNeeded / 4.0 / Math.Pow(BestRoundsToTake, 4)) + 1);

            Parallel.For(0, gamesNeeded, _ =>
            {
                var players      = Dealer.Deal().ToList();
                var playerRounds = players.Select(p => strategy.GetBestRounds(p, BestRoundsToTake).ToList()).ToList();
                for (var p1 = 0; p1 < playerRounds[0].Count; p1++)
                {
                    for (var p2 = 0; p2 < playerRounds[1].Count; p2++)
                    {
                        for (var p3 = 0; p3 < playerRounds[2].Count; p3++)
                        {
                            for (var p4 = 0; p4 < playerRounds[3].Count; p4++)
                            {
                                //var result = scoreKeeper.GetScores(new[] {playerRounds[0][p1], playerRounds[1][p2], playerRounds[2][p3], playerRounds[3][p4]}.ToList()).ToList();
                                var result = scoreKeeper.GetScoresWithRoundWeight(new[] { playerRounds[0][p1], playerRounds[1][p2], playerRounds[2][p3], playerRounds[3][p4] }.ToList()).ToList();
                                lock (this)
                                {
                                    for (var i = 0; i < result.Count; i++)
                                    {
                                        OutputResult(Writer, result, i, new int[] { p1, p2, p3, p4 });
                                    }
                                    count += 4;
                                    if (count % 10_000 == 0)
                                    {
                                        Console.WriteLine($"count {count}, time: {timer.Elapsed}");
                                    }
                                }