public static JToken JsonCommand(JToken jtoken)
        {
            JsonValidation.ValidateJTokenRuleChecker(jtoken);

            //If object is a Board...
            try //Try validating board, then Score
            {
                JsonValidation.ValidateBoard(jtoken);
                return(JToken.Parse(RuleChecker.Score(jtoken.ToObject <string[][]>()).ToString()));
            }
            catch //figure out why board is invalid if this is a board
            {
                if (jtoken.Count() > 2)
                {
                    JsonValidation.ValidateBoard(jtoken);
                }
            }

            JsonValidation.ValidateStone(jtoken.ElementAt(0));
            JsonValidation.ValidatePass(jtoken.ElementAt(1));
            //If object is [Stone, Move] and Move is "pass"
            try
            {
                if (jtoken.ElementAt(1).ToObject <string>() == "pass") //Pass this to RuleChecker
                {
                    return(JToken.Parse(JsonConvert.SerializeObject(
                                            RuleChecker.Pass())));
                }
            }
            catch { }

            //If object is [Stone, Move] and Move is a Play
            JsonValidation.ValidatePlay(jtoken.ElementAt(1));
            JsonValidation.ValidatePoint(jtoken.ElementAt(1).ElementAt(0));
            JsonValidation.ValidateBoards(jtoken.ElementAt(1).ElementAt(1));
            try
            {
                return(JToken.Parse(JsonConvert.SerializeObject(
                                        RuleChecker.Play(
                                            jtoken.ElementAt(0).ToObject <string>(),
                                            jtoken.ElementAt(1).ElementAt(0).ToObject <string>(),
                                            jtoken.ElementAt(1).ElementAt(1).ToObject <string[][][]>()))));
            }
            catch
            {
                return(JToken.Parse(JsonConvert.SerializeObject(false)));
            }

            throw new InvalidJsonInputException("Unrecognized JSONCommand passed to RuleCheckerWrapper");
        }
        public static JToken JsonCommand(JToken jtoken)
        {
            JsonValidation.ValidateJTokenRuleChecker(jtoken);

            //If object is a Board...
            if (jtoken.Count() > 2)
            {
                return(JToken.Parse(RuleChecker.Score(jtoken.ToObject <string[][]>()).ToString()));
            }

            //If object is [Stone, Move] and Move is "pass"
            try
            {
                if (jtoken.ElementAt(1).ToObject <string>() == "pass") //Pass this to RuleChecker
                {
                    return(JToken.Parse(JsonConvert.SerializeObject(
                                            RuleChecker.Pass())));
                }
            }
            catch { }

            //If object is [Stone, Move] and Move is a Play
            JsonValidation.ValidatePlay(jtoken.ElementAt(1));
            try
            {
                return(JToken.Parse(JsonConvert.SerializeObject(
                                        RuleChecker.Play(
                                            jtoken.ElementAt(0).ToObject <string>(),                        //Stone
                                            jtoken.ElementAt(1).ElementAt(0).ToObject <string>(),           //Point
                                            jtoken.ElementAt(1).ElementAt(1).ToObject <string[][][]>())))); //Boards
            }
            catch (RuleCheckerException)
            {
                return(JToken.Parse(JsonConvert.SerializeObject(false)));
            }

            throw new InvalidJsonInputException("Unrecognized JSONCommand passed to RuleCheckerAdapter");
        }
Пример #3
0
 public static bool Pass()
 {
     return(RuleChecker.Pass());
 }