Example #1
0
        static void FindIfValidCandidate(char[,] mat, int x, int y, string s, point[] points, int ndx)
        {
            if (s.Length == 0)
            {
                foreach (point p in points)
                {
                    Console.Write("{0} - [{1}, {2}] ", mat[p.x, p.y], p.x, p.y);
                }

                Console.WriteLine("\n");
                return;
            }

            if (ndx >= points.Length)
                return;

            int[] xmove = { 1, 1, 1, -1, -1, -1, 0, 0};
            int[] ymove = { 0, 1, -1, 1, -1, 0, 1, -1};

            for(int i = 0; i < xmove.Length; i++)
            {
                if (IsValidPoint(mat, x + xmove[i], y + ymove[i]) && mat[x + xmove[i], y + ymove[i]] == s[0])
                {
                    points[ndx] = new point(x + xmove[i], y + ymove[i]);
                    FindIfValidCandidate(mat, x + xmove[i], y + ymove[i], s.Substring(1), points, ndx + 1);
                }
            }
        }
Example #2
0
 float vectorDistance(point x, point y)
 {
     //sqrt(a^2 + b^2)
     float a = Mathf.Abs((float)y.x - (float)x.x);
     float b = Mathf.Abs((float)y.y - (float)x.y);
     return Mathf.Sqrt((a * a) + (b * b));
 }
Example #3
0
        static void Tour(int[,] board, point p)
        {
            Stack<point> stk = new Stack<point>();
            stk.Push(p);

            int[] x = { 1, 2, 1, 2, -1, -1, -2, -2};
            int[] y = { 2, 1, -2, -1, 2, -2, 1, -1};
            point cur = null;
            int step = 1;
            int cnt = board.GetLength(0) * board.GetLength(1) - 1;
            while (stk.Count > 0)
            {
                cur = stk.Pop();
                board[cur.x, cur.y] = step++;

                if (cnt > 0)
                {
                    for (int i = 0; i < x.Length; i++)
                    {
                        if (isValid(board, cur.x + x[i], cur.y + y[i]))
                        {
                            board[cur.x + x[i], cur.y + y[i]] = -1; //mark as visited
                            stk.Push(new point(cur.x + x[i], cur.y + y[i]));
                            cnt--;
                        }
                    }
                }
            }

            printMat(board);
        }
Example #4
0
 public point[] findPath(Vector3 tC)
 {
     /*float dist = Vector3.Distance(this.getCoord(),target);
     int disp = System.Convert.ToInt32(dist) / levelSettings.lengthOt;
     if(disp == 0) disp++;
     point[] result = new point[disp];
     result[0] = new point(this.getCoord().x,this.getCoord().y);
     float tmpX = this.getCoord().x;
     float difX = tmpX - tC.x;
     float tmpY = this.getCoord().y;
     float difY = tmpY - tC.y;
     for(int i = 1; i<disp; i++){
         result[i] = new point(tmpX+(difX/disp),tmpY+(difY/disp));
     }
     result[disp-1] = new point(tC.x,tC.y);
     return result;*/
     cell conv = new cell();
     ArrayList t = levelSettings.aStar.algAStar(conv.toGrid(this.getCoord()),conv.toGrid(tC));
     point[] result = new point[t.Count];
     for(int i = 0; i<t.Count; i++){
         conv = (cell)t[i];
         result[i] = conv.toPoint(conv);
     }
     return result;
 }
Example #5
0
        static void Main(string[] args)
        {
            point[] puntos = new point[100];
            int dato = 0;
            while (true)
            {
                c.WriteLine("Choose an option: ");
                c.WriteLine("1. Add data for one point");
                c.WriteLine("2. Display all the entered points");
                c.WriteLine("3. Calculate (and display) the average values for x and y");
                c.WriteLine("4. Exit the program");
                int opcion = Convert.ToInt32(Console.ReadLine());

                switch (opcion)
                {
                    case 1:
                        c.Write("insert x for the new point > ");
                    puntos[dato].x = Convert.ToInt32(Console.ReadLine());

                    c.WriteLine();
                    c.Write("insert y for the new point > ");
                    puntos[dato].y = Convert.ToInt32(Console.ReadLine());

                    dato++;
                    c.Clear();
                    break;
                    case 2:
                        for (int i = 0; i < dato; i++)
                    {
                        c.WriteLine("Point {0} = {1};{2}", i, puntos[i].x, puntos[i].y);
                    }

                    c.WriteLine("Press a key");
                    c.ReadKey();
                    c.Clear();
                    break;
                    case 3:
                        double sumax = 0;
                    double sumay = 0;
                    for (int i = 0; i < dato; i++)
                    {
                        sumax = sumax + puntos[i].x;
                        sumay = sumay + puntos[i].y;
                    }

                    c.WriteLine("Average point is x:{0};y:{1}", sumax / dato, sumay / dato);
                    c.WriteLine("Press a key");
                    c.ReadKey();
                    c.Clear();
                    break;
                    case 4:
                        return;

                    default:
                        c.Clear();
                        break;
                }
            }
        }
 public object NewFindLastPoint(point startingPoint,string[] newCommands)
 {
     for (int index = 0; index < newCommands.Length; index++)
     {
         if (newCommands[index] == "up") { y = startingY + 1; startingY = y; }
         else if (newCommands[index] == "down") { y = startingY - 1; startingY = y; }
         else if (newCommands[index] == "right") { x = startingX + 1; startingX = x; }
         else if (newCommands[index] == "left") { x = startingX + 1; startingX = x; }
     }
 }
Example #7
0
        private static int FindMin(int[,] grid, point p)
        {
            Queue<point> queue = new Queue<point>();
            queue.Enqueue(p);
            int mincost = 0;
            grid[p.x, p.y] = -1;
            while (queue.Count > 0)
            {
                p = queue.Dequeue();
                Console.Write(" [{0}, {1}]", p.x, p.y);
                if (grid[p.x, p.y] == 1)
                {
                    return mincost;
                }

                point pr = new point(p.x + 1, p.y);
                point pl = new point(p.x - 1, p.y);
                point pu = new point(p.x, p.y - 1);
                point pd = new point(p.x, p.y + 1);

                if (validate(grid, pr))
                {
                    if(grid[pr.x, pr.y] != 1)
                        grid[pr.x, pr.y] = -1;
                    queue.Enqueue(pr);
                }

                if (validate(grid, pl))
                {
                    if(grid[pl.x, pl.y] != 1)
                        grid[pl.x, pl.y] = -1;
                    queue.Enqueue(pl);
                }

                if (validate(grid, pu))
                {
                    if(grid[pu.x, pu.y] != 1)
                        grid[pu.x, pu.y] = -1;
                    queue.Enqueue(pu);
                }

                if (validate(grid, pd))
                {
                    if(grid[pd.x, pd.y] != 1)
                        grid[pd.x, pd.y] = -1;
                    queue.Enqueue(pd);
                }
            }

            return -1;
        }
Example #8
0
        static void Main(string[] args)
        {
            point[] puntos = new point[100];
            int dato = 0;
            int opcion = 1;
            while (option<4)
            {
                c.WriteLine("choose an option: ");
                c.WriteLine("1. Add data for one point");
                c.WriteLine("2. Display all the entered points");
                c.WriteLine("3. Calculate (and display) the average values for x and y");
                c.WriteLine("4. Exit the program");
                opcion = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine();
                switch (opcion)
                {
                    case 1:
                    c.Write("insert x for the new point > ");
                    puntos[dato].x = Convert.ToInt32(Console.ReadLine());
                    c.WriteLine();
                    c.Write("insert y for the new point > ");
                    puntos[dato].y = Convert.ToInt32(Console.ReadLine());
                    dato++;
                    break;
                    case 2:
                    for (int i = 0; i<dato; i++)
                    {
                        Console.WriteLine(puntos[i].x + " " + puntos[i].y);
                    }

                    break;
                    case 3:
                    double sumax = 0;
                    double sumay = 0;
                    for (int i = 0; i < dato; i++)
                    {
                        sumax = sumax + puntos[i].x;
                        sumay = sumay + puntos[i].y;
                    }

                    c.WriteLine("the average point for x is:{0};y:{1}", sumax / dato, sumay / dato);
                    break;
                    default:

                        break;

                }
            }
        }
Example #9
0
        static void FindStringInMatrix(char[,] mat, string s)
        {
            int m = mat.GetLength(0);
            int n = mat.GetLength(1);
            point[] points = new point[s.Length];

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (mat[i, j] == s[0])
                    {
                        points[0] = new point(i, j);
                        FindIfValidCandidate(mat, i, j, s.Substring(1), points, 1);
                    }
                }
            }
        }
Example #10
0
 public void BFS(int[,] mat, point pt)
 {
     Queue<point> queue = new Queue<point>();
     queue.Enqueue(pt);
     while (queue.Count > 0)
     {
         point p = queue.Dequeue();
         mat[p.x, p.y] = 0;
         if (isvalidPoint(p.x, p.y + 1, mat))
             queue.Enqueue(new point(p.x, p.y + 1));
         if (isvalidPoint(p.x, p.y - 1, mat))
             queue.Enqueue(new point(p.x, p.y - 1));
         if (isvalidPoint(p.x + 1, p.y, mat))
             queue.Enqueue(new point(p.x + 1, p.y));
         if (isvalidPoint(p.x - 1, p.y, mat))
             queue.Enqueue(new point(p.x - 1, p.y));
     }
 }
Example #11
0
 /// <summary>
 /// Draws 2D Grid of Points
 /// </summary>
 /// <param name="Grid"></param>
 public static void DrawGrid(point[,] Grid)
 {
     foreach (point p in Grid)
     {
         Console.SetCursorPosition(p.x, p.y);
         if (p.isWall == true)
         {
             Console.BackgroundColor = ConsoleColor.Blue;
             Console.ForegroundColor = ConsoleColor.Blue;
             Console.Write("*");
         }
         else
         {
             Console.BackgroundColor = ConsoleColor.White;
             Console.ForegroundColor = ConsoleColor.White;
             Console.Write("|");
         }
     }
 }
Example #12
0
 static void FindSeq(int[,] mat, point p, HashSet<point> sol, HashSet<point> buf, bool[, ] visited)
 {
     Stack<point> stk = new Stack<point>();
     stk.Push(p);
     int[] xmove = { 0, 0, 1, -1};
     int[] ymove = { 1, -1, 0, 0};
     visited[p.x, p.y] = true;
     while (stk.Count > 0)
     {
         point pt = stk.Pop();
         buf.Add(pt);
         bool noSeq = true;
         for (int i = 0; i < xmove.Length; i++)
         {
             if (isValid(mat, pt.x + xmove[i], pt.y + ymove[i], pt, visited))
             {
                 stk.Push(new point(pt.x + xmove[i], pt.y + ymove[i]));
                 visited[pt.x + xmove[i], pt.y + ymove[i]] = true;
                 noSeq = false;
             }
         }
         if (noSeq)
         {
             //traverse back, path ends
             if (sol.Count < buf.Count)
             {
                 sol.Clear();
                 Console.Write("Sol{0}: ", sol_num++);
                 foreach (point psol in buf)
                 {
                     sol.Add(psol);
                     Console.Write("{0} ", mat[psol.x, psol.y]);
                 }
                 Console.WriteLine();
             }
             buf.Remove(pt);
         }
     }
 }
Example #13
0
 //攻撃(パンチだけなんで後で増やす
 public Boolean attack(trap t)
 {
     if (t.type == 12)
     {
         MessageBox.Show("もぐもぐ");
         destructpointset();
         motimono.trappointremove(destructpoint.x, destructpoint.y);
         motimono.tfield[destructpoint.x, destructpoint.y] = null;
         destruction = true;
         if (goalpoint.x == destructpoint.x && goalpoint.y == destructpoint.y)
         {
             MessageBox.Show(goalpoint.x.ToString() + goalpoint.y.ToString());
             goalpoint = pointlist[0];
             MessageBox.Show(goalpoint.x.ToString() + goalpoint.y.ToString());
             distcalcstart(goalpoint.x, goalpoint.y);
             pointlist.RemoveAt(0);
         }
         else
         {
             MessageBox.Show(goalpoint.x.ToString() + goalpoint.y.ToString());
             pointlist.RemoveAll(p => p.x == destructpoint.x && p.y == destructpoint.y);
         }
         return true;
     }
     MessageBox.Show("バブーパンチ!");
     if (t.happen == 3)
     {
         if ((t.type == 7 || t.type == 8) && t.grade == 1)
         {
             actioednfrag = true;
         }
         else if(Math.Abs(t.direction-direction)==2)
         {
             actioednfrag = true;
         }
     }
     return false;
 }
Example #14
0
        static void FindPath(int[,] board, point from, point to)
        {
            Queue<point> queue = new Queue<point>();
            queue.Enqueue(from);

            int[] x = { 1, 2, 1, 2, -1, -1, -2, -2 };
            int[] y = { 2, 1, -2, -1, 2, -2, 1, -1 };
            point cur = null;
            int step = 1;
            int cnt = board.GetLength(0) * board.GetLength(1) - 1;

            while (queue.Count > 0)
            {
                cur = queue.Dequeue();
                board[cur.x, cur.y] = step;

                if (cur.x == to.x && cur.y == to.y)
                {
                    Console.WriteLine("Length of path between given points = {0}", step);
                    break;
                }
                step++;
                if (cnt > 0)
                {
                    for (int i = 0; i < x.Length; i++)
                    {
                        if (isValid(board, cur.x + x[i], cur.y + y[i]))
                        {
                            board[cur.x + x[i], cur.y + y[i]] = -1;
                            queue.Enqueue(new point(cur.x + x[i], cur.y + y[i]));
                            cnt--;
                        }
                    }
                }
            }
            printMat(board);
        }
Example #15
0
 public void moveTo(point[] goal)
 {
     bool fl = false;
     foreach(point tC in goal){
         if(tC.isPassed()){
             continue;
         }else{
             if(fl){
                 tC.makeCurrent();
                 this.stepTo(tC.getCoord());
                 fl = false;
             }else{
                 if(tC.isCurrent()){
                     this.stepTo(tC.getCoord());
                 }
                 if(Vector3.Distance(tC.getCoord(),this.getCoord())<0.01){
                     tC.pass();
                     tC.unmakeCurrent();
                     fl = true;
                 }
             }
         }
     }
 }
Example #16
0
 private void numericUpDown2_ValueChanged(object sender, EventArgs e)
 {
     save   = point1;
     save.Y = -(double)numericUpDown2.Value;
     point1 = save;
 }
Example #17
0
File: 3.cs Project: qifanyyy/CLCDSA
        private double calcPass(double vstring, double hstring)
        {
            var x1 = vstring + r;
            var x2 = x1 + g;
            var y1 = hstring + r;
            var y2 = y1 + g;

            x1 += f;
            x2 -= f;
            y1 += f;
            y2 -= f;

            var leftBottom = new point(x1, y1);

            // totally out
            if (OrgPoint.distTo(leftBottom) >= flyR)
            {
                return(0);
            }

            var rightTop = new point(x2, y2);

            if (rightTop.distTo(OrgPoint) <= flyR)
            {
                return(sqPass);
            }
            var  rightBottom    = new point(x2, y1);
            bool rightBottomOut = rightBottom.distTo(OrgPoint) >= flyR;
            var  leftTop        = new point(x1, y2);
            bool leftTopOut     = leftTop.distTo(OrgPoint) >= flyR;

            double res = 0;

            // 1
            if (!rightBottomOut && !leftTopOut)
            {
                var p1 = new point(x2, otherCood(flyR, x2));
                var p2 = new point(otherCood(flyR, y2), y2);

                res += bowArea(flyR, p1, p2);
                res += sqPass;
                res -= ((x2 - p2.x) * (y2 - p1.y)) / 2;
            }
            else if (rightBottomOut && !leftTopOut)
            {
                var p1 = new point(otherCood(flyR, y1), y1);
                var p2 = new point(otherCood(flyR, y2), y2);
                res += bowArea(flyR, p1, p2);
                var lx = Math.Max(p1.x, p2.x);
                var sx = Math.Min(p1.x, p2.x);
                res += passG * (sx - x1);
                res += (passG * (lx - sx)) / 2;
            }
            else if (!rightBottomOut && leftTopOut)
            {
                var p1 = new point(x2, otherCood(flyR, x2));
                var p2 = new point(x1, otherCood(flyR, x1));
                res += bowArea(flyR, p1, p2);
                var ly = Math.Max(p1.y, p2.y);
                var sy = Math.Min(p1.y, p2.y);
                res += passG * (sy - y1);
                res += (passG * (ly - sy)) / 2;
            }
            else if (rightBottomOut && leftTopOut)
            {
                var p1 = new point(x1, otherCood(flyR, x1));
                var p2 = new point(otherCood(flyR, y1), y1);
                res += bowArea(flyR, p1, p2);
                res += ((p1.y - y1) * (p2.x - x1)) / 2;
            }

            return(res);
        }
Example #18
0
 public void AddTopoints(point point)
 {
     base.AddObject("points", point);
 }
 public edge(int a, int b, List<point> pts)
 {
     From = pts[a]; To = pts[b];
 }
Example #20
0
 protected override void TouchUpMessage(object sender, point point, ref bool handled)
 {
     _gDown = false;
     base.TouchUpMessage(sender, point, ref handled);
 }
Example #21
0
 public line(point begin = default, point end = default)
 {
     this.begin = begin;
     this.end   = end;
 }
Example #22
0
 static void pointInspector(point point)
 {
     Console.WriteLine($"X: {point.x}\nY: {point.y}");
 }
 public edge(point p1, point p2)
 {
     From = p1; To = p2;
 }
Example #24
0
 float vectorLength(point x)
 {
     float temp1 = (float)x.x * (float)x.x;
     float temp2 = (float)x.y * (float)x.y;
     return Mathf.Sqrt((float)temp1 + (float)temp2);
 }
Example #25
0
 float vectorDotProduct(point x, point y)
 {
     float temp1 = (float)x.x * (float)y.x;
     float temp2 = (float)x.y * (float)y.y;
     return (temp1 + temp2);
 }
 public tribox(point[] pts)
 {
     Cedges = new edge[6];
     Points = new point[4];
     Points[0] = pts[0]; Points[1] = pts[1]; Points[2] = pts[2]; Points[3] = pts[3];
     Cedges[0] = new edge(pts[0], pts[1]);
     Cedges[1] = new edge(pts[0], pts[2]);
     Cedges[2] = new edge(pts[0], pts[3]);
     Cedges[3] = new edge(pts[1], pts[2]);
     Cedges[4] = new edge(pts[2], pts[3]);
     Cedges[5] = new edge(pts[3], pts[1]);
 }
Example #27
0
    static void main()
    {
        int x = 12 * 30;

        Console.WriteLine(x);
        Console.WriteLine(FeetToInches(200));

        string message  = "Hello World";
        string uppermsg = message.ToUpper();

        Console.WriteLine(uppermsg);

        int x = 2015;

        message += x.ToString();
        Console.WriteLine(message);

        //panda
        Panda p1 = new Panda("pan Dee");
        Panda p2 = new Panda("pan dat");

        Console.WriteLine(p1.name);
        Console.WriteLine(p2.name);

        Console.WriteLine(Panda.Population);

        //value instance
        Point p1 = new Point();

        p1.x = 7;

        Point p2 = p1;

        Console.WriteLine(p1.x);         //7
        Console.WriteLine(p2.x);         //7

        p1.x = 9;
        Console.WriteLine(p1.x);         //9
        Console.WriteLine(p2.x);         //7 ///*******

        //reference isntance
        Point p1 = new Point();

        p1.x = 7;

        Point p2 = p1;

        Console.WriteLine(p1.x);         //7
        Console.WriteLine(p2.x);         //7

        p1.x = 9;
        Console.WriteLine(p1.x);      //9
        Console.WriteLine(p2.x);      //9 ///*******

        Point p = null;               //class point

        Console.WriteLine(p == null); //true
        Console.WriteLine(p.x);       //throw exception

        Point p = null;               //struct point, compile error
        int   x = null;               //compile error

        //caculate size
        A a = new A();

        Console.WriteLine(Marshal.Sizeof(a));         // 8: 32bit, 16:64bit

        int x = 0, y = 0;

        Console.WriteLine(x++); //output:0, x is now 1
        Console.WriteLine(++x); //output:1, x is now 1

        int x = 2 / 3;          //x = 0;
        int y = 2 % 3;          //x = 2;

        int a = 1000000;
        int b = 1000000;
        int c = checked (a * b);      //checks just the expression

        //=>
        checked
        {
            c = a * b;
        }

        int x = int.MaxValue;
        int y = unchecked (x + 1);

        unchecked (int z = x + 1);

        short x = 1, y = 1;
        short Z = x + y;       //compile error
        short z = (short)(x + y);

        string a1 = "\\\\server\\fileshare\\helloworld.cs"; //equal below @
        string a2 = @"\\server\fileshare\helloworld.cs";

        string xml = @"<customer id = " 123 "></customer>";

        int x = 4;

        Console.WriteLine($"A square has {x} sides"); //prints: A square has 4 sides

        int    y = 2;
        string s = $@"this spans {y} lines";

        //array
        char[] vowels = new char[20];
        vowels[0] = 'a';
        vowels[1] = 'b';
        vowels[2] = 'c';
        vowels[3] = 'd';
        vowels[4] = 'e';

        char[] vowels = new char[] { 'a', 'b', 'c', 'd', 'e' };
        //or
        char[] vowels = { 'a', 'b', 'c', 'd', 'e' };

        //struct point
        Point[] a = new Point[1000];
        int     x = a[100].x; //value

        //class point
        point[] a = new Point[1000];
        int     x = a[100].x; //runtime error, NullReferenceException

        //handle above problem
        for (int i = 0; i < a.length; i++)
        {
            a[i] = new point();
        }

        //3x3 array
        int[,] matrix = new int[3, 3];

        //assignment
        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                matrix[i, j] = i * 3 + j;
            }
        }


        int[,] matrix = new int[, ] {
            { 0, 1, 2 },
Example #28
0
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("MouseRead.Input.GetMouseButtonDown(0)");
            last.x = Input.mousePosition.x;
            last.y = Input.mousePosition.y;
            points = new List<point>();
            //points.Add(new point(last.x, last.y));
        }

        if (Input.GetMouseButton(0))
        {
            //Debug.Log("MouseRead.Input.GetMouseButton(0)");
            float posX = Input.mousePosition.x;
            float posY = Input.mousePosition.y;
            float newDirection;
            point l = new point(posX - last.x, posY - last.y);
            Debug.Log("mousePosition == <" + posX + ", " + posY + ">");
            float dot = vectorDotProduct(new point(1, 0), l);
            Debug.Log("dot == " + dot);
            if(posY > last.y)
            {
                newDirection = Mathf.Deg2Rad * 360 - Mathf.Acos(dot / (vectorLength(l) + 1));
            } else
            {
                newDirection = Mathf.Acos(dot / (vectorLength(l) + 1));
            }
            newDirection = newDirection * 60;
            point tempPoint = null;
            if (Mathf.Abs(newDirection - (float)direction) > 30 && (newDirection - (float)direction) < 330)
            {
                Debug.Log("Direction Change");
                if (tempPoint != null) {
                    if (vectorDistance(new point(posX, posY), tempPoint) > (Screen.width / 100))
                    {
                        Debug.Log("Distance Exceeds Limit");
                        direction = newDirection;
                        last = tempPoint;
                        points.Add(new point(tempPoint.x, tempPoint.y));
                    }
                } else
                {
                    tempPoint = new point(posX, posY);
                }
            } else
            {
                tempPoint = null;
            }

            Debug.Log("direction == " + direction);
        }
        if (Input.GetMouseButtonUp(0))
        {
            //check points for match
            Debug.Log("points contains " + points.Count + " entries.");
            if(points.Count == 2)
            {
                if (points[0].x > points[1].x)
                {
                    //left
                    if (points[0].y > points[1].y)
                    {
                        //down
                        Debug.Log("left, down");
                    } else
                    {
                        //up
                        Debug.Log("left, up");
                    }
                } else
                {
                    //right
                    if (points[0].y > points[1].y)
                    {
                        //down
                        Debug.Log("right, down");
                    }
                    else
                    {
                        //up
                        Debug.Log("right, up");
                    }
                }
            }
        }
	}
Example #29
0
 private static bool validate(int[, ] grid, point p)
 {
     if (p.x < 0 || p.x >= grid.GetLength(0) || p.y < 0 || p.y >= grid.GetLength(1) || grid[p.x, p.y] == -1)
         return false;
     return true;
 }
Example #30
0
 private double dot(point c1, point c2)
 {
     return(c1.x * c2.x + c1.y * c2.y + c1.z * c2.z);
 }
Example #31
0
File: Form1.cs Project: xnzaa/ship
        //主串口字符串处理函数
        private void main_sp_receive(string str)
        {
            try
            {
                if (is_first_receive)       //第一次接收数据
                {
                    is_first_receive = false;
                    timer1.Start();
                    timer2.Start();
                    receive_time.Start();
                    label7.Text      = "已连接";
                    label7.BackColor = Color.White;
                }
                else                        //不是第一次接收
                {
                    //显示接收到的数据
                    label12.Text = str;

                    //接收到的数据保存在文本中
                    swr.WriteLine(str);

                    //处理含有$GPRMC的GPS数据
                    if (str.Contains("$GPRMC"))
                    {
                        string[] str_gps = str.Split(',');

                        //纬度转换并计算正确值
                        double latitude = Convert.ToDouble(str_gps[3]) / 100 - latitude_check;

                        //经度转换并计算正确值
                        double longitude = Convert.ToDouble(str_gps[5]) / 100 - longitude_check;

                        /***************************计算速度和航向********没事不要改***************************/
                        latlogtime temp;
                        temp.latlog.y = latitude;
                        temp.latlog.x = longitude;
                        temp.time     = time_passed;
                        latlogtime_queue.Enqueue(temp);
                        if (latlogtime_queue.Count == 2)
                        {
                            latlogtime temp1 = (latlogtime)latlogtime_queue.Dequeue();
                            latlogtime temp2 = (latlogtime)latlogtime_queue.Dequeue();
                            /***采用数学方法计算球面两点间距离****/
                            point  A        = temp1.latlog;
                            point  B        = temp2.latlog;
                            double distance = Math.Sqrt(Math.Pow((B.y - A.y) * 111700, 2) + Math.Pow((6371000 * 2 * Math.PI * Math.Cos(A.y * 180 / Math.PI) * (B.x - A.x) / 360), 2));
                            /*************************************/
                            double time  = Math.Abs(temp2.time - temp1.time) / 1000.0;      //毫秒转化为秒
                            double speed = distance / time;
                            label33.Text = speed.ToString().Substring(0, 5);
                            coordinate temp_coor = get_direction(temp1.latlog, temp2.latlog);
                            double[]   degree    = new double[4];
                            for (int i = 0; i < 4; ++i)
                            {
                                degree[i] = get_angle(temp_coor, axis[i]);
                            }
                            if (degree[0] <= 90 && degree[1] <= 90)
                            {
                                label35.Text = "北偏东" + degree[1].ToString().Substring(0, 5) + "°";
                            }
                            else if (degree[1] <= 90 && degree[2] <= 90)
                            {
                                label35.Text = "北偏西" + degree[1].ToString().Substring(0, 5) + "°";
                            }
                            else if (degree[2] <= 90 && degree[3] <= 90)
                            {
                                label35.Text = "南偏西" + degree[3].ToString().Substring(0, 5) + "°";
                            }
                            else if (degree[3] <= 90 && degree[4] <= 90)
                            {
                                label35.Text = "南偏东" + degree[3].ToString().Substring(0, 5) + "°";
                            }
                        }
                        /**************************************************************************************/

                        //显示当前坐标
                        label2.Text = latitude.ToString();
                        label3.Text = longitude.ToString();

                        //此处有一个未解决的疑问:每次调用InvokeScript之后,会交换objArray的值
                        //故每次均需重新构造objArray

                        //防止点数量过于密集,每接收三个丢弃一个point_counter_for_abandon % 3 == 0
                        if (point_counter_for_abandon % 3 == 0)
                        {
                            point_counter_for_abandon = 0;
                            objArray[0] = (object)latitude;
                            objArray[1] = (object)longitude;
                            webBrowser1.Document.InvokeScript("mark", objArray);
                        }

                        //船讯网显示船只信息函数
                        if (radioButton3.Checked)
                        {
                            objArray[0] = (object)latitude;
                            objArray[1] = (object)longitude;
                            webBrowser1.Document.InvokeScript("show_ships", objArray);
                        }

                        //地图居中
                        if (checkbox1.Checked)
                        {
                            objArray[0] = (object)latitude;
                            objArray[1] = (object)longitude;
                            webBrowser1.Document.InvokeScript("center", objArray);
                        }
                    }

                    //处理温湿度距离数据
                    if (str.Contains("#TEMP"))
                    {
                        //#TEMP22.7RH46.5endDIS65.68

                        /*
                         * th
                         * {string[6]}
                         *  [0]: "#TEM"
                         *  [1]: "22.7"
                         *  [2]: ""
                         *  [3]: "46.5"
                         *  [4]: "ndDI"
                         *  [5]: "65.68"
                         */

                        string[] th          = str.Split('P', 'R', 'H', 'e', 'S', '\r');
                        string   humidity    = th[3];           //湿度
                        string   temperature = th[1];           //温度

                        //温度标签
                        label18.Text       = temperature + "摄氏度";
                        progressBar1.Value = Convert.ToInt32(Convert.ToDouble(temperature));

                        //湿度标签
                        label19.Text       = humidity + "%";
                        progressBar2.Value = Convert.ToInt32(Convert.ToDouble(humidity));


                        //红外检测
                        if (str.Contains("!##!"))
                        {
                            label21.Text      = "发现目标";
                            label21.BackColor = Color.Red;
                        }
                        else
                        {
                            label21.Text      = "正常";
                            label21.BackColor = Color.White;
                        }

                        //障碍物距离
                        if (th[5] == "-1")
                        {
                            label9.Text        = "前方无目标";
                            progressBar3.Value = 1200;
                        }
                        else
                        {
                            label9.Text        = Convert.ToDouble(th[5]) / 100 + "m";
                            progressBar3.Value = Convert.ToInt32(Convert.ToDouble(th[5]));
                        }
                    }

                    //TODO: 命令返回值
                    if (str.Contains(":") || str.Contains("!"))
                    {
                        if (str.Contains(":"))
                        {
                            string[] strr = str.Split(':', '$');
                            //order_back(":"+strr[1]);
                        }
                        else if (str.Contains("!"))
                        {
                            string[] strr = str.Split('!', '$');
                            //order_back("!" + strr[1]);
                        }
                    }
                    main_sp.DiscardInBuffer();
                }
            }
            catch
            {
                return;
            }
        }
Example #32
0
        private void launchthr()
        {
            foreach (plotxy pl in plotxys)
            {
                pl.Close();
            }

            point[] points;
            GC.Collect();
            LinearModel mosd = new LinearModel();

            mosd.initTimeMoments(100, 5, 6);
            mosd.calcMove();
            //mosd.timeMoments[0];
            double ro      = calc.StrPow(textBox_ro.Text, textBox_ropop.Text);
            double L       = calc.StrPow(textBox_L.Text, textBox_Lpop.Text);
            double h       = calc.StrPow(textBox_h.Text, textBox_hpop.Text);
            double b       = calc.StrPow(textBox_b.Text, textBox_bpop.Text);
            double D       = calc.StrPow(textBox_D.Text, textBox_Dpop.Text);
            double v0      = calc.StrPow(textBox_v0.Text, textBox_v0pop.Text);
            double vamp    = calc.StrPow(textBox_vamp.Text, textBox_vamppop.Text);
            int    numP    = Convert.ToInt32(textBox_numP.Text);
            double elastic = calc.StrPow(textBox_elas.Text, textBox_elaspop.Text);
            double Re      = calc.StrPow(textBox_Renum.Text, textBox_Renumpop.Text);
            string flname  = textBox_file.Text;

            ApplyEffect(this);
            thrdraw = new Thread(delegate()
            {
                if (flname != "")
                {
                    //string[] strLoads = new string[1];
                    //int res = myfuncs.getExtStr(flname, ref strLoads);
                    //if (res != 0)
                    //{
                    //    MessageBox.Show("Fail, Err#" + res);
                    //}
                    int[] findIndex = new int[1];
                    //res = myfuncs.getnumExtLoad(strLoads, ref findIndex);
                    //if (res != 0)
                    //{
                    //    MessageBox.Show("Fail, Err#" + res);
                    //}

                    if (findIndex.Length > 0)
                    {
                        //int numP_ext = Convert.ToInt32(strLoads[findIndex[findIndex.Length - 1]].Split(':')[1]);
                        //if (numP < numP_ext)
                        //{
                        //    MessageBoxResult messboxres_numP = MessageBox.Show("Выбрано меньше точек чем в файле эксперимента\r\n\r\nВзять число точек из файла?", "numP < countp", MessageBoxButton.YesNo);
                        //    switch (messboxres_numP)
                        //    {
                        //        case MessageBoxResult.No:
                        //            return;
                        //        case MessageBoxResult.Yes:
                        //            numP = numP_ext;
                        //            break;
                        //    }
                        //}
                        FileStream fs          = new FileStream(flname, FileMode.Open);
                        StreamReader sr        = new StreamReader(fs);
                        string strRead         = sr.ReadLine();
                        int countsExt          = Convert.ToInt32(strRead);
                        double[] time          = new double[countsExt];
                        double[][][] lstF      = new double[countsExt][][];
                        double[][][] lstFem1   = new double[countsExt][][];
                        double[][][] lstFep1   = new double[countsExt][][];
                        double[][][] lsta      = new double[countsExt][][];
                        double[][][] lstv      = new double[countsExt][][];
                        double[][][] lstdispla = new double[countsExt][][];
                        double[][][] lstcoords = new double[countsExt][][];
                        double[][][] lstb      = new double[countsExt][][];

                        double[][][] lstaAN      = new double[countsExt][][];
                        double[][][] lstvAN      = new double[countsExt][][];
                        double[][][] lstdisplAN  = new double[countsExt][][];
                        double[][][] lstcoordsAN = new double[countsExt][][];
                        double[][][] lstFAN      = new double[countsExt][][];

                        double[][][] lstVmp = new double[countsExt][][];

                        strRead              = sr.ReadLine();
                        double dtExt         = Convert.ToDouble(strRead);
                        string[] strload     = sr.ReadLine().Split(':');
                        points               = new point[numP];
                        ExtLoadType loadType = ExtLoad.getPoint(strload[2]);
                        if (Modeltype == Models.particle)
                        {
                            for (int np = 0; np < numP; np++)
                            {
                                points[np] = new point
                                {
                                    ExtLoad = loadType
                                };
                            }
                        }
                        else
                        {
                            for (int np = 0; np < numP; np++)
                            {
                                points[np]         = new point();
                                points[np].ExtLoad = ExtLoadType.none;
                            }
                        }
                        points[Convert.ToInt32(strload[1])].ExtLoad = ExtLoad.getPoint(strload[2]);
                        sr.Close();
                        fs.Close();
                        calc.t(countsExt, dtExt, ref time);
                        initArr._3d(numP, 3, ref lstF);
                        initArr._3d(numP, 3, ref lstdispla);
                        initArr._3d(numP, 3, ref lstcoords);
                        initArr.Coords(L / numP, points, ref lstcoords);
                        initArr._3d(numP, 3, ref lstFem1);
                        initArr._3d(numP, 3, ref lstFep1);
                        initArr._3d(numP, 3, ref lsta);
                        initArr._3d(numP, 3, ref lstv);
                        initArr._3d(numP, 3, ref lstb);
                        initArr._3d(numP, 3, ref lstaAN);
                        initArr._3d(numP, 3, ref lstvAN);
                        initArr._3d(numP, 3, ref lstdisplAN);
                        initArr._3d(numP, 3, ref lstcoordsAN);
                        initArr._3d(numP, 3, ref lstFAN);
                        initArr._3d(numP, 3, ref lstVmp);

                        if (CalcType == CalcTypes.statical)
                        {
                            calc.StaticMovement(flname, points, Modeltype, IntegShematype, CalcType, MaterialModeltype, Retype, IsConsoleOut,
                                                L, b, h, ro, numP, countsExt, elastic, v0, vamp, D, Re, time,
                                                ref lstF, ref lstFep1, ref lstFem1, ref lsta, ref lstb, ref lstv, ref lstdispla, ref lstcoords, ref lstvAN);
                        }
                        else
                        {
                            calc.Movement(flname, points, Modeltype, IntegShematype, CalcType, MaterialModeltype, Retype, IsConsoleOut,
                                          L, b, h, ro, numP, countsExt, elastic, v0, vamp, D, Re, time,
                                          ref lstF, ref lstFep1, ref lstFem1, ref lsta, ref lstb, ref lstv, ref lstdispla, ref lstcoords,
                                          ref lstaAN, ref lstvAN, ref lstdisplAN, ref lstcoordsAN, ref lstFAN, ref lstVmp);
                        }

                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            plotxy plot = new plotxy();

                            plot = new plotxy();
                            plot.Show();
                            plot.dt     = dtExt;
                            plot.time   = time;
                            plot.coords = lstcoords;
                            plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "x(t)", "Time", "X", false, System.Drawing.Color.Red);
                            plot.initControls();
                            plotxys.Add(plot);

                            if (Modeltype == Models.particle)
                            {
                                plot = new plotxy();
                                plot.Show();
                                plot.dt     = dtExt;
                                plot.time   = time;
                                plot.coords = lstdisplAN;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "displAN(t)", "t", "displAN", false, System.Drawing.Color.Red);
                                plot.initControls();
                                plot.coords = lstdispla;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "displ(t)", "t", "displ", true, System.Drawing.Color.Blue);
                                plot.initControls();
                                plotxys.Add(plot);

                                plot = new plotxy();
                                plot.Show();
                                plot.dt     = dtExt;
                                plot.time   = time;
                                plot.coords = lstvAN;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "vAN(t)", "t", "vAN", false, System.Drawing.Color.Red);
                                plot.initControls();
                                plot.coords = lstv;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "v(t)", "t", "v", true, System.Drawing.Color.Blue);
                                plot.initControls();
                                plotxys.Add(plot);

                                plot = new plotxy();
                                plot.Show();
                                plot.dt     = dtExt;
                                plot.time   = time;
                                plot.coords = lstaAN;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "aAN(t)", "t", "aAN", false, System.Drawing.Color.Red);
                                plot.initControls();
                                plot.coords = lsta;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "a(t)", "t", "a", true, System.Drawing.Color.Blue);
                                plot.initControls();
                                plotxys.Add(plot);

                                plot = new plotxy();
                                plot.Show();
                                plot.dt     = dtExt;
                                plot.time   = time;
                                plot.coords = lstFAN;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "Fan(t)", "t", "Fan", false, System.Drawing.Color.Red);
                                plot.initControls();
                                plot.coords = lstF;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "F(t)", "t", "F", true, System.Drawing.Color.Blue);
                                plot.initControls();
                                plotxys.Add(plot);

                                plot = new plotxy();
                                plot.Show();
                                plot.dt     = dtExt;
                                plot.time   = time;
                                plot.coords = lstVmp;
                                plot.draw2d(axistype.t, axistype.x, numP, 1, true, false, "Fan(t)", "t", "Fan", false, System.Drawing.Color.Red);
                                plot.initControls();
                                plotxys.Add(plot);
                            }
                            //plot.Show();
                            //plot.draw2d(axistype.t, axistype.x, lstFep1, time, numP, 1, false, false, "Fep1(x)", "t", "N");
                            //plotxys.Add(plot);
                        }));
                        ClearEffect(this);
                        //GC.Collect();
                    }
                }
                else
                {
                    MessageBox.Show("В файле нет нагруженных точек");
                }
            });
            thrdraw.Start();
        }
 static double pointsLength(point p1, point p2)
 {
     return(Math.Sqrt(Math.Pow(p2.x - p1.x, 2) + Math.Pow(p2.y - p1.y, 2)));
 }
Example #34
0
 _debugDrawables.Add(new DebugPoint(point, color, duration));
Example #35
0
        protected override void OnRender(int x, int y, int width, int height)
        {
            //x and y are Left and Top anyway
            //x = Left;
            //y = Top;
            int maxX    = Width - 3;
            int icoSize = _font.Height + 8;

            // Draw the container
            if (Focused)
            {
                Core.Screen.DrawRectangle(Core.SystemColors.SelectionColor, 1, Left, Top, Width, Height, 0, 0,
                                          Core.SystemColors.WindowColor, 0, 0, Core.SystemColors.WindowColor, 0, 0, 256);
            }
            else
            {
                Core.Screen.DrawRectangle(Core.SystemColors.BorderColor, 1, Left, Top, Width, Height, 0, 0,
                                          Core.SystemColors.WindowColor, 0, 0, Core.SystemColors.WindowColor, 0, 0, 256);
            }

            int yy = y - ScrollY;
            int xx = x - ScrollX;

            // Draw Nodes
            if (_nodes != null)
            {
                Core.Screen.SetClippingRectangle(Left + 1, Top + 1, Width - 2, Height - 2);
                for (int i = 0; i < _nodes.Length; i++)
                {
                    int tW;
                    int tH;
                    _font.ComputeExtent(_nodes[i].Text, out tW, out tH);
                    _nodes[i].Bounds = new rect(xx, yy, Width + (xx - Left), _font.Height + 8);
                    if (maxX < tW + icoSize + 12 + xx)
                    {
                        maxX = tW + icoSize + 12 + xx;
                    }

                    if (yy + _font.Height + 4 > 0 && yy < Top + Height)
                    {
                        // Draw Icon if node has children
                        if (_nodes[i].Length > 0)
                        {
                            Core.Screen.DrawRectangle(Colors.DarkGray, 1, xx + 2, yy + 2, icoSize - 4, icoSize - 4, 0, 0, Colors.Ghost, xx + 2, yy + 2, Colors.LightGray, xx + 2, yy + 6, 256);
                            Core.Screen.DrawTextInRect((_nodes[i].Expanded) ? "-" : "+", xx + 2, yy + 4, icoSize - 4, _font.Height, Bitmap.DT_AlignmentCenter, Colors.Charcoal, _font);
                        }

                        // Draw Node Text
                        Core.Screen.DrawTextInRect(_nodes[i].Text, xx + icoSize + 4, yy + 4, tW, _font.Height, Bitmap.DT_TrimmingCharacterEllipsis,
                                                   (_nodes[i].Selected) ? _selColor : _color, _font);
                    }

                    yy += icoSize + 4;

                    if (_nodes[i].Expanded)
                    {
                        point e = RenderSubNodes(_nodes[i], xx + icoSize, yy, icoSize);
                        yy = e.Y;
                        if (e.X > maxX)
                        {
                            maxX = e.X;
                        }
                    }
                }
            }

            RequiredHeight = ScrollY + yy;
            RequiredWidth  = ScrollX + maxX;

            base.OnRender(x, y, width, height);
        }
Example #36
0
 // functie pentru a calcula distanta dintre doua puncte A si B
 static float lungime(point A, point B)
 {
     return((float)Math.Sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)));
 }
Example #37
0
        /// <summary>
        /// This function will return the shortest path between two line segments in Kilometers (XYZ is in Kilometer form)
        /// </summary>
        /// <param name="position1"></param>
        /// <param name="position2"></param>
        /// <returns></returns>
        private double FindShortestDistanceBetweenLines(Position position1, Position position2)
        {
            double EPS = 0.00000001;

            point delta21 = new point();

            delta21.x = (double)(position1.X2 - position1.X1);
            delta21.y = (double)(position1.Y2 - position1.Y1);
            delta21.x = (double)(position1.Z2 - position1.Z1);

            point delta41 = new point();

            delta41.x = (double)(position2.X2 - position2.X1);
            delta41.y = (double)(position2.Y2 - position2.Y1);
            delta41.z = (double)(position2.Z2 - position2.Z1);

            point delta13 = new point();

            delta13.x = (double)(position1.X1 - position2.X1);
            delta13.y = (double)(position1.Y1 - position2.Y1);
            delta13.z = (double)(position1.Z1 - position2.Z1);

            double a = dot(delta21, delta21);
            double b = dot(delta21, delta41);
            double c = dot(delta41, delta41);
            double d = dot(delta21, delta13);
            double e = dot(delta41, delta13);
            double D = a * c - b * b;

            double sc, sN, sD = D;
            double tc, tN, tD = D;

            if (D < EPS)
            {
                sN = 0.0;
                sD = 1.0;
                tN = e;
                tD = c;
            }
            else
            {
                sN = (b * e - c * d);
                tN = (a * e - b * d);
                if (sN < 0.0)
                {
                    sN = 0.0;
                    tN = e;
                    tD = c;
                }
                else if (sN > sD)
                {
                    sN = sD;
                    tN = e + b;
                    tD = c;
                }
            }

            if (tN < 0.0)
            {
                tN = 0.0;

                if (-d < 0.0)
                {
                    sN = 0.0;
                }
                else if (-d > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = -d;
                    sD = a;
                }
            }
            else if (tN > tD)
            {
                tN = tD;
                if ((-d + b) < 0.0)
                {
                    sN = 0;
                }
                else if ((-d + b) > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = (-d + b);
                    sD = a;
                }
            }

            if (Math.Abs(sN) < EPS)
            {
                sc = 0.0;
            }
            else
            {
                sc = sN / sD;
            }
            if (Math.Abs(tN) < EPS)
            {
                tc = 0.0;
            }
            else
            {
                tc = tN / tD;
            }

            point dP = new point();

            dP.x = delta13.x + (sc * delta21.x) - (tc * delta41.x);
            dP.y = delta13.y + (sc * delta21.y) - (tc * delta41.y);
            dP.z = delta13.z + (sc * delta21.z) - (tc * delta41.z);

            return(Math.Sqrt(dot(dP, dP)));
        }
 public tribox(Point3f[] pts)
 {
     Cedges = new edge[6];
     Points = new point[4];
     Points[0] = new point(pts[0]); Points[1] = new point(pts[1]);
     Points[2] = new point(pts[2]); Points[3] = new point(pts[3]);
     Cedges[0] = new edge(Points[0], Points[1]);
     Cedges[1] = new edge(Points[0], Points[2]);
     Cedges[2] = new edge(Points[0], Points[3]);
     Cedges[3] = new edge(Points[1], Points[2]);
     Cedges[4] = new edge(Points[2], Points[3]);
     Cedges[5] = new edge(Points[3], Points[1]);
 }
Example #39
0
 private double norm(point c1)
 {
     return(Math.Sqrt(dot(c1, c1)));
 }
Example #40
0
 private static bool ishome(int[,] grid, point p)
 {
     return (grid[p.x, p.y] == 1);
 }
Example #41
0
 internal M11Point(point P) : base(P.Par2, P.Par3)
 {
     _pfsPoint = P;
 }
Example #42
0
        private void pane_MouseUp(object sender, MouseEventArgs e)
        {
            Pane pane = (Pane)sender;

            switch (e.Button)
            {
            case MouseButtons.Left:
                leftDown = false;
                break;

            case MouseButtons.Right:
                rightDown = false;
                break;
            }
            if (bothDown && (leftDown || rightDown))
            {
                point p = new point();
                p.x = pane._x;
                p.y = pane._y;
                showaround_pane(p);
                AroundReset(pane._x, pane._y);
                return;
            }
            if (bothDown && !(leftDown || rightDown))
            {
                bothDown = false;
                return;
            }
            if (!pane.ClientRectangle.Contains(e.Location))
            {
                if (pane._Stat == 0)
                {
                    pane.BackgroundImage = Properties.Resources.grid;
                }
                return;
            }
            if (this.FirstClick == 0)
            {
                marks = 0;
                this.LayMines(pane);
                this.FirstClick = 1;
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        Pane pane2 = (Pane)this.Controls[Map[i, j]];
                        pane2._Around = this._Count_Round(i, j);
                    }
                }
                if (Form1.mode == 2)
                {
                    point p = new point();
                    p.x = Form1.col / 2;
                    p.y = Form1.row / 2;
                    t   = new Thread(Form1._instance.mineFild2.AI_Start);
                    t.Start(p);
                }
                Form1._instance.led1.Set(pnum);
                Form1._instance.led2.t = new Thread(Form1._instance.led2.Timekeeping);
                Form1._instance.led2.t.Start();
            }
            if (e.Button == MouseButtons.Right)
            {
                if (pane._Stat == 2)
                {
                    pane.BackgroundImage = Properties.Resources.grid;
                    pane._Stat           = 0;
                    marks--;
                    Form1._instance.led1.Reset();
                    Form1._instance.led1.Set(pnum - marks);
                }
                else
                {
                    if (pane._Stat == 0)
                    {
                        pane._Stat           = 2;
                        pane.BackgroundImage = Properties.Resources.Image1;
                        marks++;
                        Form1._instance.led1.Reset();
                        Form1._instance.led1.Set(pnum - marks);
                    }
                }
            }
            else
            {
                this._Displayround(pane);
            }
        }
Example #43
0
 public static Point Convert(this point point)
 {
     return(new Point((short)point.x, (short)point.y));
 }
Example #44
0
        /// <summary>
        /// AI 接口
        /// </summary>
        /// <param name="x">电脑一开始点击的位置的横坐标</param>
        /// <param name="y">电脑一开始点击的位置的纵坐标</param>
        public void AI_Mode(int x, int y)
        {
            AI_Init();
            if (this.FirstClick == 0)
            {
                this.FirstClick = 1;
                Pane pane = (Pane)this.Controls[Map[x, y]];
                this.LayMines(pane);

                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        Pane pane2 = (Pane)this.Controls[Map[i, j]];
                        pane2._Around = this._Count_Round(i, j);
                    }
                }
            }
            point t = new point();

            t.x = x; t.y = y;
            AI_think(t);
            int u;

            while (gameStat != 1)
            {
                u = _DeepThink_Init();
                int stat = AI_DeepThink(u);
                Console.WriteLine("stat = " + stat);
                int cnt = 0;
                for (int i = 0; i < this.row; i++)
                {
                    for (int j = 0; j < this.col; j++)
                    {
                        Pane pane = (Pane)this.Controls[Map[i, j]];
                        if ((pane._Stat == 1) && (pane._Around != 0))
                        {
                            point pos = new point();
                            pos.x     = i;
                            pos.y     = j;
                            mp[cnt++] = pos;
                        }
                    }
                }
                if (stat == 1)
                {
                    _Think(cnt);
                }
                else
                {
                    int   tar = 0;
                    point pos = new point();
                    pos.x = -1;
                    int    flg = 0;
                    Pane[] ran = new Pane[4];
                    ran[0] = (Pane)this.Controls[Map[0, 0]];
                    ran[1] = (Pane)this.Controls[Map[0, this.col - 1]];
                    ran[2] = (Pane)this.Controls[Map[this.row - 1, 0]];
                    ran[3] = (Pane)this.Controls[Map[this.row - 1, this.col - 1]];
                    for (int i = 0; i < 4; i++)
                    {
                        if (ran[i]._Stat == 0)
                        {
                            pos.x = ran[i]._x;
                            pos.y = ran[i]._y;
                            flg   = 1;
                            break;
                        }
                    }
                    if (flg == 0)
                    {
                        for (int i = 0; i < cnt; i++)
                        {
                            for (int k = 0; k < 8; k++)
                            {
                                int xx = nx[k] + mp[i].x;
                                int yy = ny[k] + mp[i].y;
                                if (Canset(xx, yy))
                                {
                                    Pane pane = (Pane)this.Controls[Map[xx, yy]];
                                    if (pane._Stat == 0)
                                    {
                                        pos.x = xx;
                                        pos.y = yy;
                                        tar   = 1;
                                        break;
                                    }
                                }
                            }
                            if (tar == 1)
                            {
                                break;
                            }
                        }
                    }
                    if (pos.x == -1)
                    {
                        for (int i = 0; i < this.row; i++)
                        {
                            for (int j = 0; j < this.col; j++)
                            {
                                Pane pane = (Pane)this.Controls[Map[i, j]];
                                if (pane._Stat == 0)
                                {
                                    pos.x = i;
                                    pos.y = j;
                                }
                            }
                        }
                    }
                    AI_think(pos);
                }
            }
        }
Example #45
0
    void determinePoints(string p_input)
    {
        Stack <point> returnValues = new Stack <point>();
        point         lastPoint    = new point(new Vector3(transform.position.x, transform.position.y + stepHeight, transform.position.z), transform.eulerAngles, inputHeight, S);//初始位置和父物体关联

        returnValues.Push(lastPoint);

        foreach (char c in p_input)
        {
            switch (c)
            {
            case 'S':     //Stem
                points.Add(lastPoint);

                point newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, S);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;


            case 'P':     //Petal
                points.Add(lastPoint);

                newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, P);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;

            case 'L':     //Leaf
                points.Add(lastPoint);

                newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, L);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;

            case 'D':     //Leaf
                points.Add(lastPoint);

                newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, D);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;

            case 'H':     //Leaf
                points.Add(lastPoint);

                newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, H);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;

            case 'F':     //Leaf
                points.Add(lastPoint);

                newPoint = new point(lastPoint.Pos + new Vector3(0, lastPoint.BranchLength, 0), lastPoint.Angle, inputHeight, F);
                newPoint.BranchLength = lastPoint.BranchLength * scalingFactor;
                if (newPoint.BranchLength <= 0.0f)
                {
                    newPoint.BranchLength = 0.001f;
                }

                newPoint.Angle.y = lastPoint.Angle.y;

                //add random
                if (isRandom == true)
                {
                    newPoint.Angle.y += UnityEngine.Random.Range(randomRange.x, randomRange.y);
                }

                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(newPoint.Angle.x, 0, 0));
                newPoint.Pos = pivot(newPoint.Pos, lastPoint.Pos, new Vector3(0, newPoint.Angle.y, 0));
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);
                //newPoint.Point = pivot(newPoint.Point, lastPoint.Point, Vector3.zero);

                points.Add(newPoint);
                lastPoint = newPoint;
                break;


            case '+':     // Rotate
                lastPoint.Angle.x += angle;
                break;

            case '[':     // Save State
                returnValues.Push(lastPoint);
                break;

            case '-':     // Rotate
                lastPoint.Angle.x += -angle;
                break;

            case ']':     // Load Saved State
                lastPoint = returnValues.Pop();
                break;

            case '*':     // Load Saved State
                lastPoint.Angle.z += angle;
                break;

            case '&':     // Load Saved State
                lastPoint.Angle.z -= angle;
                break;

            case '/':     // Load Saved State
                lastPoint.Angle.y += angle;
                break;

            case '?':     // Load Saved State
                lastPoint.Angle.y -= angle;
                break;
            }
        }
    }
Example #46
0
        /// <summary>
        /// AI 走决定点下当前点之后的影响
        /// </summary>
        /// <param name="u"></param>
        public void AI_think(point u)
        {
            if (u.x == -1)
            {
                return;
            }
            if (gameStat == 1)
            {
                return;
            }
            Pane         now = (Pane)this.Controls[Map[u.x, u.y]];
            Queue <Pane> q   = new Queue <Pane>();

            q.Clear();
            if (now._Has_mine)
            {
                //this._ShowAll();
                gameStat = 1;
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                now._Open();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("You win, AI hit a bomb just now.");
                    Form1.status = 22;
                    break;

                case 21:
                    MessageBox.Show("Draw.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("Lose");
                return;
            }
            q.Enqueue(now);
            vis[now._x, now._y] = 1;
            int flag = 1;

            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (vis[i, j] == 0)
                    {
                        flag = 0;
                    }
                }
            }
            if (flag == 1)
            {
                gameStat = 1;
                now._Open();
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 21:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("win");
                return;
            }
            int cnt = 0;

            while (q.Count != 0)
            {
                Pane fr = q.Dequeue();
                if (fr._Around != 0)
                {
                    fr._Open();
                    point pos = new point();
                    pos.set_val(fr._x, fr._y);
                    continue;
                }
                fr._Open();
                for (int i = 0; i < 8; i++)
                {
                    int xx = nx[i] + fr._x;
                    int yy = ny[i] + fr._y;
                    if (Canset(xx, yy) && vis[xx, yy] == 0)
                    {
                        Pane t = (Pane)this.Controls[Map[xx, yy]];
                        vis[xx, yy] = 1;
                        q.Enqueue(t);
                    }
                }
            }
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    Pane pane = (Pane)this.Controls[Map[i, j]];
                    if ((pane._Stat == 1) && (pane._Around != 0))
                    {
                        point pos = new point();
                        pos.x     = i;
                        pos.y     = j;
                        mp[cnt++] = pos;
                    }
                }
            }
            flag = 1;
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (vis[i, j] == 0)
                    {
                        flag = 0;
                    }
                }
            }
            if (flag == 1)
            {
                gameStat = 1;
                now._Open();
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 21:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("win");
                return;
            }
            _Think(cnt);
        }
Example #47
0
 public static point Createpoint(int rowid)
 {
     point point = new point();
     point.rowid = rowid;
     return point;
 }
Example #48
0
        /// <summary>
        /// AI浅层思考 不需要推理能确定是雷的点
        /// </summary>
        /// <param name="cnt"></param>
        public void _Think(int cnt)
        {
            for (int i = 0; i < cnt; i++)
            {
                mp[i].around = _Unopen(mp[i]);
            }
            for (int i = 0; i < cnt; i++)
            {
                for (int j = 0; j < cnt; j++)
                {
                    Pane pane1 = (Pane)this.Controls[Map[mp[i].x, mp[i].y]];
                    Pane pane2 = (Pane)this.Controls[Map[mp[j].x, mp[j].y]];
                    int  ui    = mp[i].around;
                    int  uj    = mp[j].around;
                    if (ui == uj)
                    {
                        if (pane1._Around < pane2._Around)
                        {
                            point t = mp[i]; mp[i] = mp[j]; mp[j] = t;
                        }
                    }
                    if (ui < uj)
                    {
                        point t = mp[i]; mp[i] = mp[j]; mp[j] = t;
                    }
                }
            }
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (_is_mine_rate[i, j] == 0 || _is_mine_rate[i, j] == 1)
                    {
                        continue;
                    }
                    _is_mine_rate[i, j] = -1;
                }
            }
            Queue <point> rec = new Queue <point>();

            rec.Clear();
            for (int i = 0; i < cnt; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int   xx  = nx[j] + mp[i].x;
                    int   yy  = ny[j] + mp[i].y;
                    point pos = new point();
                    pos.x = xx;
                    pos.y = yy;
                    if (Canset(xx, yy))
                    {
                        Pane pane  = (Pane)this.Controls[Map[xx, yy]];
                        Pane pane2 = (Pane)this.Controls[Map[mp[i].x, mp[i].y]];
                        if (pane._Stat == 0)
                        {
                            double a = (double)((double)pane2._Around - _Possible_mine(pane2)) / ((double)_Unopen(mp[i]));
                            _is_mine_rate[xx, yy] = (a == 0)?0:this.max(a, (double)(_is_mine_rate[xx, yy]));
                            if (_is_mine_rate[xx, yy] == 1)
                            {
                                _is_mine[xx, yy] = 1;

                                pane._Mark();
                            }
                            else
                            {
                                if (_is_mine_rate[xx, yy] == 0 && _vis[xx, yy] == 0)
                                {
                                    point tmp = new point();
                                    tmp.x = xx;
                                    tmp.y = yy;
                                    rec.Enqueue(tmp);
                                }
                            }
                        }
                        if (pane._Stat == 2)
                        {
                            _is_mine_rate[pane._x, pane._y] = 1;
                            _is_mine[xx, yy] = 1;
                        }
                    }
                }
            }
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (_is_mine_rate[i, j] == 0)
                    {
                        point tmp = new point();
                        tmp.x = i;
                        tmp.y = j;
                        if (_vis[i, j] == 0)
                        {
                            _vis[i, j] = 1;
                        }
                    }
                    // Console.Write(Math.Round(_is_mine_rate[i, j], 3) + "  ");
                }
                // Console.WriteLine();
            }
            //Console.WriteLine();

            if (rec.Count == 0)
            {
                int flag = 1;
                for (int i = 0; i < this.row; i++)
                {
                    for (int j = 0; j < this.col; j++)
                    {
                        Pane pane = (Pane)this.Controls[Map[i, j]];
                        if (vis[i, j] == 0 && pane._Stat != 2)
                        {
                            flag = 0;
                        }
                    }
                }
                if (flag == 1)
                {
                    Form1._instance.led2.timer.Close();
                    Form1._instance.led2.t.Abort();
                    switch (Form1.status)
                    {
                    case 20:
                        MessageBox.Show("Defeat.");
                        Form1.status = 23;
                        break;

                    case 21:
                        MessageBox.Show("Defeat.");
                        Form1.status = 23;
                        break;

                    case 22:
                        MessageBox.Show("You win.");
                        break;
                    }
                    //MessageBox.Show("win");
                    gameStat = 1;
                    return;
                }
                Console.WriteLine("Can't Solve Now!");
                return;
            }
            while (rec.Count != 0)
            {
                Thread.Sleep(Delay);
                point fr = rec.Dequeue();
                AI_think(fr);
            }
        }
Example #49
0
 select PowerLevel(point, serial)).Sum();
Example #50
0
        void Scan()
        {
            foreach (var start in KeyPoints)
            {
                char[] Map = map.ToCharArray();
                //setChar(Map, entrance.X, entrance.Y, '0');
                Stack <point>   toExplore = new Stack <point>();
                Stack <int>     lengths   = new Stack <int>();
                HashSet <point> explored  = new HashSet <point>();

                //Console.WriteLine("GO! "+start.Value);

                toExplore.Push(start.Key);
                lengths.Push(0);

                while (toExplore.Count > 0)
                {
                    point p = toExplore.Pop();
                    int   l = lengths.Pop();

                    if (explored.Contains(p))
                    {
                        continue;
                    }

                    explored.Add(p);

                    if (pos(Map, p.X, p.Y) == '@')
                    {
                        if (start.Value != KeyPoints[p])
                        {
                            // Console.WriteLine("Path from {0} to {1} takes {2}", start.Value, KeyPoints[p], l - 1);
                            Links[start.Value].addLink(KeyPoints[p], l - 1);
                        }
                    }

                    if (!explored.Contains(new point(p.X + 1, p.Y)) && pos(Map, p.X + 1, p.Y) == '.' || pos(Map, p.X + 1, p.Y) == '@')
                    {
                        toExplore.Push(new point(p.X + 1, p.Y)); lengths.Push(l + 1);
                    }
                    if (!explored.Contains(new point(p.X - 1, p.Y)) && pos(Map, p.X - 1, p.Y) == '.' || pos(Map, p.X - 1, p.Y) == '@')
                    {
                        toExplore.Push(new point(p.X - 1, p.Y)); lengths.Push(l + 1);
                    }
                    if (!explored.Contains(new point(p.X, p.Y + 1)) && pos(Map, p.X, p.Y + 1) == '.' || pos(Map, p.X, p.Y + 1) == '@')
                    {
                        toExplore.Push(new point(p.X, p.Y + 1)); lengths.Push(l + 1);
                    }
                    if (!explored.Contains(new point(p.X, p.Y - 1)) && pos(Map, p.X, p.Y - 1) == '.' || pos(Map, p.X, p.Y - 1) == '@')
                    {
                        toExplore.Push(new point(p.X, p.Y - 1)); lengths.Push(l + 1);
                    }

                    /*
                     * ---------------------------------
                     * ---------------------------------
                     * ---------------------------------
                     * ALL HAIL THE MIGHTY CODE BRICK!!!
                     * ---------------------------------
                     * ---------------------------------
                     * ---------------------------------
                     */
                }
            }
        }
this = ArcSegment(point, size, rotationAngle, sweepDirection, arcSize);
Example #52
0
 public double calcDistance(point parPointA, point parPointB)
 {
     return Math.Sqrt(Math.Pow(parPointA.x - parPointB.x, 2) + Math.Pow(parPointA.y - parPointB.y, 2));
 }
Example #53
0
        public static int zong_num; //纵将的个数

        #endregion Fields

        #region Methods

        public static int bfs(int[,] matrix, string[] name, ref Queue<int[,]> ansinmatrix)
        {
            progress haha = new progress();
            haha.Show();
            zk[] data;
            try
            {
                data = new zk[45000000];
            }
            catch (System.OutOfMemoryException ex)
            {
                haha.Close();
                return -1;
            }
            int i, j;
            for (i = 0; i < 45000000; i++) data[i].vis = false;
            status init = new status();
            init.init();
            int[] universe = { 0, 1, 2, 3, 4, 5 };
            int flag = 0;
            matrix_to_status(universe, matrix, ref init);
            zk start;
            start.cnt = start.cnt_universe = start.pre = 0;
            start.vis = false;
            start.pre = -1; start.vis = true; status_to_num(init, ref start.cnt, ref start.cnt_universe);
            Queue<zk> key = new Queue<zk>();
            key.Enqueue(start);
            int end = start.cnt;
            while (key.Count != 0)
            {
                zk zk_temp = key.ElementAt(0);
                key.Dequeue();
                status cnt = new status();
                cnt.init();
                num_to_status(zk_temp.cnt, zk_temp.cnt_universe, ref cnt);
                for (i = 1; i <= 2; i++)
                {
                    for (j = 1; j <= 4; j++)
                    {
                        status temp = new status();
                        temp.init();
                        if (move(cnt, i, j, ref temp))
                        {
                            int temp_num = 0, temp_universe = 0;
                            status_to_num(temp, ref temp_num, ref temp_universe);
                            if (!data[temp_num].vis)
                            {
                                data[temp_num].vis = true;
                                data[temp_num].cnt = temp_num; data[temp_num].cnt_universe = temp_universe; data[temp_num].pre = zk_temp.cnt;
                                zk zk_temp1;
                                zk_temp1.cnt = temp_num; zk_temp1.cnt_universe = temp_universe; zk_temp1.pre = zk_temp.cnt;
                                zk_temp1.vis = true;
                                key.Enqueue(zk_temp1);
                                if (judge(temp)) { flag = zk_temp1.cnt; break; }
                            }
                        } if (flag != 0) break;
                    } if (flag != 0) break;
                } if (flag != 0) break;
            }
            haha.Close();
            if (flag == 0)
            {
                return 0;
            }
            Queue<int> yes = new Queue<int>();
            yes.Enqueue(flag);
            while (true)
            {
                flag = data[flag].pre;
                yes.Enqueue(flag);
                if (flag == end) break;
            }
            status getansmaxtrix = new status();
            getansmaxtrix.init();
            for (i = yes.Count() - 1; i >= 0; i--)
            {
                int[,] ansmatrix = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
                getansmaxtrix.init();
                num_to_status(data[yes.ElementAt(i)].cnt, data[yes.ElementAt(i)].cnt_universe, ref getansmaxtrix);
                status_to_matrix(getansmaxtrix, ansmatrix);
                for (int ii = 0; ii < 5; ii++)
                {
                    for (int jj = 0; jj < 4; jj++)
                    {
                        if (1 <= ansmatrix[ii, jj] && ansmatrix[ii, jj] <= 5)
                        {
                            ansmatrix[ii, jj] = getansmaxtrix.universe[ansmatrix[ii, jj]];
                        }
                    }
                }
                ansinmatrix.Enqueue(ansmatrix);
            }
            /*inputstatus haha = new inputstatus();
            haha.Show();
            for (i = 0; i <ansinmatrix.Count(); i++)
            {
                haha.show_num(i);
                haha.show_matrix(ansinmatrix.ElementAt(i));
            }*/
            ansform = new showans();
            ansform.Show();
            int[,] pre_matrix = new int[5, 4];
            int[,] cnt_matrix = new int[5, 4];
            status prestatus = new status();
            status cntstatus = new status();
            prestatus.init();
            cntstatus.init();
            name[6] = "曹操";
            for (int f**k = yes.Count() - 1; f**k >= 1; f**k--)
            {
                prestatus.init();
                cntstatus.init();
                num_to_status(data[yes.ElementAt(f**k)].cnt, data[yes.ElementAt(f**k)].cnt_universe, ref prestatus);
                num_to_status(data[yes.ElementAt(f**k - 1)].cnt, data[yes.ElementAt(f**k - 1)].cnt_universe, ref cntstatus);
                ansform.write_step(yes.Count() - f**k);
                status_to_matrix(prestatus, pre_matrix);
                for (i = 0; i < 5; i++)
                    for (j = 0; j < 4; j++)
                        if (1 <= pre_matrix[i, j] && pre_matrix[i, j] <= 5) pre_matrix[i, j] = prestatus.universe[pre_matrix[i, j]];
                status_to_matrix(cntstatus, cnt_matrix);
                for (i = 0; i < 5; i++)
                    for (j = 0; j < 4; j++)
                        if (1 <= cnt_matrix[i, j] && cnt_matrix[i, j] <= 5) cnt_matrix[i, j] = cntstatus.universe[cnt_matrix[i, j]];
                int[,] pre_pos = new int[11, 2];
                int[,] cnt_pos = new int[11, 2];
                for (i = 0; i < 11; i++) { for (j = 0; j < 2; j++) { pre_pos[i, j] = 0; } }
                for (i = 0; i < 11; i++) { for (j = 0; j < 2; j++) { cnt_pos[i, j] = 0; } }
                Queue<point> pre_bing = new Queue<point>();
                Queue<point> cnt_bing = new Queue<point>();
                point temp = new point();
                for (i = 0; i < 5; i++)
                {
                    for (j = 0; j < 4; j++)
                    {
                        if (pre_matrix[i, j] == 7) { temp.x = i + 1; temp.y = j + 1; pre_bing.Enqueue(temp); }
                        else if (pre_pos[pre_matrix[i, j], 0] == 0) { pre_pos[pre_matrix[i, j], 0] = i + 1; pre_pos[pre_matrix[i, j], 1] = j + 1; }
                        if (cnt_matrix[i, j] == 7) { temp.x = i + 1; temp.y = j + 1; cnt_bing.Enqueue(temp); }
                        else if (cnt_pos[cnt_matrix[i, j], 0] == 0) { cnt_pos[cnt_matrix[i, j], 0] = i + 1; cnt_pos[cnt_matrix[i, j], 1] = j + 1; }
                    }
                }
                int move_flag = 0;
                for (i = 1; i <= 6; i++)
                {
                    if (pre_pos[i, 0] - cnt_pos[i, 0] == 1) { ansform.write_word(name[i]); ansform.write_word_line("向上移动一格"); move_flag = 1; }
                    else if (pre_pos[i, 0] - cnt_pos[i, 0] == -1) { ansform.write_word(name[i]); ansform.write_word_line("向下移动一格"); move_flag = 1; }
                    if (pre_pos[i, 1] - cnt_pos[i, 1] == 1) { ansform.write_word(name[i]); ansform.write_word_line("向左移动一格"); move_flag = 1; }
                    if (pre_pos[i, 1] - cnt_pos[i, 1] == -1) { ansform.write_word(name[i]); ansform.write_word_line("向右移动一格"); move_flag = 1; }
                }
                if (move_flag == 1) continue;
                int[] pre_bing_vis = { 0, 0, 0, 0 };
                int[] cnt_bing_vis = { 0, 0, 0, 0 };
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 4; j++)
                    {
                        if (pre_bing.ElementAt(i).x == cnt_bing.ElementAt(j).x && pre_bing.ElementAt(i).y == cnt_bing.ElementAt(j).y) { pre_bing_vis[i] = cnt_bing_vis[j] = 1; }
                    }
                }
                int posi, posj;
                for (posi = 0; posi < 4; posi++) if (pre_bing_vis[posi] == 0) break;
                for (posj = 0; posj < 4; posj++) if (cnt_bing_vis[posj] == 0) break;
                if (pre_bing.ElementAt(posi).x - cnt_bing.ElementAt(posj).x == 1) { ansform.write_soilder(pre_bing.ElementAt(posi).x, pre_bing.ElementAt(posi).y, "向上移一位"); continue; }
                else if (pre_bing.ElementAt(posi).x - cnt_bing.ElementAt(posj).x == -1) { ansform.write_soilder(pre_bing.ElementAt(posi).x, pre_bing.ElementAt(posi).y, "向下移一位"); continue; }
                else if (pre_bing.ElementAt(posi).y - cnt_bing.ElementAt(posj).y == 1) { ansform.write_soilder(pre_bing.ElementAt(posi).x, pre_bing.ElementAt(posi).y, "向左移一位"); continue; }
                else if (pre_bing.ElementAt(posi).y - cnt_bing.ElementAt(posj).y == -1) { ansform.write_soilder(pre_bing.ElementAt(posi).x, pre_bing.ElementAt(posi).y, "向右移一位"); continue; }
                prestatus.init();
                cntstatus.init();
            }
            return 1;
        }
Example #54
0
 public edge(point start, point end)
 {
     this.start = start;
     this.end   = end;
     this.dist  = Mathf.Infinity;
 }
Example #55
0
 //  public Point();
 //  {
 //   Console.WriteLine("Yeeeey!");
 //  }
 public void add(point othe) // static void Add(Point this, Point p) {}
 {
     x += othe.x;
     y += othe.y;
 }
Example #56
0
 public point toPoint(cell a)
 {
     point res;
         float x = a.x * levelSettings.objectSize + levelSettings.objectSize/2;
         float y = a.y * levelSettings.objectSize + levelSettings.objectSize/2;
         res = new point(new Vector3(x,y,0));
         return res;
 }
Example #57
0
 private void TestAlignmentHorizontal(object sender, point point)
 {
     _labels[0].TextAlignment = (HorizontalAlignment)((Button)sender).Tag;
     _labels[1].TextAlignment = (HorizontalAlignment)((Button)sender).Tag;
 }
 => GetVoxelIndexOfPoint(point, Mathf.RoundToInt);
Example #59
0
 static bool isValid(int[,] mat, int x, int y, point pt, bool[, ] visited)
 {
     if (x < 0 || y < 0 || x >= mat.GetLength(0) || y >= mat.GetLength(1) || visited[x, y] == true || (Math.Abs(mat[x, y] - mat[pt.x, pt.y]) != 1))
         return false;
     return true;
 }
Example #60
0
        private static void DecomposeCurve(int n, int p, double[] U,
                                           Point[] P, out int nb, out Point[][] Q)
        {
            int m = n + p + 1;
            int a = p;
            int b = p + 1;

            nb = 0;
            // If there are m+1 knots and a clamped knot vector
            // The number of knot intervals would ideally be (m-2p)
            // which is also the max number of Bezier curves that can be created
            point[,] qq = new point[m - 2 * p, p + 1];
            for (int i = 0; i <= p; i++)
            {
                qq[nb, i].X = P[i].X;
                qq[nb, i].Y = P[i].Y;
                qq[nb, i].Z = P[i].Z;
            }
            while (b < m)
            {
                int i = b;
                while (b < m && U[b + 1] == U[b])
                {
                    b++;
                }
                int mult = b - i + 1;
                if (mult < p)
                {
                    double[] alphas = new double[p];
                    var      numer  = U[b] - U[a];
                    for (int j = p; j > mult; j--)
                    {
                        alphas[j - mult - 1] = numer / (U[a + j] - U[a]);
                    }
                    int r = p - mult;
                    for (int j = 1; j <= r; j++)
                    {
                        var save = r - j;
                        int s    = mult + j;
                        for (int k = p; k >= s; k--)
                        {
                            var alpha = alphas[k - s];
                            qq[nb, k].X = alpha * qq[nb, k].X + (1 - alpha) * qq[nb, k - 1].X;
                            qq[nb, k].Y = alpha * qq[nb, k].Y + (1 - alpha) * qq[nb, k - 1].Y;
                            qq[nb, k].Z = alpha * qq[nb, k].Z + (1 - alpha) * qq[nb, k - 1].Z;
                        }
                        if (b < m)
                        {
                            qq[nb + 1, save] = qq[nb, p];
                        }
                    }
                }
                nb = nb + 1;
                if (b < m)
                {
                    for (int j = p - mult; j <= p; j++)
                    {
                        qq[nb, j].X = P[b - p + j].X;
                        qq[nb, j].Y = P[b - p + j].Y;
                        qq[nb, j].Z = P[b - p + j].Z;
                    }
                    a = b;
                    b = b + 1;
                }
            }
            int nrows = qq.GetLength(0);

            Q = new Point[nrows][];
            for (int i = 0; i < nrows; i++)
            {
                Q[i] = new Point[p + 1];
                for (int j = 0; j <= p; j++)
                {
                    Q[i][j] = Point.ByCoordinates(
                        qq[i, j].X, qq[i, j].Y, qq[i, j].Z);
                }
            }
        }