コード例 #1
0
 public PokerAction(Ak kind, int position, double amount, string cards)
 {
     Kind     = kind;
     Position = position;
     Amount   = amount;
     Cards    = cards;
 }
コード例 #2
0
 private void VerifyActionRecord(int pos, Ak kind, string cards, double amount, PokerAction ar)
 {
     Assert.AreEqual(pos, ar.Position);
     Assert.AreEqual(kind, ar.Kind);
     Assert.AreEqual(cards, ar.Cards);
     Assert.AreEqual(amount, ar.Amount);
 }
コード例 #3
0
 public ActionTreeNode FindChildByAction(Ak actionKind)
 {
     for (int c = 0; c < Children.Count; ++c)
     {
         if (Children[c].ActionKind == actionKind)
         {
             return(Children[c]);
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: NutsReport.cs プロジェクト: ivan-alles/poker-acpc
        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;
                }
            }
        }
コード例 #5
0
        int ActionPreference(Ak a)
        {
            switch (a)
            {
            case Ak.c:
                return(100);

            case Ak.r:
                return(50);

            case Ak.f:
                return(0);
            }
            Debug.Assert(false);
            return(-1);
        }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: ivan-alles/poker-acpc
 private bool ProcessAction(Ak ak)
 {
     if (_gameState.IsPlayerActing(_position))
     {
         ShowMessage("Not your turn");
         return false;
     }
     List<Ak> allowedActions = _gameState.GetAllowedActions(GameDef);
     if (!allowedActions.Contains(ak))
     {
         ShowMessage(string.Format("Wrong action: '{0}', expected: '{1}'", ak, ActionKindListToString(allowedActions)));
         return false;
     }
     PokerAction pa = new PokerAction();
     pa.Kind = ak;
     pa.Position = _gameState.CurrentActor;
     if(ak == Ak.r)
     {
         pa.Amount = GameDef.BetStructure[_gameState.Round];
     }
     _gameRecord.Actions.Add(pa);
     _gameState.UpdateByAction(pa, GameDef);
     return true;
 }
コード例 #7
0
        }//receptor timeseries

        /// <summary>
        ///Output of microscale flow-field at receptors points into GRAL_Meteozeitreihe.dat
        /// </summary>
        public void WriteMicroscaleFlowfieldReceptors()
        {
            if ((Program.ReceptorsAvailable > 0) && (Program.FlowFieldLevel > 0))
            {
                try
                {
                    CultureInfo ic = CultureInfo.InvariantCulture;

                    List <string> content = new List <string>();

                    //read the existing header and content up to the recent Program.IWET - prevent errors if a user restarts at a previous weather situation
                    if (Program.IWET > 1 && File.Exists("GRAL_Meteozeitreihe.dat"))
                    {
                        using (FileStream wr = new FileStream("GRAL_Meteozeitreihe.dat", FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            using (StreamReader read = new StreamReader(wr))
                            {
                                // read Header lines
                                try
                                {
                                    string header = read.ReadLine();
                                    if (header.EndsWith("+")) // additional header lines for all receptors
                                    {
                                        content.Add(header);
                                        content.Add(read.ReadLine()); // Name
                                        content.Add(read.ReadLine()); // X
                                        content.Add(read.ReadLine()); // Y
                                        content.Add(read.ReadLine()); // Z
                                    }
                                    else if (header.Contains("U"))    // old one line header, otherwise very old and no header
                                    {
                                        content.Add(header);
                                    }
                                }
                                catch
                                {
                                    //content.Add("0");
                                }

                                for (int ianz = 1; ianz <= Program.IWET; ianz++)
                                {
                                    try
                                    {
                                        content.Add(read.ReadLine()); // add existing data
                                    }
                                    catch
                                    {
                                        content.Add("0"); // add 0 if a user continues with a later weather situations
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // create a new header
                        content.Add("U,V,SC,BLH+");
                        string[] headerLine = ReceptorMeteoCreateMeteoHeader(4);
                        foreach (string h in headerLine)
                        {
                            content.Add(h);
                        }
                    }

                    using (StreamWriter write = new StreamWriter("GRAL_Meteozeitreihe.dat", false))
                    {
                        // write header and entire file up to (Program.IWET - 1)
                        for (int ianz = 0; ianz < content.Count; ianz++)
                        {
                            write.WriteLine(content[ianz]);
                        }

                        for (int ianz = 1; ianz <= Program.ReceptorNumber; ianz++)
                        {
                            if (Program.Topo == 1 && Program.AKL_GRAMM[0, 0] != 0) // 11.9.2017 Kuntner Write Local SCL
                            {
                                int I_SC = (int)((Program.ReceptorX[ianz] - Program.GrammWest) / Program.DDX[1]) + 1;
                                int J_SC = (int)((Program.ReceptorY[ianz] - Program.GrammSouth) / Program.DDY[1]) + 1;

                                if (I_SC >= 0 && I_SC <= Program.NX1 && J_SC >= 0 && J_SC <= Program.NY1)
                                {
                                    write.Write(Program.UK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                                "\t" + Program.VK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                                "\t" + Program.SC_Gral[I_SC][J_SC].ToString(ic) +
                                                "\t" + Convert.ToInt32(Program.BdLayHeight).ToString(ic) + "\t");
                                }
                                else // invalid indices -> write mean SCL or meteogpt SCL
                                {
                                    int Ak;
                                    if (Program.StabClassGramm > 0)
                                    {
                                        Ak = Program.StabClassGramm;
                                    }
                                    else
                                    {
                                        Ak = Program.StabClass;
                                    }

                                    write.Write(Program.UK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                                "\t" + Program.VK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                                "\t" + Ak.ToString(ic) +
                                                "\t" + Convert.ToInt32(Program.BdLayHeight).ToString(ic) + "\t");
                                }
                            }
                            else // original format without SCL
                            {
                                int Ak = Program.StabClass;
                                write.Write(Program.UK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                            "\t" + Program.VK[Program.ReceptorIIndFF[ianz]][Program.ReceptorJIndFF[ianz]][Program.ReceptorKIndFF[ianz]].ToString("0.00", ic) +
                                            "\t" + Ak.ToString(ic) +
                                            "\t" + Convert.ToInt32(Program.BdLayHeight).ToString(ic) + "\t");
                            }
                        }
                    }
                }
                catch { }

                for (int iq = 0; iq < Program.SourceGroups.Count; iq++)
                {
                    for (int ianz = 1; ianz <= Program.ReceptorNumber; ianz++)
                    {
                        Program.ReceptorConc[ianz][iq] = 0;
                    }
                }
            }
        }//microscale flow-field at receptors
コード例 #8
0
 /// <summary>
 /// Converts a character to Ak. If a character is invalid, false is returned.
 /// </summary>
 public static bool AkFromChar(char ch, out Ak kind)
 {
     kind = _actionCharToKindMap[ch];
     return(kind != (Ak)(-1));
 }
コード例 #9
0
 public static bool IsDealerAction(Ak kind)
 {
     return(kind == Ak.d);
 }
コード例 #10
0
 public static bool IsPlayerAction(Ak kind)
 {
     return(kind >= Ak.f);
 }
コード例 #11
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);
            }
        }