Exemplo n.º 1
0
        private void FlagWeight(WeightTable pTbl, int rank1, int rank2, int suit1, int suit2, int suited)
        {
            int card1, card2, index = 0;

            //add indices
            if ((suit1 >= 0) && (suit2 >= 0))
            {
                card1 = rank1 + (suit1 * 13);
                card2 = rank2 + (suit2 * 13);
                if (card1 == card2)
                {
                    return;
                }

                if (card1 < card2)
                {
                    index  = card2 * (card2 - 1) / 2;
                    index += card1;
                }
                else if (card1 > card2)
                {
                    index  = card1 * (card1 - 1) / 2;
                    index += card2;
                }

                pTbl.mWeights[index].mFlag = true;
            }

            if (suit1 == -1)
            {
                for (suit1 = 0; suit1 < 4; suit1++)
                {
                    if ((suited > 0) && (suit2 > 0))
                    {
                        if ((suit1 == suit2) ^ (suited == 1))
                        {
                            continue;
                        }
                    }

                    FlagWeight(pTbl, rank1, rank2, suit1, suit2, suited);
                }
            }
            else if (suit2 == -1)
            {
                for (suit2 = 0; suit2 < 4; suit2++)
                {
                    if (suited > 0)
                    {
                        if ((suit1 == suit2) ^ (suited == 1))
                        {
                            continue;
                        }
                    }

                    FlagWeight(pTbl, rank1, rank2, suit1, suit2, suited);
                }
            }
        }
Exemplo n.º 2
0
        private void GetBoardCards(String boardString, ref long board, ref int count, int max)
        {
            board = 0;
            count = 0;

            int pos = 0;

            while (!boardString.Equals(""))
            {
                pos += boardString.Length;
                TrimLeft(ref boardString, " ,.");
                pos -= boardString.Length;

                if (boardString.Equals(""))
                {
                    break;
                }

                int rank = GetRank(boardString[0]);
                if (rank < 0)
                {
                    throw new ArgumentException("Can't parse rank value", "boardString");
                }

                boardString = boardString.Substring(1);
                pos        += 1;

                if (boardString.Equals(""))
                {
                    break;
                }

                int suit = GetSuit(boardString[0]);
                if (suit < 0)
                {
                    throw new ArgumentException("Can't parse suit value", "boardString");
                }

                boardString = boardString.Substring(1);
                pos        += 1;

                long mask = WeightTable.GetCardMask(suit * 13 + rank);
                if ((mask & board) > 0)
                {
                    throw new ArgumentException("Board contains duplicate cards", "boardString");
                }

                board |= mask;

                count++;
            }

            if (count > max)
            {
                throw new ArgumentOutOfRangeException("boardString", count, "Board contains too many cards");
            }
        }
Exemplo n.º 3
0
        private void GetHoldem6PlusDeadCards(ref long dead)
        {
            dead = 0;

            for (var rank = 0; rank < 4; rank++)
            {
                for (var suit = 0; suit < 4; suit++)
                {
                    long mask = WeightTable.GetCardMask(suit * 13 + rank);

                    dead |= mask;
                }
            }
        }
Exemplo n.º 4
0
        private int ReadHoleCombos(String handString, ref WeightTable pWTbl, ref WeightTable pFoldTbl)
        {
            String subString = "", weightString, originalString;

            originalString = handString;

            pWTbl.Reset();
            pFoldTbl.Reset();

            while (!handString.Equals(""))
            {
                if (handString[0] == '/')
                {
                    if (pWTbl == pFoldTbl)
                    {
                        mConfusedBy = "/";
                        return(-1);
                    }

                    pWTbl = pFoldTbl;
                    TrimLeft(ref handString, " /");
                }

                float weight = 1.0f;

                int limit = FindOneOf(handString, ". ,(/");
                if (limit > 0)
                {
                    subString  = handString.Substring(0, limit);
                    handString = handString.Substring(limit);//ATT

                    if (!handString.Equals("") && handString[0] == '(')
                    {
                        limit        = handString.IndexOf(")");
                        weightString = handString.Substring(1, limit - 1);
                        handString   = handString.Substring(limit + 1);

                        weight = (float)Convert.ToDouble(weightString) / 100.0f;
                    }

                    TrimLeft(ref handString, ", .(");
                }
                else if (limit == 0)
                {
                }
                else
                {
                    subString  = handString;
                    handString = "";
                }

                //process the substring and add the weight indices generated to a list

                //1st char should be a rank

                pWTbl.ResetFlags();

                String originalSubstring = subString;


                int rank11 = 0, rank12 = 0;
                int suit11, suit12;
                int rank21 = 0, rank22 = 0;
                int suit21, suit22;
                int suited1, suited2;

                //suited=1, offsuited=2, both=0
                suited1 = suited2 = 0;

                //default to no specified suit
                suit11 = suit12 = -1;
                suit21 = suit22 = -1;

                if (InterpretHoleString(ref subString, ref rank11, ref rank12, ref suit11, ref suit12, ref suited1) < 0)
                {
                    int gap  = -1;
                    int suit = 0;

                    //special cases
                    if (String.Compare(subString, "scc", true) == 0)
                    {
                        gap  = 1;
                        suit = 0;
                    }
                    else if (String.Compare(subString, "scd", true) == 0)
                    {
                        gap  = 1;
                        suit = 1;
                    }
                    else if (String.Compare(subString, "sch", true) == 0)
                    {
                        gap  = 1;
                        suit = 2;
                    }
                    else if (String.Compare(subString, "scs", true) == 0)
                    {
                        gap  = 1;
                        suit = 3;
                    }
                    else if (String.Compare(subString, "ogc", true) == 0)
                    {
                        gap  = 2;
                        suit = 0;
                    }
                    else if (String.Compare(subString, "ogd", true) == 0)
                    {
                        gap  = 2;
                        suit = 1;
                    }
                    else if (String.Compare(subString, "ogh", true) == 0)
                    {
                        gap  = 2;
                        suit = 2;
                    }
                    else if (String.Compare(subString, "ogs", true) == 0)
                    {
                        gap  = 2;
                        suit = 3;
                    }

                    if (gap >= 1)
                    {
                        for (rank11 = 8; rank11 > 2; rank11--)
                        {
                            FlagWeight(pWTbl, rank11, rank11 - gap, suit, suit, 0);
                        }
                    }
                    else
                    {
                        mConfusedBy = originalSubstring;
                        return(-1);
                    }
                }

                if (subString.Equals(""))
                {
                    FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                    //add all weights with rank11 rank12
                }
                else if (subString[0] == '+')
                {
                    //pairs
                    if (rank11 == rank12)
                    {
                        do
                        {
                            FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                            rank11++;
                            rank12++;
                        } while (rank11 < 13);
                    }
                    else
                    {
                        do
                        {
                            FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                            rank12++;
                        } while (rank12 < rank11);
                    }
                }
                else if (subString[0] == '-')
                {
                    subString = subString.Substring(1);
                    if (InterpretHoleString(ref subString, ref rank21, ref rank22, ref suit21, ref suit22, ref suited2) == 0)
                    {
                        mConfusedBy = originalSubstring;
                        return(-1);
                    }

                    //need to check that suit11 == suit21
                    //need to check that suit12 == suit22
                    //need to check that suited1 == suited2

                    if ((suited1 != suited2) || (suit11 != suit21) || (suit12 != suit22))
                    {
                        mConfusedBy = originalSubstring;
                        return(-1);
                    }

                    //pairs?
                    if (rank11 == rank12)
                    {
                        //1st cards are pairs
                        if (rank21 != rank22)
                        {
                            mConfusedBy = originalSubstring;
                            return(-1);
                        }

                        int step  = (rank21 > rank11) ? 1 : -1;
                        int count = (rank21 - rank11) * step;

                        do
                        {
                            FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                            rank11 += step;
                            rank12  = rank11;
                            count--;
                        } while (count >= 0);
                    }
                    //non pairs so 1st card should be the same ?
                    else if (rank11 == rank21)
                    {
                        //add all combos inbetween rank11, rank12-rank22

                        int step  = (rank22 > rank12) ? 1 : -1;
                        int count = (rank22 - rank12) * step;

                        do
                        {
                            FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                            rank12 += step;
                            count--;
                        } while (count >= 0);
                    }
                    else if ((rank11 - rank12) == (rank21 - rank22))
                    {
                        int step = (rank22 > rank12) ? 1 : -1;
                        do
                        {
                            FlagWeight(pWTbl, rank11, rank12, suit11, suit12, suited1);
                            rank11 += step;
                            rank12 += step;
                        } while ((rank11 - rank21) * step <= 0);
                    }
                    else
                    {
                        mConfusedBy = originalSubstring;
                        return(-1);
                    }
                }

                pWTbl.SetFlaggedWeight(weight);
            }
            ;

            pWTbl.DumpFlagged();


            return(1);
        }