示例#1
0
        private Pattern GeneratePatternData(string aPattern)
        {
            CamelsMovement camelsMovement = new CamelsMovement(aPattern);
            Pattern        pattern        = new Pattern(aPattern, camelsMovement.GetCamelsResults());

            return(pattern);
        }
示例#2
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);
        }