Beispiel #1
0
        protected int EvaulateFunction()
        {
            PatternFunction lFunction = GetCurrentFunction();

            NextToken();
            NextToken();

            PatternFunctionParameters <int> lPatternFunctionParameters = new PatternFunctionParameters <int>();

            while (true)
            {
                PatternToken lToken    = GetCurrentToken();
                int          lInt      = GetTokenInteger();     // in case this is needed later
                char         lVariable = GetTokenVariable();    // in case this is needed later

                NextToken();

                if (lToken == PatternToken.COMMA)
                {
                    continue;
                }

                if (lToken == PatternToken.CLOSE_PARA)
                {
                    break;
                }

                if (lToken == PatternToken.INTEGER)
                {
                    lPatternFunctionParameters.Add(lInt);
                }
                else if (lToken == PatternToken.VARIABLE)
                {
                    Coordinate lCoordinate = OriginPoint + (Pattern.GetLetterLocation(lVariable) - Pattern.Origin).Transform(Transform);

                    lPatternFunctionParameters.Add(Board.Coord.At(lCoordinate.X, lCoordinate.Y));
                }
                else
                {
                    lPatternFunctionParameters.Add(EvaulateExpression());
                }
            }

            // Call function
            return(lFunction(Board, Player, lPatternFunctionParameters));
        }
Beispiel #2
0
        public static PatternActionCode Compile(PatternActionCode patternActionCode, Pattern pattern, string action)
        {
            if (string.IsNullOrEmpty(action))
            {
                return(patternActionCode);
            }

            int lOpenParan  = action.IndexOf('(');
            int lCloseParan = action.IndexOf(')');

            if (lOpenParan < 0)
            {
                patternActionCode.SetErrorMessage("Action line missing an open parentheses");
                return(patternActionCode);
            }

            if (lCloseParan < 0)
            {
                patternActionCode.SetErrorMessage("Action line missing a close parentheses");
                return(patternActionCode);
            }

            string lName   = action.Substring(0, lOpenParan).Trim();
            string lValues = action.Substring(lOpenParan + 1, lCloseParan - lOpenParan - 1).Trim();

            PatternFunctionParameters <Coordinate> lPatternFunctionParameters = new PatternFunctionParameters <Coordinate>();

            if (!string.IsNullOrEmpty(lValues))
            {
                string[] lParameters = lValues.Split(',');

                foreach (string lParameter in lParameters)
                {
                    if (lParameter.Length != 1)
                    {
                        patternActionCode.SetErrorMessage("Invalid action function parameter: " + lParameter);
                        return(patternActionCode);
                    }

                    lPatternFunctionParameters.Add(pattern.GetLetterLocation(lParameter[0]));
                }
            }

            PatternActionFunctions.PatternActionFunction lPatternActionFunction = PatternActionFunctions.GetFunction(lName, lPatternFunctionParameters.Count);

            if (lPatternActionFunction == null)
            {
                patternActionCode.SetErrorMessage("Unknown action function: " + lName + " with " + lPatternFunctionParameters.Count + " parameters");
                return(patternActionCode);
            }

            patternActionCode.Add(new PatternActionOperand(lPatternActionFunction, lPatternFunctionParameters, pattern.Origin));

            return(patternActionCode);
        }
Beispiel #3
0
        public void Execute(GoBoard goBoard, Coordinate originPoint, int transform, MoveList moves)
        {
            PatternFunctionParameters <int> lPatternFunctionParameters = new PatternFunctionParameters <int>();

            foreach (Coordinate lCoordinate in Parameters)
            {
                Coordinate lCoordinate2 = originPoint + (lCoordinate - Origin).Transform(transform);

                lPatternFunctionParameters.Add(goBoard.Coord.At(lCoordinate2.X, lCoordinate2.Y));
            }

            Function(moves, lPatternFunctionParameters);
        }