Exemplo n.º 1
0
 public void Post([FromBody] Classes.Mutant m)
 {
     if (m == null)
     {
         this.HttpContext.Response.StatusCode = 500;
     }
     else
     {
         if (m.DNA.Length > 0)
         {
             functions _f = new functions();
             if (_f.isMutant(m))
             {
                 this.HttpContext.Response.StatusCode = 200;
             }
             else
             {
                 this.HttpContext.Response.StatusCode = 403;
             }
         }
         else
         {
             this.HttpContext.Response.StatusCode = 500;
         }
     }
 }
Exemplo n.º 2
0
        public bool isMutant(Classes.Mutant _person)
        {
            bool ismutant     = false;
            bool invalidValue = false;

            char[,] mDNA = new char[maxH(_person.DNA), maxW(_person.DNA)];
            int col = 0;

            foreach (string s in _person.DNA)
            {
                int line = 0;
                foreach (char c in s.ToCharArray())
                {
                    if (InputValid(c))
                    {
                        mDNA[col, line] = c;
                    }
                    else
                    {
                        invalidValue = true;
                        break;
                    }
                    line++;
                }
                col++;
            }
            if (!invalidValue)
            {
                int validDNA = 0;
                int H        = maxH(_person.DNA);
                int W        = maxW(_person.DNA);

                //horizontal test
                validDNA = validDNA + HorizontalTest(H, W, mDNA);

                //vertical test
                validDNA = validDNA + VerticalTest(H, W, mDNA);

                //diagonal test
                validDNA = validDNA + DiagonalTest(H, W, mDNA);

                if (validDNA > 2)
                {
                    ismutant = true;
                }
            }

            return(ismutant);
        }