Exemplo n.º 1
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]);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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]);
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }