Пример #1
0
        public PrintCommand(TLine pl, NBInterpreter i) : base(pl, i)
        {
            var print = (KwrPrint)pl.Statement;

            _value     = (IValue)Interpreter.Make(pl.Clone(print.Statement));
            _printLine = print.NewLine;
        }
Пример #2
0
 // Guess the current line
 //  First validate, check for black pegs, white pegs,
 //  check for a win, for a loss }
 static void GuessLine()
 {
     if (CheckValid())
     {
         TLine TempLine = Lines[CurLine];
         int   Black    = CheckBlackPegs(ref TempLine);
         int   White    = CheckWhitePegs(ref TempLine, Black);
         Lines[CurLine].Peg = TempLine.Peg;
         if (!CheckWon())
         {
             CheckLost();
         }
         DrawPegs();
         if (GameOver)
         {
             EraseColour();
             ErasePiece();
         }
         else
         {
             ChangeMsg("You Scored " + Black.ToString() + " Black Peg(s) and " + White.ToString() + " White Peg(s)");
             ErasePiece();
             CurPiece = 0;
             CurLine++;
             DrawPiece();
         }
     }
 }
Пример #3
0
 protected BaseBinaryOperator(TLine line, NBInterpreter i, IValue <T2> left, IValue <T2> right, Func <IValue <T2>, IValue <T2>, T1> worker)
     : base(line, i)
 {
     _left   = left;
     _right  = right;
     _worker = worker;
 }
Пример #4
0
        private IItem MakeVariable(TLine programLine)
        {
            IVariable v = (IVariable)DoMake(programLine);

            InitVariable(programLine, v);
            return((IItem)v);
        }
Пример #5
0
        public JumpIfNotTrueCommand(TLine pg, NBInterpreter i) : base(pg, i, -1)
        {
            var jmp = (KwrJumpIfNotTrue)pg.Statement;

            _condition = (IValue <bool>)Interpreter.Make(pg.Clone(jmp.Condition));
            JumpPos    = jmp.JumpPos;
        }
Пример #6
0
        public LocateCommand(TLine pl, NBInterpreter i) : base(pl, i)
        {
            KwLocate loc = (KwLocate)pl.Statement;

            _x = (IValue <double>)Interpreter.Make(pl.Clone(loc.X));
            _y = (IValue <double>)Interpreter.Make(pl.Clone(loc.Y));
        }
        public void LineAtPointTest()
        {
            TPage page = m_TestPage;

            DataLocator target = new DataLocator(page);

            Point point = new Point();

            TLine         expected = null;
            TLine         actual   = null;
            IList <TLine> result   = target.LinesAtPoint(point);

            if (result.Count > 0)
            {
                actual = result[0];
            }

            Assert.AreEqual(expected, actual, "Recognition.Locator.DataLocator.LineAtPoint did not return the expected value.");

            point    = new Point(325, 285);
            expected = page.Lines[0];

            actual = target.LinesAtPoint(point)[0];

            Assert.AreEqual(expected, actual, "Recognition.Locator.DataLocator.LineAtPoint did not return the expected value.");
        }
Пример #8
0
        internal void PrepareReturn(TLine pg)
        {
            if (_subStack.Count == 0)
            {
                throw new InterpreterException(pg, "RETURN without GOSUB in " + pg.OriginalLine.LineNum);
            }

            _jumpLine = _subStack.Pop();
        }
Пример #9
0
        public RandomizeCommand(TLine pl, NBInterpreter i) : base(pl, i)
        {
            KwRandomize rnd = (KwRandomize)pl.Statement;

            if (rnd.Statement != null)
            {
                _seed = (IValue <double>)Interpreter.Make(pl.Clone(rnd.Statement));
            }
        }
Пример #10
0
        public PauseCommand(TLine pl, NBInterpreter i) : base(pl, i)
        {
            KwPause pause = (KwPause)pl.Statement;

            if (pause != null)
            {
                _interval = (IValue <double>)Interpreter.Make(pl.Clone(pause.Interval));
            }
        }
Пример #11
0
        internal void PrepareGoto(TLine pg, int line)
        {
            if (line < 0 || line >= Program.Count)
            {
                throw new InterpreterException(pg, "Invalid GOTO jump");
            }

            _jumpLine = line;
        }
Пример #12
0
        public BaseBinaryOperator(TLine line, NBInterpreter i) : base(line, i)
        {
            BinaryOperator sb    = (BinaryOperator)line.Statement;
            Statement      left  = sb.Left;
            Statement      right = sb.Right;

            _left  = (IValue <T2>)Interpreter.Make(line.Clone(left));
            _right = (IValue <T2>)Interpreter.Make(line.Clone(right));
        }
Пример #13
0
 public TLine CopyFrom(TLine c)
 {
     if (value)
     {
         value = null;
     }
     value = new string(new char[c.value.Length]);
     value = c.value;
     return(this);
 }
Пример #14
0
    public TLine Digits()
    {
        TLine ret = "";

        for (int i = 0; i < size; i++)
        {
            ret += arr[i].Digits();
        }
        return(new TLine(ret));
    }
Пример #15
0
 public void Add(TLine s)
 {
     if (size == capacity)
     {
         Console.Write("text container is full");
         Console.Write("\n");
         return;
     }
     arr[size++] = s;
 }
Пример #16
0
 public void Replace(TLine a, TLine b)
 {
     for (int i = 0; i < size; i++)
     {
         if (arr[i] == a)
         {
             arr[i] = b;
             break;
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Constructor
        /// </summary>
        protected ScalesMng()
        {
            // Singleton
            _main = this;

            SerialDevice = ESerialDevice.K3Scales;

            LastLine = new TLine {
                Line = string.Empty
            };
        }
Пример #18
0
 public IItem Make(TLine programLine)
 {
     if (programLine.Statement is Variable)
     {
         return(MakeVariable(programLine));
     }
     else
     {
         return(DoMake(programLine));
     }
 }
        public void AddLineTest()
        {
            TPage target = new TPage();
            TLine oLine  = new TLine();

            target.AddLine(oLine);
            TiS_Recognition_Common_TPageAccessor pageAccessor = new TiS_Recognition_Common_TPageAccessor(target);

            Assert.IsTrue(target.Lines.Contains(oLine), "Target must contain added line");
            Assert.IsTrue(target.Lines.Count == 1, "number of lines is wrong");
        }
Пример #20
0
        public ArrayVariable(TLine pl, NBInterpreter i, Func <Statement, string> nameGetter) : base(pl, i)
        {
            Name = nameGetter(pl.Statement);

            VariableArray va = (VariableArray)pl.Statement;

            foreach (var dimension in va.Dimensions)
            {
                var coordinate = (IValue <double>)Interpreter.Make(pl.Clone(dimension));
                _coordinates.Add(coordinate);
            }
        }
Пример #21
0
        private IItem DoMake(TLine line)
        {
            Func <TLine, NBInterpreter, IItem> f;
            string type = line.Statement.GetType().Name;

            if (types.TryGetValue(type, out f))
            {
                return(f(line, this));
            }

            throw new FactoryException(line, "Unknown type " + type);
        }
Пример #22
0
        public BinaryOperatorString(TLine line, NBInterpreter i) : base(line, i)
        {
            _operator = ((BinaryOperator)line.Statement).Operator;
            switch (_operator)
            {
            case "=": _worker = (l, r) => { ((IVariable <string>)l).SetValue(_right.Value); return(r.Value); }; break;

            case "+": _worker = (l, r) => l.Value + r.Value; break;

            default: throw new InterpreterException(line, "Unknown string operator: " + _operator);
            }
        }
Пример #23
0
            public static TPage ToPRD(PageOcrData ocrData, String saveToPrdPath)
#endif
            {
                try
                {
                    if (ocrData != null)
                    {
                        TPage res = new TPage();

                        //-- iterate data lines --\\
                        foreach (LineOcrData lineOcr in ocrData.Lines)
                        {
                            TLine currentLine = new TLine();
                            //-- Itarate the line's words --\\
                            foreach (WordOcrData wordOcr in lineOcr.Words)
                            {
                                //-- Iterate the word's chars --\\
                                TWord wordPrd = new TWord();
                                foreach (CharOcrData charOcr in wordOcr.GetAsChars(true))
                                {
                                    wordPrd.AddChar(new TChar(charOcr.Value, (short)charOcr.Confidence, new TOCRRect(charOcr.Rect)));
                                }
                                currentLine.AddWord(wordPrd);
                            }

                            if (currentLine != null && currentLine.Words != null && currentLine.Words.Count > 0)
                            {
                                res.AddLine(currentLine);
                            }
                        }

                        //-- Save the contents to a PRD file if 'saveToPrdPath' is specified --\\
                        if (!String.IsNullOrEmpty(saveToPrdPath))
                        {
                            if (!Directory.Exists(Path.GetDirectoryName(saveToPrdPath)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(saveToPrdPath));
                            }
                            TPage.SaveToPRD(res, saveToPrdPath);
                        }
                        return(res);
                    }
                    else
                    {
                        throw new Exception(String.Format("Invalid input PRD object in: [{0}]", MethodBase.GetCurrentMethod().Name));
                    }
                }
                catch (Exception ex)
                {
                    ILog.LogError(ex);
                }
                return(null);
            }
Пример #24
0
 // Check TEMPLINE against the ANSWER, looking for right colour in right spot
 //  Return CNT which is the number of black pegs found }
 static int CheckBlackPegs(ref TLine TempLine)
 {
     int Cnt = 0;
     for (int i = 0; i < 4; i++)
     {
         if (TempLine.Piece[i] == Answer[i])
         {
             TempLine.Peg[Cnt] = 1;
             Cnt++;
         }
     }
     return Cnt;
 }
Пример #25
0
            public static TPoint GetIntersection(TLine ln1, TLine ln2)
            {
                double x = (ln1.N - ln2.N) / (ln2.K - ln1.K);
                double y = ln2.K * x + ln2.N;

                if (double.IsInfinity(ln2.K))
                {
                    x = ln2.Dots[0].X;
                    y = ln1.K * x + ln1.N;
                }
                ;
                return(new TPoint(x, y));
            }
Пример #26
0
    private Vector3 GetLinesCrossPoint(TLine linePrev, TLine lineActual)
    {
        Vector3 res = new Vector3();

        bool fCrossInLines = false;

        if (!(PointCrossLines(linePrev.begin, linePrev.end, lineActual.begin, lineActual.end, ref res, ref fCrossInLines)))
        {
            res = linePrev.begin;   // ???
        }
        // + Расчёт и вставка доп. треугольников в острые внешние углы (!fCrossInLines)

        return(res);
    }
Пример #27
0
        public BinaryOperatorBool(TLine line, NBInterpreter i) : base(line, i)
        {
            _operator = ((BinaryOperator)line.Statement).Operator;
            switch (_operator)
            {
            case "&&": _worker = (l, r) => l.Value && r.Value; break;

            case "||": _worker = (l, r) => l.Value || r.Value; break;

            case "^^": _worker = (l, r) => l.Value ^ r.Value; break;

            default: throw new InterpreterException(line, "Unknown boolean operator: " + _operator);
            }
        }
Пример #28
0
        // Check TEMPLINE against the ANSWER, looking for right colour in right spot
        //  Return CNT which is the number of black pegs found }
        static int CheckBlackPegs(ref TLine TempLine)
        {
            int Cnt = 0;

            for (int i = 0; i < 4; i++)
            {
                if (TempLine.Piece[i] == Answer[i])
                {
                    TempLine.Peg[Cnt] = 1;
                    Cnt++;
                }
            }
            return(Cnt);
        }
Пример #29
0
        public void PopulateAllShape()
        {
            TRectangle rect    = new TRectangle();
            TEllipse   ellipse = new TEllipse();
            TStar      star    = new TStar();
            TLine      line    = new TLine();
            TArrow     arrow   = new TArrow();

            shapes.Add(rect.getShapeName(), rect);
            shapes.Add(ellipse.getShapeName(), ellipse);
            shapes.Add(star.getShapeName(), star);
            shapes.Add(arrow.getShapeName(), arrow);
            shapes.Add(line.getShapeName(), line);
        }
Пример #30
0
        internal void PrepareGosub(TLine pg, int line)
        {
            if (_subStack.Count > 50)
            {
                throw new InterpreterException(pg, "GOSUB stack overflow");
            }

            if (line < 0 || line >= Program.Count)
            {
                throw new InterpreterException(pg, "Invalid GOSUB jump");
            }

            _subStack.Push(CurrentLine + 1);
            _jumpLine = line;
        }
        /// <summary>
        ///A Create PRD
        ///</summary>
        public TPage CreatePRD()
        {
            TPage page = new TPage();

            TLine line1 = new TLine();
            TLine line2 = new TLine();
            TLine line3 = new TLine();

            TWord word1 = new TWord();
            TWord word2 = new TWord();
            TWord word3 = new TWord();
            TWord word4 = new TWord();
            TWord word5 = new TWord();

            word1.AddChar(new TChar('A', 100, new TOCRRect(10, 10, 20, 20)));
            word1.AddChar(new TChar('B', 100, new TOCRRect(40, 10, 20, 20)));
            word1.AddChar(new TChar('C', 100, new TOCRRect(70, 10, 20, 20)));

            word2.AddChar(new TChar('D', 100, new TOCRRect(100, 10, 20, 20)));
            word2.AddChar(new TChar('E', 100, new TOCRRect(140, 10, 20, 20)));
            word2.AddChar(new TChar('F', 100, new TOCRRect(170, 10, 20, 20)));

            word3.AddChar(new TChar('1', 100, new TOCRRect(10, 40, 20, 20)));
            word3.AddChar(new TChar('2', 100, new TOCRRect(40, 40, 20, 20)));
            word3.AddChar(new TChar('3', 100, new TOCRRect(70, 40, 20, 20)));

            word4.AddChar(new TChar('X', 100, new TOCRRect(10, 70, 20, 20)));
            word4.AddChar(new TChar('Y', 100, new TOCRRect(40, 70, 20, 20)));
            word4.AddChar(new TChar('Z', 100, new TOCRRect(70, 70, 20, 20)));

            word5.AddChar(new TChar('W', 100, new TOCRRect(110, 70, 20, 20)));
            word5.AddChar(new TChar('V', 100, new TOCRRect(140, 70, 20, 20)));
            word5.AddChar(new TChar('Q', 100, new TOCRRect(170, 70, 20, 20)));

            line1.AddWord(word1);
            line1.AddWord(word2);

            line2.AddWord(word3);

            line3.AddWord(word4);
            line3.AddWord(word5);

            page.AddLine(line1);
            page.AddLine(line2);
            page.AddLine(line3);

            return(page);
        }
Пример #32
0
 // Check TEMPLINE against the ANSWER, looking for right colour in wrong spot
 //  Return CNT - BLACK which is the number of white pegs found }
 static int CheckWhitePegs(ref TLine TempLine, int Black)
 {
     int Cnt = Black;
     if (Black < 4)
     {
         for (int i = 0; i < 4; i++)
         {
             for (int j = 0; j < 4; j++)
             {
                 if ((TempLine.Piece[i] == Answer[j]) && (i != j))
                 {
                     TempLine.Peg[Cnt] = 2;
                     Cnt++;
                 }
             }
         }
     }
     return Cnt - Black;
 }