ToString() публичный Метод

public ToString ( ) : string
Результат string
Пример #1
0
 public override string ToString()
 {
     if (next == 0)
     {
         return("{ Empty Node }");
     }
     else if (next == -1)
     {
         return("{ Node " + key.ToString() + " }");
     }
     return("{ Node " + key.ToString() + ", Next: " + (next - 1) + " }");
 }
Пример #2
0
        /// <summary>Sets the NormalVector to reflect the current view of the IndexedFace on the screen. Automatically called from Refresh().</summary>
        internal void UpdateNormalVector()
        {
            //update the vector. don't just use the first three vertices - the polygon might have a convex edge there and the result will be wrong.
            mNormalVector = new Coord();
            for (int i = 0; i < Vertices.Count - 2; i++)
            {
                mNormalVector += (Vertices[i].ViewCoord - Vertices[i + 1].ViewCoord).CrossProduct(Vertices[i + 2].ViewCoord - Vertices[i + 1].ViewCoord);
            }
            int c = Vertices.Count;

            mNormalVector += (Vertices[c - 1].ViewCoord - Vertices[c - 2].ViewCoord).CrossProduct(Vertices[0].ViewCoord - Vertices[c - 2].ViewCoord);
            mNormalVector += (Vertices[c - 1].ViewCoord - Vertices[0].ViewCoord).CrossProduct(Vertices[1].ViewCoord - Vertices[0].ViewCoord);
            mNormalVector /= mNormalVector.Length;

            if (!mNormalVector.IsValid())
            {
                StringBuilder b = new StringBuilder();
                b.Append("Invalid Normal Vector: ").AppendLine(mNormalVector.ToString());
                b.AppendLine("Vertices: ");
                foreach (Vertex v in Vertices)
                {
                    b.AppendLine(v.ViewCoord.ToString());
                }
                System.Diagnostics.Debug.WriteLine(b.ToString());
                //throw new Exception(b.ToString());
            }
        }
Пример #3
0
    public void AddNode(Node node)
    {
        string key = Coord.ToString(node.Coord);

        Nodes.Add(key, node);
        AddIndex(key);
    }
Пример #4
0
 public string ToString(string format)
 {
     return(Coord.ToString(format) + " "
            + Value.ToString(format) + "\n"
            + "Vector Size: " +
            Math.Sqrt(Value.X * Value.X +
                      Value.Y * Value.Y).ToString(format) + "\n");
 }
Пример #5
0
 public void SetDirection(Coord direction, bool open)
 {
     if (!direction.IsDirection)
     {
         throw new ArgumentException(direction.ToString());
     }
     directionOpen[direction.ToDirectionIndex] = open;
 }
Пример #6
0
    public Graph(Node startNode)
    {
        StartNode = startNode;
        string key = Coord.ToString(StartNode.Coord);

        Nodes.Add(key, StartNode);
        AddIndex(key);
    }
Пример #7
0
    public void AddNode(Tile tile, Coord coord)
    {
        Node   newNode = new Node(tile, coord);
        string key     = Coord.ToString(newNode.Coord);

        Nodes.Add(key, newNode);
        AddIndex(key);
    }
Пример #8
0
    public Node FindNodeByCoord(Coord coord)
    {
        Node outNode;

        if (Nodes.TryGetValue(Coord.ToString(coord), out outNode))
        {
            return(outNode);
        }

        return(null);
    }
Пример #9
0
        public void Add(Coord pos)
        {
            BuildingCell created = Util.Instantiate(prototype).AddComponent <BuildingCell>();

            created.name = pos.ToString();
            created.Initialize();
            pieces[pos]                     = created;
            created.tile                    = created.GetComponent <BuildingTile>();
            created.transform.parent        = content.DisposableRoot;
            created.transform.localRotation = Quaternion.identity;
            created.transform.localPosition = pos.ToWorld();
        }
Пример #10
0
    static public void DrawLine(Coord startPos, Coord endPos, float width, Color color)
    {
        GameObject   line         = new GameObject("Point_" + startPos.ToString());
        LineRenderer lineRenderer = line.AddComponent <LineRenderer>();

        lineRenderer.material       = new Material(Shader.Find("Unlit/Color"));
        lineRenderer.material.color = color;
        lineRenderer.positionCount  = 2; //sets # of vertices (lines only need two)
        lineRenderer.SetPosition(0, new Vector3(startPos.X, startPos.Y, startPos.Z));
        lineRenderer.SetPosition(1, new Vector3(endPos.X, endPos.Y, endPos.Z));
        lineRenderer.startWidth = width;
        lineRenderer.endWidth   = width;
    }
Пример #11
0
    static public void DrawPoint(Coord position, float width, Color color)
    {
        GameObject   line         = new GameObject("Point_" + position.ToString());
        LineRenderer lineRenderer = line.AddComponent <LineRenderer>();

        lineRenderer.material       = new Material(Shader.Find("Unlit/Color"));
        lineRenderer.material.color = color;
        lineRenderer.positionCount  = 2; //sets # of vertices (lines only need two)
        lineRenderer.SetPosition(0, new Vector3(position.X - width / 3.0f, position.Y - width / 3.0f, position.Z));
        lineRenderer.SetPosition(1, new Vector3(position.X + width / 3.0f, position.Y + width / 3.0f, position.Z));
        lineRenderer.startWidth = width;
        lineRenderer.endWidth   = width;
    }
Пример #12
0
        private void MouseHover(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Point p = e.GetPosition((Grid)sender);

            try
            {
                Coord c = BoardPointToCoordinate(p);
                Coordinates.Content = c.ToString();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(p);
            }
        }
Пример #13
0
        public void RefreshDebug()
        {
            if (!debugVisibleObject)
            {
                return;
            }
            Vector3 p = astar.maze.GetGroundPosition(coord), u = Vector3.up * .125f;

            debugVisibleObject.transform.position = p + u;
            bool   isVisible = visMap[coord];
            string text      = (_f < 0 && _g < 0)
                                ? coord.ToString()
                                : $"{coord}\nf:{_f}\ng:{_g}\n{_edge}";

            UiText.SetText(debugVisibleObject, text);
            UiText.SetColor(debugVisibleObject, isVisible ? Color.white : Color.black);
        }
Пример #14
0
    public static void Main()
    {
        magic = int.Parse(Console.ReadLine());
        LinkedList <Coord> bfs = new LinkedList <Coord>();

        bfs.AddLast(new Coord(1, 1, 0));
        HashSet <String> set = new HashSet <String>();

        int[] dx = new int[] { 1, -1, 0, 0 };
        int[] dy = new int[] { 0, 0, -1, 1 };
        int   part1 = -1, part2 = -1;

        while (bfs.Count > 0 && (part1 == -1 || part2 == -1))
        {
            Coord c = bfs.First.Value;
            bfs.RemoveFirst();
            if (c.x == 31 && c.y == 39 && part1 == -1)
            {
                part1 = c.d;
            }
            if (c.d == 51 && part2 == -1)
            {
                part2 = set.Count;
            }
            String s = c.ToString();
            if (set.Contains(s))
            {
                continue;
            }
            set.Add(s);
            for (int i = 0; i < 4; i++)
            {
                int x = c.x + dx[i];
                int y = c.y + dy[i];
                if (Free(x, y))
                {
                    bfs.AddLast(new Coord(x, y, c.d + 1));
                }
            }
        }
        Console.WriteLine(part1);
        Console.WriteLine(part2);
    }
Пример #15
0
    public void CheckEntityPositions()
    {
        // TODO if debug

        // Check all BoardEntities are on board
        //
        BoardEntity[] foundEntities = GameObject.FindObjectsOfType <BoardEntity>();
        Utils.Assert(foundEntities.Length == allEntities.Count);

        // Check each entity is on the right space
        //
        foreach (BoardEntity e in allEntities)
        {
            Coord p = e.pos;
            Utils.Assert(e == GetTile(p).entity, "Mitmatch entity position at " + p.ToString());
        }

        Utils.DebugText("Board has: " + allEntities.Count + " entities");
    }
Пример #16
0
    void LogQMatrix(int epoch)
    {
        string s = "Epoch " + epoch + " - Q Matrix: \n +---------------------------------+ \n";

        s += string.Format("{0, 8}", "");

        foreach (KeyValuePair <Coord, int> pair in actions)
        {
            s += string.Format("{0, 15}", pair.Key);
        }
        s += '\n';

        for (int r = 0; r < qMatrix.GetLength(0); r++)
        {
            s += string.Format("{0, -8}", Coord.ToString(states.GetNodeByIndex(r).Coord) + ")");
            for (int c = 0; c < qMatrix.GetLength(1); c++)
            {
                s += string.Format("{0, 15}", qMatrix[r, c].ToString("F8"));
            }
            s += '\n';
        }

        Debug.Log(s);
    }
Пример #17
0
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            if (mIsClickEditArea)
            {
                mIsClickEditArea = false;
            }
            else
            {
                mCurLeftClicked = MapView.Current.Layout.ScreenPos2Coord(MapView.Current.MapCamera, Input.mousePosition.xy());
                coord.text      = mCurLeftClicked.ToString();
                List <int> sprs = mapProxy.GetSprLists(mCurLeftClicked.GetSubmapCoord());
                for (int i = 0; i < sprs.Count; i++)
                {
                    sprLists[i].value = sprs[i];
                }
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            Coord newdst = MapView.Current.Layout.ScreenPos2Coord(MapView.Current.MapCamera, Input.mousePosition.xy());
            mDst = newdst;
            OnMRBAction_Common();
        }
        else if (Input.GetMouseButton(1))
        {
            Coord newdst = MapView.Current.Layout.ScreenPos2Coord(MapView.Current.MapCamera, Input.mousePosition.xy());
            if (newdst != mDst)
            {
                mDst = newdst;
                OnMRBAction_Common();
            }
        }
    }
Пример #18
0
 public override string ToString()
 {
     return("Site " + _siteIndex.ToString() + ": " + Coord.ToString());
 }
Пример #19
0
 public override string ToString()
 {
     return($"Move to {_targetPosition.ToString()}");
 }
Пример #20
0
 //*********************************************************
 public string ToWKT()
 {
     return("POINT" + Coord.ToString());
 }
Пример #21
0
    public int GetNodeIndex(Node node)
    {
        string key = Coord.ToString(node.Coord);

        return(indices[key]);
    }
 public void ReturnsValidValue()
 {
     for (int x = -10; x < Constants.MAP_WIDTH + 10; x++)
     {
         for (int y = -10; y < Constants.MAP_HEIGHT + 10; y++)
         {
             var coord     = new Coord(x, y);
             var fastCoord = FastCoord.Create(coord);
             FastCoord.IsInsideMap(fastCoord).Should().Be(coord.IsInsideMap(), coord.ToString());
         }
     }
 }
Пример #23
0
 public override string ToString()
 {
     return(Coord.ToString() + " "
            + Value.ToString() + "\n");
 }
Пример #24
0
 //*********************************************************
 public override string ToString()
 {
     return(Coord.ToString());
 }
Пример #25
0
 public override string ToString()
 {
     return($"Dig ore at {OrePosition.ToString()}");
 }
Пример #26
0
    void Update()
    {
        if (visionParticle != null)
        {
            if (characterMover.JumpButtonTimed > 0 && !visionParticle.isPlaying)
            {
                visionParticle.Play();
            }
            else if (characterMover.JumpButtonTimed == 0 && visionParticle.isPlaying)
            {
                visionParticle.Stop();
            }
        }
        Coord mapSize = maze.Map.GetSize();

        if (mapAstar == null)
        {
            mapAstar = new Map2dAStar(() => canJump, maze, discovery.vision, _t, prefab_debug_astar);
        }
        mapAstar.UpdateMapSize();
        Vector3 p    = _t.position;
        Coord   here = maze.GetCoord(p);

        if (follower.waypoints.Count > 0)
        {
            Coord there = maze.GetCoord(follower.waypoints[0].positon);
            if (here == there)
            {
                follower.NotifyWayPointReached();
            }
        }
        List <Coord> moves = mapAstar.Moves(here, canJump);

        if (textOutput != null)
        {
            UiText.SetText(textOutput, here.ToString() + ":" + (p - maze.transform.position) + " " + moves.JoinToString(", "));
        }
        if (useVisionParticle && visionParticle)
        {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                mapSize.ForEach(co => {
                    if (discovery.vision[co])
                    {
                        Vector3 po = maze.GetPosition(co);
                        po.y       = _t.position.y;
                        visionParticle.transform.position = po;
                        visionParticle.Emit(1);
                    }
                });
                timer = .5f;
            }
        }
        switch (aiBehavior)
        {
        case AiBehavior.RandomLocalEdges:
            if (!characterMover.IsAutoMoving())
            {
                Coord c = moves[Random.Next(moves.Count)];
                characterMover.SetAutoMovePosition(MoveablePosition(c, p));
            }
            break;

        case AiBehavior.RandomInVision:
            if (mapAstar.goal == here)
            {
                if (mapAstar.RandomVisibleNode(out Coord there, here))
                {
                    //Debug.Log("startover #");
                    //Debug.Log("goal " + there+ " "+astar.IsFinished());
                }
                else
                {
                    mapAstar.RandomNeighborNode(out there, here);
                }
                mapAstar.Start(here, there);
            }
            else
            {
                // iterate astar algorithm
                if (!mapAstar.IsFinished())
                {
                    mapAstar.Update();
                }
                else if (mapAstar.BestPath == null)
                {
                    //Debug.Log("f" + astar.IsFinished() + " " + astar.BestPath);
                    mapAstar.Start(here, here);
                    //Debug.Log("startover could not find path");
                }
                if (mapAstar.BestPath != null)
                {
                    if (mapAstar.BestPath != currentBestPath)
                    {
                        currentBestPath = mapAstar.BestPath;
                        List <Coord> nodes = new List <Coord>();
                        Coord        c     = mapAstar.start;
                        nodes.Add(c);
                        for (int i = currentBestPath.Count - 1; i >= 0; --i)
                        {
                            c = mapAstar.NextNode(c, currentBestPath[i]);
                            nodes.Add(c);
                        }
                        //Debug.Log(currentBestPath.JoinToString(", "));
                        indexOnBestPath = nodes.IndexOf(here);
                        if (indexOnBestPath < 0)
                        {
                            mapAstar.Start(here, mapAstar.goal);
                            //Debug.Log("startover new better path");
                        }
                        Vector3 pos = p;
                        follower.ClearWaypoints();
                        for (int i = 0; i < currentBestPath.Count; ++i)
                        {
                            pos = MoveablePosition(nodes[i + 1], pos);
                            //pos.y += follower.CharacterHeight;
                            //Show.Log(i + " " + nodes.Count + " " + currentBestPath.Count + " " + (currentBestPath.Count - i - 1));
                            MazeAStar.EdgeMoveType moveType = MazeAStar.GetEdgeMoveType(currentBestPath[currentBestPath.Count - i - 1]);
                            switch (moveType)
                            {
                            case MazeAStar.EdgeMoveType.Walk: follower.AddWaypoint(pos, false); break;

                            case MazeAStar.EdgeMoveType.Fall: follower.AddWaypoint(pos, false, 0, true); break;

                            case MazeAStar.EdgeMoveType.Jump: follower.AddWaypoint(pos, false, characterMover.jump.fullPressDuration); break;
                            }
                        }
                        follower.SetCurrentTarget(pos);
                        follower.UpdateLine();
                        follower.doPrediction = true;
                    }
                    else
                    {
                        if (!characterMover.IsAutoMoving() && follower.waypoints.Count == 0)
                        {
                            mapAstar.Start(here, here);
                            //Debug.Log("startover new level?");
                        }
                    }
                }
            }
            break;
        }
    }
Пример #27
0
        void DrawPanel()
        {
            var panelSize = new Vector2(PANEL_WIDTH, position.height);
            var padding   = PADDING * Vector2.one;
            var groupRect = new Rect(padding, panelSize - 2 * padding);

            GUI.Box(new Rect(Vector2.zero, panelSize), GUIContent.none);
            GUILayout.BeginArea(groupRect);
            GUILayout.BeginVertical();
            EditorGUI.BeginChangeCheck();
            properties.TagTable = (TagDrawTable)EditorGUILayout.ObjectField("Tag Table", properties.TagTable, typeof(TagDrawTable), allowSceneObjects: false);
            if (EditorGUI.EndChangeCheck())
            {
                CreateMazeTexture();
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedLength);
            EditorGUILayout.PropertyField(serializedWidth);
            if (EditorGUI.EndChangeCheck())
            {
                // The min is a functional requirement, the max is to avoid texture sizes for use cases
                // this tool is not suited to support.
                serializedLength.intValue = Mathf.Clamp(serializedLength.intValue, 1, 100);
                serializedWidth.intValue  = Mathf.Clamp(serializedWidth.intValue, 1, 100);
                CreateMazeTexture();
            }
            scale = EditorGUILayout.IntField("Scale", scale);

            // Note that we defer adding or removing items to after the loop terminates, to
            // avoid changing the list while we iterate over it.
            EditorGUILayout.LabelField("Tags", EditorStyles.boldLabel);
            Coord?targetCell = null;
            KeyValuePair <string, string>?deleteKvp = null;
            KeyValuePair <string, string>?newKvp    = null;

            foreach (var tag in cellTags)
            {
                Coord cell     = tag.Key;
                var   metaData = tag.Value;
                foreach (var pair in metaData)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUIUtility.labelWidth = 50; // reduce label size
                    EditorGUILayout.PrefixLabel(cell.ToString());
                    EditorGUIUtility.labelWidth = 0;  // restore label size
                    string key   = EditorGUILayout.DelayedTextField(pair.Key);
                    string value = EditorGUILayout.DelayedTextField(pair.Value);
                    if (pair.Key != key || pair.Value != value)  // This pair changed
                    {
                        targetCell = cell;
                        deleteKvp  = pair;
                        newKvp     = new KeyValuePair <string, string>(key, value);
                    }
                    if (GUILayout.Button("X"))
                    {
                        targetCell = cell;
                        deleteKvp  = pair;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.Separator();  // Create space before drawing the next tag's data.
            }
            if (targetCell.HasValue)
            {
                cellTags[targetCell.Value].Remove(deleteKvp.Value);
                if (newKvp.HasValue)
                {
                    cellTags[targetCell.Value].Add(newKvp.Value);
                }
                DrawTags(targetCell.Value);
            }
            if (GUILayout.Button("Save"))
            {
                SaveMaze();
            }
            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
Пример #28
0
 public override string ToString()
 {
     return($"Dig radar at {TargetPosition.ToString()}");
 }
Пример #29
0
        private void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (_activeComponent == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Right && !_mouseLocation.IsEmpty)
            {
                pictureBox.Cursor = Cursors.Hand;
                var dX = e.X - _mouseLocation.X;
                var dY = e.Y - _mouseLocation.Y;
                if (dX != 0 || dY != 0)
                {
                    _renderer.Pan(dX, dY);
                    RequestRedraw(true);
                }
            }
            else
            {
                pictureBox.Cursor = Cursors.Default;
            }

            var location = _renderer.WorldFromScreen(new PointF(e.Location.X, e.Location.Y));

            statusLocation.Text = $"{location.ToString(_displayUnit, _snapGridSize)}    Grid: {_snapGridSize.ToString(_displayUnit)}";

            _mouseLocation = e.Location;
            pictureBox.Focus();
        }