예제 #1
0
 public void Update(GameRecord gameRecord)
 {
     if (!gameRecord.IsGameOver)
     {
         return;
     }
     GamesCount++;
     for (int pos = 0; pos < gameRecord.Players.Count; ++pos)
     {
         GameRecord.Player grPlayer = gameRecord.Players[pos];
         Player            myPlayer = FindOrCreatePlayer(grPlayer.Name);
         myPlayer.Update(pos, 1, grPlayer.Result);
     }
 }
예제 #2
0
        public void Update(GameRecord gameRecord)
        {
            int[] hand = new int[7];
            for (int pos = 0; pos < gameRecord.Players.Count; ++pos)
            {
                GameRecord.Player player = gameRecord.Players[pos];
                if (player.Name == _hero)
                {
                    Allocate(pos);
                    _positions[pos].TotalGames++;
                    _positions[pos].TotalResult += gameRecord.Players[pos].Result;
                    int c = 0;
                    Ak  lastHeroAction = Ak.b;
                    foreach (PokerAction action in gameRecord.Actions)
                    {
                        if (action.Kind == Ak.d && (action.Position == pos || action.Position == -1))
                        {
                            int [] cards = StdDeck.Descriptor.GetIndexes(action.Cards);
                            cards.CopyTo(hand, c);
                            c += cards.Length;
                        }
                        if (action.IsPlayerAction() && action.Position == pos)
                        {
                            lastHeroAction = action.Kind;
                        }
                    }
                    if (c == 7)
                    {
                        if (!HeHelper.CanLose(hand))
                        {
                            if (_printNuts)
                            {
                                Console.WriteLine("{0}: {1}", pos, gameRecord.ToGameString());
                            }
                            _positions[pos].TotalNuts++;
                            if (lastHeroAction == Ak.f)
                            {
                                _positions[pos].FoldedNuts++;
                                Debug.Assert(gameRecord.Players[pos].Result < 0);
                                _positions[pos].LostInFoldedNuts += Math.Abs(gameRecord.Players[pos].Result);
                            }
                        }
                    }

                    break;
                }
            }
        }
예제 #3
0
 public void Update(GameRecord gameRecord)
 {
     for (int pos = 0; pos < gameRecord.Players.Count; ++pos)
     {
         GameRecord.Player player = gameRecord.Players[pos];
         if (player.Name == _hero)
         {
             Allocate(pos);
             foreach (PokerAction action in gameRecord.Actions)
             {
                 if (action.Kind == Ak.d && action.Position == pos)
                 {
                     CardSet      pocket     = StdDeck.Descriptor.GetCardSet(action.Cards);
                     HePocketKind pocketKind = HePocket.CardSetToKind(pocket);
                     _positions[pos][(int)pocketKind].count++;
                     _positions[pos][(int)pocketKind].result += player.Result;
                 }
             }
             break;
         }
     }
 }
예제 #4
0
        public void Test_Random()
        {
            int seed = (int)DateTime.Now.Ticks;

            Console.WriteLine("RNG seed {0}", seed);
            Random rng         = new Random(seed);
            int    repetitions = 20000;

            Ak[] actions = new Ak[] { Ak.d, Ak.r, Ak.c, Ak.f };
            for (int r = 0; r < repetitions; ++r)
            {
                GameRecord gr1 = new GameRecord();
                if (rng.Next(0, 2) == 0)
                {
                    gr1.Id = rng.Next().ToString();
                }
                gr1.IsGameOver = rng.Next(0, 2) == 0;

                int playerCount = rng.Next(1, 15);
                for (int p = 0; p < playerCount; ++p)
                {
                    GameRecord.Player player = new GameRecord.Player();
                    player.Name   = "Pl_" + rng.NextDouble().ToString();
                    player.Stack  = (rng.NextDouble() - 0.5) * 1000;
                    player.Blind  = rng.NextDouble() * 1000;
                    player.Result = (rng.NextDouble() - 0.5) * 1000;
                    gr1.Players.Add(player);
                }

                int actionCount = rng.Next(0, 100);
                for (int a = 0; a < actionCount; ++a)
                {
                    PokerAction action = new PokerAction();
                    action.Kind = actions[rng.Next(0, actions.Length)];
                    switch (action.Kind)
                    {
                    case Ak.d:
                        action.Cards    = GenerateRandomCards(rng);
                        action.Position = rng.Next(-1, playerCount);
                        break;

                    case Ak.f:
                        action.Position = rng.Next(0, playerCount);
                        break;

                    case Ak.c:
                        action.Position = rng.Next(0, playerCount);
                        if (rng.Next(0, 2) == 0)
                        {
                            action.Amount = -rng.NextDouble() * 1000;
                        }
                        break;

                    case Ak.r:
                        action.Position = rng.Next(0, playerCount);
                        action.Amount   = rng.NextDouble() * 1000;
                        break;

                    default:
                        Assert.Fail("Unexpected action");
                        break;
                    }
                    gr1.Actions.Add(action);
                }
                string     gs1 = gr1.ToGameString();
                GameRecord gr2 = new GameRecord(gs1);
                string     gs2 = gr2.ToGameString();
                Assert.AreEqual(gs1, gs2);
            }
        }
예제 #5
0
        void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
        {
            if (!gameRecord.IsGameOver)
            {
                return;
            }

            _samplesCount++;
            if (_samplesCount >= _sampleLimit)
            {
                _sampleStep  *= 2;
                _sampleLimit *= 2;
            }

            CurveDescriptor cdKey = new CurveDescriptor();

            for (int pos = 0; pos < gameRecord.Players.Count; ++pos)
            {
                GameRecord.Player player = gameRecord.Players[pos];

                cdKey.Player   = player.Name;
                cdKey.Position = pos;

                CurveDescriptor curveDescriptor;

                if (!_curveDescriptors.TryGetValue(cdKey, out curveDescriptor))
                {
                    if (_autocreateCurveDescriptors)
                    {
                        curveDescriptor = new CurveDescriptor {
                            Player = player.Name, Position = -1
                        };
                        _curveDescriptors.Add(curveDescriptor, curveDescriptor);
                    }
                    else
                    {
                        // No curve for this player and position
                        continue;
                    }
                }


                double total;
                if (!_totalResult.TryGetValue(curveDescriptor, out total))
                {
                    total = 0;
                }
                total += player.Result;
                _totalResult[curveDescriptor] = total;

                curveDescriptor.SamplesCount++;

                // Add to the chart only samples from players from game record,
                // not from all from _totalResult, in order to see where a player
                // stops playing.

                if ((curveDescriptor.SamplesCount % _sampleStep) != 0)
                {
                    continue;
                }

                UpdateChart(curveDescriptor, total);
            }
        }