• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / PuzzleSolver / 4064748535

pending completion
4064748535

push

github

GitHub
Merge pull request #28 from samsmithnz/AddingMapAndPathFinding

806 of 854 branches covered (94.38%)

Branch coverage included in aggregate %.

342 of 342 new or added lines in 8 files covered. (100.0%)

1165 of 1194 relevant lines covered (97.57%)

1263151.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.1
/src/PuzzleSolver/Map/MapTile.cs
1
using System;
2
using System.Numerics;
3

4
namespace PuzzleSolver.Map
5
{
6
    public class MapTile
7
    {
8
        /// <summary>
9
        /// Creates a new instance of MapTile.
10
        /// </summary>
11
        /// <param name="x">The node's location along the X axis</param>
12
        /// <param name="y">The node's location along the Y axis</param>=
13
        /// <param name="isWalkable">True if the node can be traversed, false if the node is a wall</param>
14
        /// <param name="endLocation">The location of the destination node</param>
15
        public MapTile(int x, int y, string tileType, Vector2 endLocation)
50✔
16
        {
50✔
17
            this.Location = new Vector2(x, y);
50✔
18
            this.State = TileState.Untested;
50✔
19
            this.TileType = tileType;
50✔
20
            this.H = GetTraversalCost(this.Location, endLocation);
50✔
21
            this.G = 0;
50✔
22
        }
50✔
23

24
        /// <summary>
25
        /// The node's location in the grid
26
        /// </summary>
27
        public Vector2 Location { get; private set; }
247✔
28

29
        /// <summary>
30
        /// True when the node may be traversed, otherwise false
31
        /// </summary>
32
        /// //formerly IsWalkable
33
        public string TileType { get; set; }
84✔
34

35
        /// <summary>
36
        /// Cost from start to here
37
        /// </summary>
38
        public float G { get; private set; }
140✔
39

40
        /// <summary>
41
        /// Estimated cost from here to end
42
        /// </summary>
43
        public float H { get; private set; }
92✔
44

45
        /// <summary>
46
        /// Flags whether the node is open, closed or untested by the PathFinder
47
        /// </summary>
48
        public TileState State { get; set; }
140✔
49

50
        /// <summary>
51
        /// Estimated total cost (F = G + H)
52
        /// </summary>
53
        public float F
54
        {
55
            get { return this.G + this.H; }
126✔
56
        }
57

58
        public int TraversalCost
59
        {
60
            get { return Convert.ToInt32(Math.Ceiling(F)); }
×
61
        }
62

63
        private MapTile _parentTile;
64
        /// <summary>
65
        /// Gets or sets the parent node. The start node's parent is always null.
66
        /// </summary>
67
        public MapTile ParentTile
68
        {
69
            get
70
            {
20✔
71
                return this._parentTile;
20✔
72
            }
20✔
73
            set
74
            {
24✔
75
                // When setting the parent, also calculate the traversal cost from the start node to here (the 'G' value)
76
                this._parentTile = value;
24✔
77
                this.G = this._parentTile.G + GetTraversalCost(this.Location, this._parentTile.Location);
24✔
78
            }
24✔
79
        }
80

81
        public override string ToString()
82
        {
×
83
            return string.Format("{0}, {1}: {2}", this.Location.X, this.Location.Y, this.State);
×
84
        }
×
85

86
        /// <summary>
87
        /// Gets the distance between two points
88
        /// </summary>
89
        internal static float GetTraversalCost(Vector2 location, Vector2 otherLocation)
90
        {
74✔
91
            float deltaX = otherLocation.X - location.X;
74✔
92
            float deltaY = otherLocation.Y - location.Y;
74✔
93
            float result = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
74✔
94
            //System.Diagnostics.Debug.WriteLine("GetTraversalCost:" + result);
95
            return result;
74✔
96
        }
74✔
97
    }
98

99
    /// <summary>
100
    /// Represents the search state of a Node
101
    /// </summary>
102
    public enum TileState
103
    {
104
        /// <summary>
105
        /// The node has not yet been considered in any possible paths
106
        /// </summary>
107
        Untested,
108
        /// <summary>
109
        /// The node has been identified as a possible step in a path
110
        /// </summary>
111
        Open,
112
        /// <summary>
113
        /// The node has already been included in a path and will not be considered again
114
        /// </summary>
115
        Closed
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc