Example #1
0
        private void btn_Centri_Click(object sender, EventArgs e)
        {
            int nr_neuroni = 10;

            int distanta = 600 / nr_neuroni;

            neuroni = new Punct[nr_neuroni, nr_neuroni];
            for (int i = 0; i < nr_neuroni; i++)
            {
                for (int j = 0; j < nr_neuroni; j++)
                {
                    neuroni[i, j] = new Punct((i * distanta) - 270, (j * distanta) - 270, Color.Blue); // normal
                    //neuroni[i, j] = new Punct((i * distanta) - 270, 290, Color.Blue);   // dintr-o latura
                    // neuroni[i, j] = new Punct(-290, -290, Color.Blue);   // dintr-un punct



                    g.FillRectangle((new SolidBrush(neuroni[i, j].color)), neuroni[i, j].x, neuroni[i, j].y, 1, 1);
                }
            }

            drawLines(Color.Blue);
            Thread.Sleep(1500);

            Actualizeaza();
        }
Example #2
0
        static void updateMatriceCost(Marcaj m, Punct p)
        {
            miAtacuriComputer[p.x, p.y] = 1;

            switch (m)
            {
            case Marcaj.aer:    //A
            {
                miTablaCost[p.x, p.y] = 0;
                updateCeluleAdiacente(-10, p);
            } break;

            case Marcaj.avion:    // /
            {
                miTablaCost[p.x, p.y] = 0;
                updateCeluleAdiacente(100, p);
            } break;

            case Marcaj.cabina:    // *
            {
                miTablaCost[p.x, p.y] = 200;
                updateCeluleAdiacente(200, p);
            } break;
            }
        }
        public IHttpActionResult PutPunct(int id, Punct punct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != punct.Id)
            {
                return(BadRequest());
            }

            db.Entry(punct).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PunctExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
 public TextUnit(Type type, string stringVal = "", Punct punctVal = default, T refObj = default)
 {
     this.type      = type;
     this.stringVal = stringVal;
     this.punctVal  = punctVal;
     this.refObj    = refObj;
 }
Example #5
0
        static void updateCeluleAdiacente(int val, Punct pct)
        {
            for (int i = pct.x - 1; i <= pct.x + 1; i++)
            {
                for (int j = pct.y - 1; j <= pct.y + 1; j++)
                {
                    if (isValidCoordinate(i, j) && ((i != pct.x) || (j != pct.y)))
                    {
                        miTablaCost[i, j] += val;
                    }
                }
            }
            //ToDo vezi colturile
            //V2
            //if ((pct.x - 1 >= 0) && (pct.y - 1 >=0)) TablaCost[pct.x -1,pct.y -1] += val;//stanga sus
            //if ((pct.x - 1 >= 0) && (pct.y >= 0))    TablaCost[pct.x - 1, pct.y] += val;//deasupra
            //if ((pct.x - 1 >= 0) && (pct.y + 1 <=9)) TablaCost[pct.x - 1, pct.y + 1] += val;//dreapta sus
            //if ((pct.x >= 0) && (pct.y + 1 <= 9)) TablaCost[pct.x , pct.y + 1] += val;//dreapta
            //if ((pct.x + 1 <=9) && (pct.y + 1 <=9)) TablaCost[pct.x + 1, pct.y + 1] += val;//dreapta jos
            //if ((pct.x + 1 <= 9) && (pct.y  <= 9)) TablaCost[pct.x + 1, pct.y ] += val;//jos
            //if ((pct.x + 1 <= 9) && (pct.y-1 <= 9)&&(pct.y-1 >=0)) TablaCost[pct.x + 1, pct.y - 1 ] += val;//stanga jos
            //if ((pct.x  >= 0) && (pct.y - 1 >= 0)) TablaCost[pct.x , pct.y - 1] += val;//stanga

            //afiseaza
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    // char var = TablaCost[i, j];
                    Console.Write(miTablaCost[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
Example #6
0
        public Triunghi(Punct point1, Punct point2, Punct point3)
        {
            this.P1 = point1;

            this.P2 = point2;

            this.P3 = point3;
        }
Example #7
0
        public Segment(Punct leftPoint, Punct rightPoint)
        {
            this.P2 = new Punct();


            this.P1 = leftPoint;

            this.P2 = rightPoint;
        }
Example #8
0
        public Punct[] GetAllPoints()
        {
            Punct[] points = new Punct[3];

            points[0] = this.P1;
            points[1] = this.P2;
            points[2] = this.P3;

            return(points);
        }
Example #9
0
 /// <summary>
 /// Verifica daca locatia data a fost atacata in unul din atacurile anterioare
 /// </summary>
 /// <param name="pct">Coordonatele punctului de verificat</param>
 /// <returns></returns>
 static bool isValidShot(Punct pct)
 {
     if (miAtacuriComputer[pct.x, pct.y] == 1)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public IHttpActionResult GetPunct(int id)
        {
            Punct punct = db.Puncts.Find(id);

            if (punct == null)
            {
                return(NotFound());
            }

            return(Ok(punct));
        }
        public IHttpActionResult PostPunct(Punct punct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Puncts.Add(punct);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = punct.Id }, punct));
        }
Example #12
0
 static void updateCeluleAdiacente(int val, Punct p)
 {
     if ((p.x > 0) && (p.y > 0) && (p.x < 9) && (p.y < 9))
     {
         for (int i = p.x - 1; i <= p.x + 1; i++)
         {
             for (int j = p.x - 1; j <= p.x + 1; j++)
             {
                 TablaCost[i, j] -= 10;//scade valoarea casutelor adiacente cu 1
             }
         }
     }
 }
        public IHttpActionResult DeletePunct(int id)
        {
            Punct punct = db.Puncts.Find(id);

            if (punct == null)
            {
                return(NotFound());
            }

            db.Puncts.Remove(punct);
            db.SaveChanges();

            return(Ok(punct));
        }
        public static Bitmap Deseneaza(int n, int linii)
        {
            bmp = new Bitmap(width, height);
            grp = Graphics.FromImage(bmp);
            grp.Clear(Color.White);

            Punct[] v = new Punct[n];
            for (int i = 0; i < n; i++)
            {
                if (layers == 0)
                {
                    v[i] = new Punct(i, n, MutaPeCerc, MutaPeRaza);
                }
                else
                {
                    v[i] = new Punct(i, n, MutaPeCerc, layers, distance);
                }
            }
            for (int i = 0; i < n; i++)
            {
                grp.DrawEllipse(Pens.Blue, v[i].x, v[i].y, 2, 2);
            }

            int decateori = linii, aux = 0;

            for (int i = 0; i < n; i++)
            {
                if (i < n - decateori)
                {
                    for (int j = 1; j <= decateori; j++)
                    {
                        grp.DrawLine(myPen, v[i].x, v[i].y, v[i + j].x, v[i + j].y);
                    }
                }
                else
                {
                    aux++;
                    for (int j = 1; j <= decateori - aux; j++)
                    {
                        grp.DrawLine(myPen, v[i].x, v[i].y, v[i + j].x, v[i + j].y);
                    }
                    for (int j = 1; j <= aux; j++)
                    {
                        grp.DrawLine(myPen, v[i].x, v[i].y, v[j - 1].x, v[j - 1].y);
                    }
                }
            }
            return(bmp);
        }
Example #15
0
        public Trapeze(Punct topLeft, Punct bottomLeft, int topBarWidth, int bottomBarWidth)
        {
            this.P2 = new Punct();
            this.P3 = new Punct();
            this.P4 = new Punct();

            this.P1 = topLeft;

            this.P2.X = topLeft.X + topBarWidth;
            this.P2.Y = topLeft.Y;

            this.P3.X = bottomLeft.X + bottomBarWidth;
            this.P3.Y = bottomLeft.Y;

            this.P4 = bottomLeft;
        }
Example #16
0
        /// <summary>
        /// Calculeaza suma elementelor din jurul unui element dat dintr`o materice
        /// </summary>
        /// <param name="pct">Punctul in jurul caruia se calculeaza suma</param>
        /// <returns></returns>
        static int smallMatrixSum(Punct pct)
        {
            int sum = 0;

            for (int i = pct.x - 1; i <= pct.x + 1; i++)
            {
                for (int j = pct.y - 1; j <= pct.y + 1; j++)
                {
                    if (isValidCoordinate(i, j))
                    {
                        sum += miTablaCost[i, j];
                    }
                }
            }
            return(sum);
        }
Example #17
0
        /// <summary>
        /// Find a valid shot in a 3x3 matrix around the provided point
        /// </summary>
        /// <param name="pct">Point around which to search for a valid shot</param>
        /// <param name="depth">Recursivity depth. Method should be called with value 0</param>
        /// <returns>A valid shooting point</returns>
        public static Punct cautaLovituraInZonaRestransa(Punct pct, int depth)
        {
            int  incrementX          = 0;
            int  incrementY          = 0;
            int  invalidShotsCounter = 0;
            bool bValidShotFound     = false;

            int[]  aiRandomValues = { -1, 0, 1 };
            Random rndPoz         = new Random();
            Punct  pctBestShot;

            depth++;//increment indicele de adancime
            do
            {
                incrementX = aiRandomValues[rndPoz.Next(0, 3)];
                incrementY = aiRandomValues[rndPoz.Next(0, 3)];


                pctBestShot.x = pct.x + incrementX;
                pctBestShot.y = pct.y + incrementY;
                if (isValidShot(pctBestShot))
                {
                    bValidShotFound = true;
                }
                else
                {
                    invalidShotsCounter++;
                }
            }while (((incrementX == 0) && (incrementY == 0)) || ((bValidShotFound == false) && (invalidShotsCounter < 30)));

            if (!bValidShotFound)
            {
                if (depth < lsLlastHits.Count - 1)
                {
                    pctBestShot = cautaLovituraInZonaRestransa(lsLlastHits[lsLlastHits.Count - depth], depth);
                }
                else
                {
                    pctBestShot = cautaLovituraRandom();
                }
            }


            return(pctBestShot);
        }
Example #18
0
        public static Punct cautaLovituraMica(Punct pct, int depth)
        {
            int  incrementX          = 0;
            int  incrementY          = 0;
            int  invalidShotsCounter = 0;
            bool bValidShotFound     = false;

            int[]  randomValueArray = { -1, 0, 1 };
            Random rndPoz           = new Random();
            Punct  pctBestShot;

            depth++;
            do
            {
                incrementX = randomValueArray[rndPoz.Next(0, 3)];
                incrementY = randomValueArray[rndPoz.Next(0, 3)];


                pctBestShot.x = pct.x + incrementX;
                pctBestShot.y = pct.y + incrementY;
                if (isValidShot(pctBestShot))
                {
                    bValidShotFound = true;
                }
                else
                {
                    invalidShotsCounter++;
                }
            }while (((incrementX == 0) && (incrementY == 0)) || ((bValidShotFound == false) && (invalidShotsCounter < 30)));

            if (!bValidShotFound)
            {
                if (depth < lastHits.Count - 1)
                {
                    pctBestShot = cautaLovituraMica(lastHits[lastHits.Count - depth], depth);
                }
                else
                {
                    pctBestShot = cautaLovitura();
                }
            }


            return(pctBestShot);
        }
Example #19
0
 public Square(Punct topLeft, int width)
 {
     this.P1 = new Punct()
     {
         X = topLeft.X, Y = topLeft.Y
     };
     this.P2 = new Punct()
     {
         X = topLeft.X + width, Y = topLeft.Y
     };
     this.P3 = new Punct()
     {
         X = topLeft.X + width, Y = topLeft.Y + width
     };
     this.P4 = new Punct()
     {
         X = topLeft.X, Y = topLeft.Y + width
     };
 }
Example #20
0
        static void updateMatriceCost(Marcaj m, Punct p)
        {
            switch (m)
            {
            case Marcaj.aer:    //A
            {
                TablaCost[p.x, p.y] = 0;
                updateCeluleAdiacente(-10, p);
            } break;

            case Marcaj.avion:    // /
            {
                TablaCost[p.x, p.y] = 100;
            } break;

            case Marcaj.cabina:    // *
            {
                TablaCost[p.x, p.y] = 200;
            } break;
            }
        }
Example #21
0
        static void updateMatriceCost(Marcaj m, Punct p)
        {
            miAtacuriComputer[p.x, p.y] = 1;

            switch (m)
            {
            case Marcaj.aer:    //A
            {
                miTablaCost[p.x, p.y] = 0;
            } break;

            case Marcaj.avion:    // /
            {
                miTablaCost[p.x, p.y] = 1;
            } break;

            case Marcaj.cabina:    // *
            {
                miTablaCost[p.x, p.y] = 2;
            } break;
            }
        }
Example #22
0
        private void btn_GenPct_Click(object sender, EventArgs e)
        {
            punct = new Punct[n];
            string path = "Input.txt";

            inputData = new int[n, 2];
            FileStream fisier;


            if ((!File.Exists(path)) || (File.ReadLines(path).Count() != n))
            {
                fisier = File.Open(path, FileMode.Create);

                StreamWriter sw = new StreamWriter(fisier);
                for (int i = 0; i < n; i++)
                {
                    //  int x = getRandomNumber(-299, 300);
                    // int y = getRandomNumber(-299, 300);
                    //  sw.WriteLine(x + " " + y);
                }
                sw.Close();
            } // creeaza fisier daca e nevoie.


            string[] lines = File.ReadAllLines(path);
            for (int i = 0; i < lines.Length; i++)
            {
                string[] words = lines[i].Split(' ');


                punct[i] = new Punct(Convert.ToInt32(words[0]), Convert.ToInt32(words[1]), Color.Red);
            }

            for (int i = 0; i < n; i++)
            {
                DeseneazaPunct(i);
            }
        }
Example #23
0
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     using (var sr = new System.IO.StreamReader(openFileDialog1.FileName))
     {
         string line = sr.ReadLine();
         int    n    = 0;
         if (int.TryParse(line, out n))
         {
             puncte = new Punct[n];
             for (int i = 0; i < n; i++)
             {
                 line      = sr.ReadLine();
                 puncte[i] = new Punct();
                 var s = line.Split(' ');
                 puncte[i].zona = int.Parse(s[0]);
                 puncte[i].c    = Color.Black;
                 puncte[i].x    = int.Parse(s[1]);
                 puncte[i].y    = int.Parse(s[2]);
             }
         }
     }
     deseneazaPunctele(puncte);
 }
Example #24
0
        private Punct findNearestNeuron(Punct punct)
        {
            double distantaFinala = 10000, distanta;
            int    nr_neuroni = 10;

            Punct winner_index = new Punct(0, 0, Color.Red);

            for (int i = 0; i < nr_neuroni; i++)
            {
                for (int j = 0; j < nr_neuroni; j++)
                {
                    distanta = Math.Sqrt(Math.Pow((punct.x - neuroni[i, j].x), 2) + Math.Pow((punct.y - neuroni[i, j].y), 2));


                    if (distanta < distantaFinala)
                    {
                        distantaFinala = distanta;
                        winner_index   = new Punct(i, j, Color.Black);
                    }
                }
            }

            return(winner_index);
        }
Example #25
0
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            double error = 0;

            for (int t = 0; t < puncte.Length; t++)
            {
                Punct    punct  = puncte[t];
                double[] result = nn.FeedForward(new double[] { punct.x / 400.0, punct.y / 400.0 });
                double[] target = new double[result.Length];
                double   max    = double.MinValue;
                int      maxPos = 0;
                for (int i = 0; i < result.Length; i++)
                {
                    if (result[i] > max)
                    {
                        maxPos = i;
                        max    = result[i];
                    }
                    target[i] = 0;
                }
                if (punct.zona != maxPos)
                {
                    target[punct.zona] = 1;
                    nn.BackPropagation(target);
                    error++;
                }

                punct.c = colors[maxPos];
            }

            deseneazaPunctele(puncte);
            if (error < 0.02 * puncte.Length)
            {
                timer1.Stop();
            }
        }
Example #26
0
        public Rectangle(Punct topLeft, int width, int heigth)
        {
            this.P2 = new Punct();
            this.P3 = new Punct();
            this.P4 = new Punct();


            this.P1 = topLeft;

            this.P2.X = topLeft.X + width;
            this.P2.Y = topLeft.Y;

            this.P2 = new Punct
            {
                X = topLeft.X + width,
                Y = topLeft.Y
            };

            this.P3.X = topLeft.X + width;
            this.P3.Y = topLeft.Y + heigth;

            this.P4.X = topLeft.X;
            this.P4.Y = topLeft.Y + heigth;
        }
        private Tuple <string, string> GetNextToken()
        {
            NNewlines = 0;

            if (ParserPos >= Input.Length)
            {
                return(new Tuple <string, string>("", "TK_EOF"));
            }

            WantedNewline = false;
            var c = Input[ParserPos];

            ParserPos += 1;
            var keepWhitespace = Opts.KeepArrayIndentation && IsArray(Flags.Mode);

            if (keepWhitespace)
            {
                var whitespaceCount = 0;

                while (Whitespace.Contains(c))
                {
                    if (c == '\n')
                    {
                        TrimOutput();
                        Output.Add("\n");
                        JustAddedNewline = true;
                        whitespaceCount  = 0;
                    }
                    else if (c == '\t')
                    {
                        whitespaceCount += 4;
                    }
                    else if (c == '\r')
                    {
                    }
                    else
                    {
                        whitespaceCount += 1;
                    }

                    if (ParserPos >= Input.Length)
                    {
                        return(new Tuple <string, string>("", "TK_EOF"));
                    }

                    c          = Input[ParserPos];
                    ParserPos += 1;
                }

                if (JustAddedNewline)
                {
                    foreach (var i in Enumerable.Range(0, whitespaceCount))
                    {
                        Output.Add(" ");
                    }
                }
            }
            else //  not keep_whitespace
            {
                while (Whitespace.Contains(c))
                {
                    if (c == '\n')
                    {
                        if (Opts.MaxPreserveNewlines == 0 || Opts.MaxPreserveNewlines > NNewlines)
                        {
                            NNewlines += 1;
                        }
                    }

                    if (ParserPos >= Input.Length)
                    {
                        return(new Tuple <string, string>("", "TK_EOF"));
                    }

                    c          = Input[ParserPos];
                    ParserPos += 1;
                }

                if (Opts.PreserveNewlines && NNewlines > 1)
                {
                    foreach (var i in Enumerable.Range(0, NNewlines))
                    {
                        AppendNewline(i == 0);
                        JustAddedNewline = true;
                    }
                }

                WantedNewline = NNewlines > 0;
            }

            var cc = c.ToString();

            if (Wordchar.Contains(c))
            {
                if (ParserPos < Input.Length)
                {
                    cc = c.ToString();
                    while (Wordchar.Contains(Input[ParserPos]))
                    {
                        cc        += Input[ParserPos];
                        ParserPos += 1;
                        if (ParserPos == Input.Length)
                        {
                            break;
                        }
                    }
                }

                // small and surprisingly unugly hack for 1E-10 representation
                if (ParserPos != Input.Length && "+-".Contains(Input[ParserPos]) && Regex.IsMatch(cc, "^[0-9]+[Ee]$"))
                {
                    var sign = Input[ParserPos];
                    ParserPos++;
                    var t = GetNextToken();
                    cc += sign + t.Item1;
                    return(new Tuple <string, string>(cc, "TK_WORD"));
                }

                if (cc == "in") // in is an operator, need to hack
                {
                    return(new Tuple <string, string>(cc, "TK_OPERATOR"));
                }

                if (WantedNewline && LastType != "TK_OPERATOR" && LastType != "TK_EQUALS" &&
                    !Flags.IfLine && (Opts.PreserveNewlines || LastText != "var"))
                {
                    AppendNewline();
                }

                return(new Tuple <string, string>(cc, "TK_WORD"));
            }

            if ("([".Contains(c))
            {
                return(new Tuple <string, string>(c.ToString(), "TK_START_EXPR"));
            }

            if (")]".Contains(c))
            {
                return(new Tuple <string, string>(c.ToString(), "TK_END_EXPR"));
            }

            if (c == '{')
            {
                return(new Tuple <string, string>(c.ToString(), "TK_START_BLOCK"));
            }

            if (c == '}')
            {
                return(new Tuple <string, string>(c.ToString(), "TK_END_BLOCK"));
            }

            if (c == ';')
            {
                return(new Tuple <string, string>(c.ToString(), "TK_SEMICOLON"));
            }

            if (c == '/')
            {
                var comment     = "";
                var commentMode = "TK_INLINE_COMMENT";

                if (Input[ParserPos] == '*') // peek /* .. */ comment
                {
                    ParserPos += 1;
                    if (ParserPos < Input.Length)
                    {
                        while (!(Input[ParserPos] == '*' && ParserPos + 1 < Input.Length &&
                                 Input[ParserPos + 1] == '/') &&
                               ParserPos < Input.Length)
                        {
                            c        = Input[ParserPos];
                            comment += c;
                            if ("\r\n".Contains(c))
                            {
                                commentMode = "TK_BLOCK_COMMENT";
                            }
                            ParserPos += 1;
                            if (ParserPos >= Input.Length)
                            {
                                break;
                            }
                        }
                    }

                    ParserPos += 2;
                    return(new Tuple <string, string>("/*" + comment + "*/", commentMode));
                }

                if (Input[ParserPos] == '/') // peek // comment
                {
                    comment = c.ToString();
                    while (!"\r\n".Contains(Input[ParserPos]))
                    {
                        comment   += Input[ParserPos];
                        ParserPos += 1;
                        if (ParserPos >= Input.Length)
                        {
                            break;
                        }
                    }

                    if (WantedNewline)
                    {
                        AppendNewline();
                    }
                    return(new Tuple <string, string>(comment, "TK_COMMENT"));
                }
            }

            if (c == '\'' || c == '"' ||
                c == '/' &&
                (LastType == "TK_WORD" && IsSpecialWord(LastText) ||
                 LastType == "TK_END_EXPR" && (Flags.PreviousMode == "(FOR-EXPRESSION)" ||
                                               Flags.PreviousMode == "(COND-EXPRESSION)") ||
                 new[]
            {
                "TK_COMMENT", "TK_START_EXPR", "TK_START_BLOCK", "TK_END_BLOCK", "TK_OPERATOR", "TK_EQUALS",
                "TK_EOF", "TK_SEMICOLON", "TK_COMMA"
            }.Contains(LastType)))
            {
                var sep             = c;
                var esc             = false;
                var esc1            = 0;
                var esc2            = 0;
                var resultingString = c.ToString();
                var inCharClass     = false;
                if (ParserPos < Input.Length)
                {
                    if (sep == '/')
                    {
                        // handle regexp
                        inCharClass = false;
                        while (esc || inCharClass || Input[ParserPos] != sep)
                        {
                            resultingString += Input[ParserPos];
                            if (!esc)
                            {
                                esc = Input[ParserPos] == '\\';
                                if (Input[ParserPos] == '[')
                                {
                                    inCharClass = true;
                                }
                                else if (Input[ParserPos] == ']')
                                {
                                    inCharClass = false;
                                }
                            }
                            else
                            {
                                esc = false;
                            }

                            ParserPos += 1;
                            if (ParserPos >= Input.Length)
                            {
                                // ncomplete regex when end-of-file reached
                                // bail out with what has received so far
                                return(new Tuple <string, string>(resultingString, "TK_STRING"));
                            }
                        }
                    }
                    else
                    {
                        // handle string
                        while (esc || Input[ParserPos] != sep)
                        {
                            resultingString += Input[ParserPos];
                            if (esc1 != 0 && esc1 >= esc2)
                            {
                                if (!int.TryParse(
                                        new string(resultingString.Skip(Math.Max(0, resultingString.Count() - esc2))
                                                   .Take(esc2).ToArray()), NumberStyles.HexNumber, CultureInfo.CurrentCulture,
                                        out esc1))
                                {
                                    esc1 = 0;
                                }
                                if (esc1 != 0 && esc1 >= 0x20 && esc1 <= 0x7e)
                                {
                                    // FIXME
                                    resultingString = new string(resultingString.Take(2 + esc2).ToArray());
                                    if ((char)esc1 == sep || (char)esc1 == '\\')
                                    {
                                        resultingString += '\\';
                                    }
                                    resultingString += (char)esc1;
                                }

                                esc1 = 0;
                            }

                            if (esc1 != 0)
                            {
                                ++esc1;
                            }
                            else if (!esc)
                            {
                                esc = Input[ParserPos] == '\\';
                            }
                            else
                            {
                                esc = false;
                            }
                            ParserPos += 1;
                            if (ParserPos >= Input.Length)
                            {
                                // incomplete string when end-of-file reached
                                // bail out with what has received so far
                                return(new Tuple <string, string>(resultingString, "TK_STRING"));
                            }
                        }
                    }
                }

                ParserPos       += 1;
                resultingString += sep;
                if (sep == '/')
                {
                    while (ParserPos < Input.Length && Wordchar.Contains(Input[ParserPos]))
                    {
                        resultingString += Input[ParserPos];
                        ParserPos       += 1;
                    }
                }

                return(new Tuple <string, string>(resultingString, "TK_STRING"));
            }

            if (c == '#')
            {
                var resultString = "";
                // she-bang
                if (Output.Count == 0 && Input.Length > 1 && Input[ParserPos] == '!')
                {
                    resultString = c.ToString();
                    while (ParserPos < Input.Length && c != '\n')
                    {
                        c             = Input[ParserPos];
                        resultString += c;
                        ParserPos    += 1;
                    }

                    Output.Add(resultString.Trim() + '\n');
                    AppendNewline();
                    return(GetNextToken());
                }

                //  Spidermonkey-specific sharp variables for circular references
                // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
                // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
                var sharp = "#";

                if (ParserPos < Input.Length && Digits.Contains(Input[ParserPos]))
                {
                    while (true)
                    {
                        c          = Input[ParserPos];
                        sharp     += c;
                        ParserPos += 1;
                        if (ParserPos >= Input.Length || c == '#' || c == '=')
                        {
                            break;
                        }
                    }
                }

                if (c == '#' || ParserPos >= Input.Length)
                {
                    // pass
                }
                else if (Input[ParserPos] == '[' && Input[ParserPos + 1] == ']')
                {
                    sharp     += "[]";
                    ParserPos += 2;
                }
                else if (Input[ParserPos] == '{' && Input[ParserPos + 1] == '}')
                {
                    sharp     += "{}";
                    ParserPos += 2;
                }

                return(new Tuple <string, string>(sharp, "TK_WORD"));
            }

            if (c == '<' && Input.Substring(ParserPos - 1, Math.Min(4, Input.Length - ParserPos + 1)) == "<!--")
            {
                ParserPos += 3;
                var ss = "<!--";
                while (ParserPos < Input.Length && Input[ParserPos] != '\n')
                {
                    ss        += Input[ParserPos];
                    ParserPos += 1;
                }

                Flags.InHtmlComment = true;
                return(new Tuple <string, string>(ss, "TK_COMMENT"));
            }

            if (c == '-' && Flags.InHtmlComment && Input.Substring(ParserPos - 1, 3) == "-->")
            {
                Flags.InHtmlComment = false;
                ParserPos          += 2;
                if (WantedNewline)
                {
                    AppendNewline();
                }
                return(new Tuple <string, string>("-->", "TK_COMMENT"));
            }

            if (c == '.')
            {
                return(new Tuple <string, string>(".", "TK_DOT"));
            }

            if (Punct.Contains(c.ToString()))
            {
                var ss = c.ToString();
                while (ParserPos < Input.Length && Punct.Contains(ss + Input[ParserPos]))
                {
                    ss        += Input[ParserPos];
                    ParserPos += 1;
                    if (ParserPos >= Input.Length)
                    {
                        break;
                    }
                }

                if (ss == "=")
                {
                    return(new Tuple <string, string>("=", "TK_EQUALS"));
                }

                if (ss == ",")
                {
                    return(new Tuple <string, string>(",", "TK_COMMA"));
                }

                return(new Tuple <string, string>(ss, "TK_OPERATOR"));
            }

            return(new Tuple <string, string>(c.ToString(), "TK_UNKNOWN"));
        }
Example #28
0
 public static float CalculeazaAriaCladirii(Punct A, Punct B, Punct C)
 {
     var determinant = (A.x - C.x) * (B.y - A.y) - (A.x - B.x) * (C.y - A.y);
     var area = (determinant > 0) ? determinant : -determinant;
     return area;
 }
Example #29
0
 public static TextUnit <T> Punct(string content, Punct p) => new TextUnit <T>(Type.Punct, content, p);
Example #30
0
        static List <Punct> findMaxValues(int[,] inMatrix, int lastmax)
        {
            Punct          pct         = new Punct();
            List <hailasa> allSum      = new List <hailasa>();
            List <Punct>   maxSum      = new List <Punct>();
            hailasa        tempHailasa = new hailasa();

            //calc suma pt toate matricele de 3x3
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    pct.x = i;
                    pct.y = j;
                    tempHailasa.matrixSum = smallMatrixSum(pct);
                    tempHailasa.pct       = pct;
                    //adauga suma si elementrul central al matricii in lista
                    allSum.Add(tempHailasa);
                }
            }
            //sorteaza descrescator dupa suma
            List <hailasa> mama = allSum.OrderByDescending(x => x.matrixSum).ToList();

            maxSum.Add(mama[0].pct);

            for (int i = 1; i < mama.Count; i++)
            {
                if (mama[0].matrixSum == mama[i].matrixSum)
                {
                    maxSum.Add(mama[i].pct);
                }
            }

            // at this point maxSum should contain all the points in which the sum of the minimatrix is greatest

            return(maxSum);


            //int maxVal=-500;
            //List<Punct> outvals=new List<Punct>();

            //Punct tempPunct;

            //for (int i = 0; i < 10; i++)
            //{
            //    for (int j = 0; j < 10; j++)
            //    {
            //         if (inMatrix[i,j]>maxVal)
            //         {
            //             maxVal=inMatrix[i,j];
            //         }
            //    }
            //}

            //for (int i = 0; i < 10; i++)
            //{
            //    for (int j = 0; j < 10; j++)
            //    {
            //        if (inMatrix[i, j] == maxVal)
            //        {
            //            tempPunct.x = i;
            //            tempPunct.y = j;
            //            outvals.Add(tempPunct);
            //        }
            //    }
            //}

            //return outvals;
        }
Example #31
0
 static void updateMatriceAtacuri(Punct pct)
 {
     miAtacuriComputer[pct.x, pct.y] = 1;
 }