Beispiel #1
0
        public string ToStringOldCamelUpFormat()
        {
            //White2->Y  Yellow2 Blue3->O Orange3 Green4
            //;;wy;bo;g
            string retval = string.Empty;

            if (GetUnrolledCamelByRank().Length == 0)
            {
                int caseIndex = 0;
                for (int i = 0; i < BoardState.Length; i++)
                {
                    if (BoardState[i] == GameRules.CASE_SEPARATOR)
                    {
                        caseIndex++;
                    }
                    else if (GameRules.IsCharIdentityCamel(BoardState[i]))
                    {
                        retval += GameRules.FullNameCamel(BoardState[i]) + caseIndex;

                        if (BoardState.Length - 1 > i && GameRules.IsCharIdentityCamel(BoardState[i + 1]))
                        {
                            retval += "->" + Char.ToUpper(BoardState[i + 1]) + " ";
                        }

                        retval += " ";
                    }
                }
            }

            foreach (BoardDebug suBoard in m_SubBoard)
            {
                retval += suBoard.ToStringOldCamelUpFormat();
            }
            return(retval + "\t");
        }
Beispiel #2
0
        private Pattern PopulatePatternDict(string aParttern)
        {
            Pattern newPattern = GeneratePatternData(aParttern);

            if (m_Patterns.ContainsKey(newPattern.Id))
            {
                GameRules.Log(newPattern.Id + " " + aParttern);
            }

            m_Patterns.Add(newPattern.Id, newPattern);

            for (int i = 0; i < newPattern.ResultsInList.Count; i++)
            {
                List <string> formatedResults = GameRules.PatternResultToPattern(newPattern.ResultsInList[i]);

                foreach (string formatedResult in formatedResults)
                {
                    if (!m_Patterns.ContainsKey(formatedResult) && !m_PatternsToDiscover.Contains(formatedResult))
                    {
                        m_PatternsToDiscover.Add(formatedResult);
                    }
                }
            }

            return(newPattern);
        }
Beispiel #3
0
        //todo find another place
        public static List <string> PatternResultToPattern(string result)
        {
            List <string>  retval         = new List <string>();
            CamelsMovement camelsMovement = new CamelsMovement(result);
            string         holePattern    = camelsMovement.StartingCamelsInBoard;

            //Before Camel A
            while (!GameRules.IsCharPatternCamel(holePattern.Substring(1, 1)))
            {
                holePattern = holePattern.Substring(1, holePattern.Length - 1);
            }

            //BetweenCamel
            int  camelNb            = 0;
            int  caseSinceLastCamel = 0;
            int  nbCamelsOnLastPile = 1;
            bool isCamelSameCase    = false;

            for (int i = 0; i < holePattern.Length; i++)
            {
                if (holePattern[i] == GameRules.CASE_SEPARATOR)
                {
                    caseSinceLastCamel++;
                    isCamelSameCase = false;
                }
                else if (holePattern[i] != GameRules.TRAP_MINUS && holePattern[i] != GameRules.TRAP_PLUS)
                {
                    if (IsCamelsAreTooFar(nbCamelsOnLastPile, caseSinceLastCamel))
                    {
                        retval.Add(holePattern.Substring(0, i - caseSinceLastCamel));
                        holePattern = holePattern.Substring(i - 1, holePattern.Length - i + 1);
                        i           = 1;
                        camelNb     = 0;
                    }

                    if (!isCamelSameCase)
                    {
                        isCamelSameCase    = true;
                        nbCamelsOnLastPile = 0;
                    }

                    nbCamelsOnLastPile++;

                    //Override Camel
                    StringBuilder sb = new StringBuilder(holePattern);
                    sb[i]       = GameRules.PATTERN_CAMEL_NAME[camelNb++];
                    holePattern = sb.ToString();

                    caseSinceLastCamel = 0;
                }
                else
                {
                    //TODO BUG ICI mauvais pattern ;A;+;+ -> ;A; pas sur si cest la bonne solution
                    caseSinceLastCamel = 0;
                }
            }
            retval.Add(holePattern);
            return(retval);
        }
Beispiel #4
0
        private byte[] GetCamelsNeighbouring(byte aCamel)
        {
            if (!m_Neighbouring.ContainsKey(aCamel))
            {
                List <byte>   camels        = new List <byte>();
                List <byte[]> splittedBoard = SplitBoardByCase();

                for (int i = 0; i < splittedBoard.Count; i++)
                {
                    if (!GameRules.IsByteIdentityCamel(splittedBoard[i][0]))
                    {
                        continue;
                    }

                    if (IsByteArrayContainByte(splittedBoard[i], aCamel))
                    {
                        camels.AddRange(splittedBoard[i]);
                        continue;
                    }
                    int rolledCamelPos = GetCamelPos(aCamel);
                    int nbCaseBetweenSplittedAndRolledCamel = rolledCamelPos - GetCamelPos(splittedBoard[i][0]);

                    if (nbCaseBetweenSplittedAndRolledCamel > 0)
                    {
                        if (!GameRules.IsCamelsAreTooFar(splittedBoard[i].Length, nbCaseBetweenSplittedAndRolledCamel))
                        {
                            camels.AddRange(splittedBoard[i]);
                        }
                        else
                        {
                            camels = new List <byte>();
                        }
                    }
                    else
                    {
                        int lastSplitPos    = Math.Abs(GetCamelPos(splittedBoard[i - 1][0]));
                        int currentSplitPos = Math.Abs(GetCamelPos(splittedBoard[i][0]));

                        if (!GameRules.IsCamelsAreTooFar(splittedBoard[i - 1].Length, currentSplitPos - lastSplitPos))
                        {
                            camels.AddRange(splittedBoard[i]);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                foreach (byte camel in camels)
                {
                    m_Neighbouring.Add(camel, camels.ToArray());
                }
            }

            return(m_Neighbouring[aCamel]);
        }
        private void CheckCamelLandOnAnotherCamel(Camel aCamel, bool aFromMinusTrap)
        {
            if (!aFromMinusTrap)
            {
                for (int i = 0; i < m_Camels.Count; i++)
                {
                    if (m_Camels[i] != aCamel &&
                        m_Camels[i].Pos == aCamel.Pos &&
                        m_Camels[i].CamelOnTop == null)
                    {
                        m_Camels[i].CamelOnTop = aCamel;
                    }
                }
            }
            else
            {
                //TODO faire des tests
                string       camelsOnTop          = aCamel.Id.ToString();
                string       camelsOnPos          = string.Empty;
                List <Camel> orderedStartingCamel = SortCamelInOrderPos(m_Camels);
                Camel        tempCamel            = aCamel.CamelOnTop;

                while (tempCamel != null)
                {
                    camelsOnTop += tempCamel.Id;
                    tempCamel    = tempCamel.CamelOnTop;
                }

                foreach (Camel camel in orderedStartingCamel)
                {
                    if (!camelsOnTop.Contains(camel.Id.ToString()) &&
                        camel.Pos == aCamel.Pos &&
                        !GetCurrentCamel(camel.Id).IsMoving)
                    {
                        camelsOnPos += camel.Id;
                    }
                }

                if (!string.IsNullOrEmpty(camelsOnPos))
                {
                    Camel toppestCamel = aCamel;

                    while (toppestCamel.CamelOnTop != null)
                    {
                        toppestCamel = toppestCamel.CamelOnTop;
                    }

                    toppestCamel.CamelOnTop = GetCurrentCamel(camelsOnPos[camelsOnPos.Length - 1]);

                    if (aCamel.CamelOnTop == null || aCamel.CamelOnTop == aCamel)
                    {
                        GameRules.Log("Peut etre un bug....");
                    }
                }
            }
        }
        private void CamelInfo(List <Camel> aCamels, string aPreLog)
        {
            string log = aPreLog + '\n';

            foreach (Camel camel in aCamels)
            {
                log += string.Format("{0}: {1} -> {2} {3}", camel.Id, camel.Pos, camel.CamelOnTop == null ? "null": camel.CamelOnTop.Id.ToString(), '\n');
            }

            GameRules.Log(log);
        }
        private Ev GenerateShortTermCardEv()
        {
            var highestCamelEv = m_CamelRankManager.GetHighestEv(m_CamelCards);
            Ev  retval         = new Ev
            {
                m_PlayerAction = GameRules.PlayerAction.PickShortTermCard,
                m_Ev           = highestCamelEv.Item2,
                m_Info         = GameRules.FullNameCamel(highestCamelEv.Item1)
            };

            return(retval);
        }
Beispiel #8
0
        public float EVShortTerm(int aCardNb)
        {
            float retval = 0;

            for (int i = 0; i < m_TimeFinish.Length; i++)
            {
                float rankPercentFinish = GetProportionByPosition(i);
                retval += rankPercentFinish * GameRules.GetRankPrice(i, aCardNb);
            }

            return(retval);
        }
Beispiel #9
0
        public string GetRankString()
        {
            byte[] rankByte = GetRank();
            string retval   = string.Empty;

            foreach (var rank in rankByte)
            {
                retval += GameRules.ByteToString(rank);
            }

            return(retval);
        }
Beispiel #10
0
        private bool IsCamelRolled(byte aCamel)
        {
            byte UnrollCamel = GameRules.ByteUnrollToRoll(aCamel);

            foreach (var aByte in BoardState)
            {
                if (aByte == UnrollCamel)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #11
0
        private int GetNbCamelInPattern(string aPattern)
        {
            int nbOfCamelInPattern = 0;

            foreach (char pattern in aPattern)
            {
                if (GameRules.IsCharPatternCamel(pattern))
                {
                    nbOfCamelInPattern++;
                }
            }
            return(nbOfCamelInPattern);
        }
        private List <Camel> SortCamelInOrderPos(List <Camel> aCamel)
        {
            List <Camel> newList         = new List <Camel>();
            List <Camel> remainingCamels = (List <Camel>)Extensions.Clone(aCamel);

            for (int j = 0; j < aCamel.Count; j++)
            {
                char  tempCamelName = 'x';
                Camel higherCamel   = new Camel(tempCamelName, -1, null);

                foreach (Camel currentCamel in remainingCamels)
                {
                    if (newList.Count > 0 && currentCamel.CamelOnTop != null && currentCamel.CamelOnTop.Id == newList[newList.Count - 1].Id)
                    {
                        //prend le camelOnTop du dernier camel entrer
                        higherCamel = currentCamel;
                        break;
                    }
                    else
                    {
                        //Prend le plus grosse pos + sans camel on top
                        if (currentCamel.CamelOnTop == null && currentCamel.Pos > higherCamel.Pos)
                        {
                            higherCamel = currentCamel;
                        }
                    }
                }

                for (int k = 0; k < remainingCamels.Count; k++)
                {
                    if (remainingCamels[k].Id == higherCamel.Id)
                    {
                        remainingCamels.Remove(remainingCamels[k]);
                    }
                }

                if (higherCamel.Id == tempCamelName)
                {
                    GameRules.Log("Didnt find higherCamel");
                }

                newList.Add(higherCamel);
            }

            if (remainingCamels.Count != 0)
            {
                GameRules.Log("We miss a Camel");
            }

            return(newList);
        }
Beispiel #13
0
        public string ToString(Dictionary <char, int> aCamelCards)
        {
            string retval = String.Empty;

            foreach (var camelRank in m_CamelRanks)
            {
                char camel  = char.ToUpper(camelRank.Key);
                int  cardNb = aCamelCards.ContainsKey(camel) ? aCamelCards[camel] : 0;
                retval += string.Format("{0} {1} \tCarteST: {2} \n", camelRank.Value.EVShortTerm(cardNb).ToString("N2"), camelRank,
                                        GameRules.GetRankPrice(0, cardNb));
            }

            return(retval);
        }
Beispiel #14
0
 public string GetRank()
 {
     if (string.IsNullOrWhiteSpace(m_Rank))
     {
         foreach (char token in BoardState)
         {
             if (GameRules.IsCharIdentityCamel(token))
             {
                 m_Rank += token;
             }
         }
     }
     return(m_Rank);
 }
Beispiel #15
0
        private bool IsCamelLandEmptyCase(byte aCamel)
        {
            byte[] rank = GetRank();
            aCamel = GameRules.ByteRollToUnroll(aCamel);
            for (int i = 1; i < rank.Length; i++)
            {
                if (GameRules.ByteRollToUnroll(rank[i]) == aCamel)
                {
                    return(GetCamelPos(aCamel) != GetCamelPos(rank[i - 1]));
                }
            }

            return(true);
        }
Beispiel #16
0
        private byte[] GetUnrolledCamelByRank()
        {
            List <byte> retvalList = new List <byte>();

            foreach (byte token in BoardState)
            {
                if (GameRules.IsByteIdentityCamelUnrolled(token))
                {
                    retvalList.Add(token);
                }
            }

            return(retvalList.ToArray());
        }
Beispiel #17
0
        private void SetAllCamelUnroll()
        {
            StringBuilder tempBoard = new StringBuilder(BoardState);

            for (int i = 0; i < tempBoard.Length; i++)
            {
                if (GameRules.IsCharIdentityCamel(tempBoard[i]))
                {
                    tempBoard[i] = Char.ToUpper(tempBoard[i]);
                }
            }

            BoardState = tempBoard.ToString();
        }
Beispiel #18
0
        public string GetUnrolledCamelByRank()
        {
            string retval = string.Empty;

            foreach (char token in BoardState)
            {
                if (GameRules.IsCharIdentityCamel(token) &&
                    Char.IsUpper(token))
                {
                    retval += token;
                }
            }

            return(retval);
        }
Beispiel #19
0
        public BoardByte(string aBoardId)
        {
            m_SubBoard    = new List <IBoard>();
            BoardState    = GameRules.StringToByte(aBoardId);
            CasesLandedOn = new int[GameRules.CASE_NUMBER];
            Weight        = 1;
            m_DicesHistoriesByte.Add(new List <byte>());

            PopulateNeighbouring();

            if (!GameRules.USE_DICE_NB_IN_DICE_HSITORY)
            {
                PopulateSubBoard();
            }
        }
        public Ev GetEv()
        {
            Dictionary <char, double[]> camelRanks          = GetAverageCamelRankInfo();
            Tuple <char, double>        highestEvFirstPlace = new Tuple <char, double>('x', -10f);
            Tuple <char, double>        highestEvLastPlace  = new Tuple <char, double>('x', -10f);

            foreach (var cr in camelRanks)
            {
                double ev = LongTermCardGuesser.Instance.GetPriceForFirst(cr.Key) * cr.Value[0];
                if (ev > highestEvFirstPlace.Item2)
                {
                    highestEvFirstPlace = new Tuple <char, double>(cr.Key, ev);
                }

                ev = LongTermCardGuesser.Instance.GetPriceForLast(cr.Key) * cr.Value[4];                //todo magic number
                if (ev > highestEvLastPlace.Item2)
                {
                    highestEvLastPlace = new Tuple <char, double>(cr.Key, ev);
                }
            }

            Tuple <char, double> highest;
            bool isFirst;

            if (highestEvFirstPlace.Item2 > highestEvLastPlace.Item2)
            {
                highest = highestEvFirstPlace;
                isFirst = true;
            }
            else
            {
                highest = highestEvLastPlace;
                isFirst = false;
            }

            string info = String.Format("{0} cards pour le {1}, avec une proportion de {2}",
                                        isFirst? "First" : "Last", GameRules.FullNameCamel(highest.Item1), GetTotalProportionAllRankManagers);

            Ev retval = new Ev
            {
                m_PlayerAction = GameRules.PlayerAction.PickLongTermCard,
                m_Ev           = (float)highest.Item2,
                m_Info         = info
            };

            return(retval);
        }
Beispiel #21
0
        public void PopulateSubBoard()
        {
            if (IsCamelReachEnd)
            {
                return;
            }

            byte[] unRollCamel = GetUnrolledCamelByRank();

            if (unRollCamel.Length == 0)
            {
                SetAllCamelUnroll();
                unRollCamel = GetUnrolledCamelByRank();
            }

            List <Pattern> patterns = ToPattern();

            // i = pattern
            // j = movingCamel in pattern
            // k = result
            foreach (Pattern pattern in patterns)
            {
                string unrolledCamels = string.Empty;
                for (int j = 0; j < pattern.NbCamel && j < unRollCamel.Length; j++)
                {
                    byte unrollCamel = unRollCamel[j];
                    if (!pattern.CamelsIdentity.ToUpper().Contains(GameRules.ByteToString(unrollCamel).ToString().ToUpper()))
                    {
                        continue;
                    }

                    List <string> results = pattern.GetResultsForDice(GameRules.ByteToString(unrollCamel));
                    unrolledCamels += GameRules.ByteToString(unRollCamel[j]);
                    for (int k = 0; k < results.Count; k++)
                    {
                        CreateSubboard(results[k], unrollCamel, k + 1);
                    }
                }

                foreach (char unrollCamel in unrolledCamels)
                {
                    unRollCamel = RemoveByteFromBytesArray(unRollCamel, GameRules.StringToByte(unrollCamel));
                }

                unrolledCamels = string.Empty;
            }
        }
Beispiel #22
0
        public void Save(List <Pattern> aPatterns, bool aAppend)
        {
            string save = string.Empty;

            foreach (var pattern in aPatterns)
            {
                save += pattern.ToString() + '\n';
            }

            string path = CompletePath;

            GameRules.Log(path);
            TextWriter tw = new StreamWriter(path, aAppend);

            tw.WriteLine(save);
            tw.Close();
        }
        //METHOD

        public LongTermBoardAnalyser(IBoard aBoard, Action aActionAfterManageBoard)
        {
            //TODO supporter plusieurs board...il y a un bug quand on ajoute boards avec 2 dés roulés
            m_MaxDicesRoll = m_FinishBoard.Values.SelectMany(fb => fb.DicesHistories).Aggregate("", (max, cur) => max.Length > cur.Length ? max : cur).Length;

            ManageBoards(new List <IBoard> {
                aBoard
            });
            if (aActionAfterManageBoard != null)
            {
                aActionAfterManageBoard.Invoke();
            }

            if (m_FinishBoard.Values.Any())
            {
                AddCamelRankManager(m_FinishBoard.Values.ToList());
                m_FinishBoard.Clear();
            }

            while (m_UncompleteBoards.Any() && IsContinueAnalyze())
            {
                try
                {
                    CreateBoards();
                }
                catch (Exception ex)
                {
                    m_IsMemoryFail = true;
                }

                if (m_FinishBoard.Values.Any())
                {
                    AddCamelRankManager(m_FinishBoard.Values.ToList());
                    m_FinishBoard.Clear();
                }

                if (m_IsMemoryFail)
                {
                    GameRules.Log(string.Format("\n\n Je fail at: {0} avec {1} UncompleteBoards \n\n", GetTotalProportionAllRankManagers, m_UncompleteBoards.Count));
                }

                m_UncompleteBoards = new Dictionary <string, IBoard>(m_UnfinishBoard);
                m_UnfinishBoard.Clear();
                m_MaxDicesRoll++;
            }
        }
Beispiel #24
0
        private void SetAllCamelUnroll()
        {
            byte[] tempBoard = new byte[BoardState.Length];
            for (int i = 0; i < tempBoard.Length; i++)
            {
                if (GameRules.IsByteIdentityCamel(BoardState[i]))
                {
                    tempBoard[i] = GameRules.ByteRollToUnroll(BoardState[i]);
                }
                else
                {
                    tempBoard[i] = BoardState[i];
                }
            }

            BoardState = tempBoard;
        }
 private void CalculateWeightAndCasesLandedOn()
 {
     foreach (var board in m_Boards)
     {
         if (board.m_SubBoard.Count == 0)
         {
             m_TotalSubBoardWithWeight += board.Weight;
             for (int j = 0; j < board.CasesLandedOn.Length; j++)
             {
                 m_CasesLandedOn[j] += board.CasesLandedOn[j] * board.Weight;
             }
         }
         else
         {
             GameRules.Log("");
         }
     }
 }
Beispiel #26
0
 private int GetCamelPos(byte aRolledCamel)
 {
     if (!m_Position.ContainsKey(aRolledCamel))
     {
         int retval = 0;
         foreach (byte token in BoardState)
         {
             if (GameRules.IsByteIdentityCamel(token) && GameRules.ByteRollToUnroll(token) == GameRules.ByteRollToUnroll(aRolledCamel))
             {
                 m_Position.Add(aRolledCamel, retval);
             }
             else if (token == GameRules.CASE_SEPARATOR_BYTE)
             {
                 retval++;
             }
         }
     }
     return(m_Position[aRolledCamel]);
 }
Beispiel #27
0
        private char CamelToPattern(char aCamel)
        {
            int camelIndex = 0;

            foreach (char token in BoardState)
            {
                char upperChar = char.ToUpper(token);

                if (upperChar == char.ToUpper(aCamel))
                {
                    break;
                }
                else if (GameRules.IsCharIdentityCamel(upperChar))
                {
                    camelIndex++;
                }
            }

            return(GameRules.PATTERN_CAMEL_NAME[camelIndex]);
        }
Beispiel #28
0
        private char CamelIdentityToPattern(char aIdentity)
        {
            int idIndex      = CamelsIdentity.ToUpper().IndexOf(char.ToUpper(aIdentity));
            int patternIndex = 0;

            foreach (char t in Id)
            {
                if (GameRules.IsCharPatternCamel(t))
                {
                    if (idIndex == patternIndex)
                    {
                        return(t);
                    }

                    patternIndex++;
                }
            }

            return('0');
        }
Beispiel #29
0
        public byte[] GetRank()
        {
            if (m_Rank == null)
            {
                List <byte> tempByte = new List <byte>();
                foreach (byte token in BoardState)
                {
                    if (GameRules.IsByteIdentityCamel(token))
                    {
                        tempByte.Add(token);
                    }
                }

                m_Rank = new byte[tempByte.Count];

                for (int i = 0; i < m_Rank.Length; i++)
                {
                    m_Rank[i] = tempByte[i];
                }
            }
            return(m_Rank);
        }
Beispiel #30
0
        private List <Pattern> ToPattern()
        {
            string board      = string.Empty;
            int    camelIndex = 0;

            foreach (byte token in BoardState)
            {
                if (GameRules.IsByteIdentityCamel(token))
                {
                    board += GameRules.PATTERN_CAMEL_NAME[camelIndex++];
                }
                else
                {
                    board += GameRules.ByteToString(token);
                }
            }

            List <string>  patterns = GameRules.PatternResultToPattern(board);
            List <Pattern> retval   = new List <Pattern>();

            byte[] camels      = GetRank();
            int    camelsIndex = 0;

            foreach (string pattern in patterns)
            {
                if (!PatternGenerator.Instance.Patterns.ContainsKey(pattern))
                {
                    PatternGenerator.Instance.StartGeneratePattern(pattern);
                }

                byte[]  camelIdentity = SubByteArray(camels, camelsIndex, PatternGenerator.Instance.Patterns[pattern].NbCamel);
                Pattern newPattern    = new Pattern(PatternGenerator.Instance.Patterns[pattern], camelIdentity);
                camelsIndex += newPattern.NbCamel;
                retval.Add(newPattern);
            }

            return(retval);
        }