public static int IsSafeXMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
        {
            Color lPlayer = player.Opposite;

            return(((goBoard.IsLegal(parameters[0], lPlayer)) &&
                    (LibertyCountAfterMove(goBoard, lPlayer, parameters[0]) > 1)) ? TRUE : FALSE);
        }
        public static void Replace(MoveList moves, PatternFunctionParameters <int> patternFunctionParameters)
        {
            double lValue = moves.GetValue(patternFunctionParameters[0]);

            moves.RemoveMove(patternFunctionParameters[0]);
            moves.SetMinValue(patternFunctionParameters[1], lValue);                    // redistribution	(limited)
        }
Beispiel #3
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 #4
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);
        }
Beispiel #5
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));
        }
        public static bool Execute(string method, MoveList moves, PatternFunctionParameters <int> patternFunctionParameters)
        {
            PatternActionFunction lFunction = GetFunction(method, patternFunctionParameters.Count);

            if (lFunction == null)
            {
                return(false);
            }

            try
            {
                lFunction(moves, patternFunctionParameters);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
 public static int IsKo(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.IsKo(parameters[0]) ? TRUE : FALSE);
 }
 public static int IsSuicideXMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.IsSuicide(parameters[0], player.Opposite) ? TRUE : FALSE);
 }
        public static int IsLegalXMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
        {
            Color lPlayer = player.Opposite;

            return((goBoard.IsLegal(parameters[0], lPlayer)) ? TRUE : FALSE);
        }
 public static int IsLegalOMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return((goBoard.IsLegal(parameters[0], player)) ? TRUE : FALSE);
 }
 public static int Unknown(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.GetSafetyStatus(parameters[0]).IsUndecided ? TRUE : FALSE);
 }
 public static int SameString(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.IsSameString(parameters[0], parameters[1]) ? TRUE : FALSE);
 }
 public static void AntiSuji(MoveList moves, PatternFunctionParameters <int> patternFunctionParameters)
 {
     moves.RemoveMove(patternFunctionParameters[0]);
 }
 public static void Test(MoveList moves, PatternFunctionParameters <int> patternFunctionParameters)
 {
     Console.Error.WriteLine("DEBUG: Test Action!");
 }
 public static int LibertyCountAfterMove(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(LibertyCountAfterMove(goBoard, player, parameters[0]));
 }
 public static int Safe(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.GetSafetyStatus(parameters[0]).IsAlive ? TRUE : FALSE);
 }
 public static int LibertyCount(GoBoard goBoard, Color player, PatternFunctionParameters <int> parameters)
 {
     return(goBoard.GetBlockLibertyCount(parameters[0]));
 }
Beispiel #18
0
 public PatternActionOperand(PatternActionFunctions.PatternActionFunction function, PatternFunctionParameters <Coordinate> parameters, Coordinate origin)
 {
     Function   = function;
     Parameters = parameters;
     Origin     = origin;
 }