Repository: juhgiyo/EpPathFinding.cs
Branch: master
Commit: e0d3d4bf7353
Files: 38
Total size: 182.9 KB
Directory structure:
gitextract_a16lqtoo/
├── .gitignore
├── EpPathFinding.cs/
│ ├── EpPathFinding.cs/
│ │ ├── EpPathFinding.cs.csproj
│ │ ├── PathFinder/
│ │ │ ├── AStarFinder.cs
│ │ │ ├── DiagonalMovement.cs
│ │ │ ├── Grid/
│ │ │ │ ├── BaseGrid.cs
│ │ │ │ ├── DynamicGrid.cs
│ │ │ │ ├── DynamicGridWPool.cs
│ │ │ │ ├── PartialGridWPool.cs
│ │ │ │ └── StaticGrid.cs
│ │ │ ├── GridPos.cs
│ │ │ ├── GridRect.cs
│ │ │ ├── Heuristic.cs
│ │ │ ├── JumpPointFinder.cs
│ │ │ ├── NodePool.cs
│ │ │ ├── ParamBase.cs
│ │ │ └── Util.cs
│ │ ├── Properties/
│ │ │ └── AssemblyInfo.cs
│ │ └── packages.config
│ ├── EpPathFinding.cs.nupkg
│ └── EpPathFinding.cs.sln
├── EpPathFindingDemo/
│ ├── EpPathFindingDemo.csproj
│ ├── EpPathFindingDemo.sln
│ ├── General/
│ │ └── SingletonHolder.cs
│ ├── GridBox.cs
│ ├── GridLine.cs
│ ├── LICENSE
│ ├── Program.cs
│ ├── Properties/
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── ResultBox.cs
│ ├── SearchGridForm.Designer.cs
│ ├── SearchGridForm.cs
│ └── SearchGridForm.resx
├── README.md
└── _config.yml
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.pdb
Debug/
Release/
*.suo
packages/
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/EpPathFinding.cs.csproj
================================================
Debug
AnyCPU
8.0.30703
2.0
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}
Library
Properties
EpPathFinding.cs
EpPathFinding.cs
v4.0
512
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\Release\
TRACE
prompt
4
..\packages\C5.2.4.5947.17249\lib\net40\C5.dll
True
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/AStarFinder.cs
================================================
#if (UNITY_EDITOR || UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_STANDALONE || UNITY_WII || UNITY_IOS || UNITY_IPHONE || UNITY_ANDROID || UNITY_PS4 || UNITY_SAMSUNGTV || UNITY_XBOXONE || UNITY_TIZEN || UNITY_TVOS || UNITY_WP_8_1 || UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0 || UNITY_WINRT || UNITY_WINRT_8_1 || UNITY_WINRT_10_0 || UNITY_WEBGL || UNITY_ADS || UNITY_ANALYTICS || UNITY_ASSERTIONS)
#define UNITY
#else
using System.Threading.Tasks;
#endif
using C5;
using System;
using System.Collections;
using System.Collections.Generic;
namespace EpPathFinding.cs
{
public class AStarParam : ParamBase
{
public delegate float HeuristicDelegate(int iDx, int iDy);
public float Weight;
public AStarParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, float iweight, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid,iStartPos,iEndPos, iDiagonalMovement,iMode)
{
Weight = iweight;
}
public AStarParam(BaseGrid iGrid, float iweight, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid, iDiagonalMovement, iMode)
{
Weight = iweight;
}
internal override void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
{
}
}
public static class AStarFinder
{
/*
private class NodeComparer : IComparer
{
public int Compare(Node x, Node y)
{
var result = (x.heuristicStartToEndLen - y.heuristicStartToEndLen);
if (result < 0) return -1;
else
if (result > 0) return 1;
else
{
return 0;
}
}
}
*/
public static List FindPath(AStarParam iParam)
{
object lo = new object();
//var openList = new IntervalHeap(new NodeComparer());
var openList = new IntervalHeap();
var startNode = iParam.StartNode;
var endNode = iParam.EndNode;
var heuristic = iParam.HeuristicFunc;
var grid = iParam.SearchGrid;
var diagonalMovement = iParam.DiagonalMovement;
var weight = iParam.Weight;
startNode.startToCurNodeLen = 0;
startNode.heuristicStartToEndLen = 0;
openList.Add(startNode);
startNode.isOpened = true;
while (openList.Count != 0)
{
var node = openList.DeleteMin();
node.isClosed = true;
if (node == endNode)
{
return Node.Backtrace(endNode);
}
var neighbors = grid.GetNeighbors(node, diagonalMovement);
#if (UNITY)
foreach(var neighbor in neighbors)
#else
Parallel.ForEach(neighbors, neighbor =>
#endif
{
#if (UNITY)
if (neighbor.isClosed) continue;
#else
if (neighbor.isClosed) return;
#endif
var x = neighbor.x;
var y = neighbor.y;
float ng = node.startToCurNodeLen + (float)((x - node.x == 0 || y - node.y == 0) ? 1 : Math.Sqrt(2));
if (!neighbor.isOpened || ng < neighbor.startToCurNodeLen)
{
neighbor.startToCurNodeLen = ng;
if (neighbor.heuristicCurNodeToEndLen == null) neighbor.heuristicCurNodeToEndLen = weight * heuristic(Math.Abs(x - endNode.x), Math.Abs(y - endNode.y));
neighbor.heuristicStartToEndLen = neighbor.startToCurNodeLen + neighbor.heuristicCurNodeToEndLen.Value;
neighbor.parent = node;
if (!neighbor.isOpened)
{
lock (lo)
{
openList.Add(neighbor);
}
neighbor.isOpened = true;
}
else
{
}
}
}
#if (!UNITY)
);
#endif
}
return new List();
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/DiagonalMovement.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EpPathFinding.cs
{
public enum DiagonalMovement
{
Always,
Never,
IfAtLeastOneWalkable,
OnlyWhenNoObstacles
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Grid/BaseGrid.cs
================================================
/*!
@file BaseGrid.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief BaseGrid Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the BaseGrid Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class Node : IComparable
{
public int x;
public int y;
public bool walkable;
public float heuristicStartToEndLen; // which passes current node
public float startToCurNodeLen;
public float? heuristicCurNodeToEndLen;
public bool isOpened;
public bool isClosed;
public Object parent;
public Node(int iX, int iY, bool? iWalkable = null)
{
this.x = iX;
this.y = iY;
this.walkable = (iWalkable.HasValue ? iWalkable.Value : false);
this.heuristicStartToEndLen = 0;
this.startToCurNodeLen = 0;
// this must be initialized as null to verify that its value never initialized
// 0 is not good candidate!!
this.heuristicCurNodeToEndLen = null;
this.isOpened = false;
this.isClosed = false;
this.parent = null;
}
public Node(Node b)
{
this.x = b.x;
this.y = b.y;
this.walkable = b.walkable;
this.heuristicStartToEndLen = b.heuristicStartToEndLen;
this.startToCurNodeLen = b.startToCurNodeLen;
this.heuristicCurNodeToEndLen = b.heuristicCurNodeToEndLen;
this.isOpened = b.isOpened;
this.isClosed = b.isClosed;
this.parent = b.parent;
}
public void Reset(bool? iWalkable = null)
{
if (iWalkable.HasValue)
walkable = iWalkable.Value;
this.heuristicStartToEndLen = 0;
this.startToCurNodeLen = 0;
// this must be initialized as null to verify that its value never initialized
// 0 is not good candidate!!
this.heuristicCurNodeToEndLen = null ;
this.isOpened = false;
this.isClosed = false;
this.parent = null;
}
public int CompareTo(Node iObj)
{
float result = this.heuristicStartToEndLen - iObj.heuristicStartToEndLen;
if (result > 0.0f)
return 1;
else if (result == 0.0f)
return 0;
return -1;
}
public static List Backtrace(Node iNode)
{
List path = new List();
path.Add(new GridPos(iNode.x, iNode.y));
while (iNode.parent != null)
{
iNode = (Node)iNode.parent;
path.Add(new GridPos(iNode.x, iNode.y));
}
path.Reverse();
return path;
}
public override int GetHashCode()
{
return x ^ y;
}
public override bool Equals(System.Object obj)
{
// If parameter is null return false.
if (obj == null)
{
return false;
}
// If parameter cannot be cast to Point return false.
Node p = obj as Node;
if ((System.Object)p == null)
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
public bool Equals(Node p)
{
// If parameter is null return false:
if ((object)p == null)
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
public static bool operator ==(Node a, Node b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}
// Return true if the fields match:
return a.x == b.x && a.y == b.y;
}
public static bool operator !=(Node a, Node b)
{
return !(a == b);
}
}
public abstract class BaseGrid
{
public BaseGrid()
{
m_gridRect = new GridRect();
}
public BaseGrid(BaseGrid b)
{
m_gridRect = new GridRect(b.m_gridRect);
width = b.width;
height = b.height;
}
protected GridRect m_gridRect;
public GridRect gridRect
{
get { return m_gridRect; }
}
public abstract int width { get; protected set; }
public abstract int height { get; protected set; }
public abstract Node GetNodeAt(int iX, int iY);
public abstract bool IsWalkableAt(int iX, int iY);
public abstract bool SetWalkableAt(int iX, int iY, bool iWalkable);
public abstract Node GetNodeAt(GridPos iPos);
public abstract bool IsWalkableAt(GridPos iPos);
public abstract bool SetWalkableAt(GridPos iPos, bool iWalkable);
public List GetNeighbors(Node iNode, DiagonalMovement diagonalMovement)
{
int tX = iNode.x;
int tY = iNode.y;
List neighbors = new List();
bool tS0 = false, tD0 = false,
tS1 = false, tD1 = false,
tS2 = false, tD2 = false,
tS3 = false, tD3 = false;
GridPos pos = new GridPos();
if (this.IsWalkableAt(pos.Set(tX, tY - 1)))
{
neighbors.Add(GetNodeAt(pos));
tS0 = true;
}
if (this.IsWalkableAt(pos.Set(tX + 1, tY)))
{
neighbors.Add(GetNodeAt(pos));
tS1 = true;
}
if (this.IsWalkableAt(pos.Set(tX, tY + 1)))
{
neighbors.Add(GetNodeAt(pos));
tS2 = true;
}
if (this.IsWalkableAt(pos.Set(tX - 1, tY)))
{
neighbors.Add(GetNodeAt(pos));
tS3 = true;
}
switch (diagonalMovement)
{
case DiagonalMovement.Always:
tD0 = true;
tD1 = true;
tD2 = true;
tD3 = true;
break;
case DiagonalMovement.Never:
break;
case DiagonalMovement.IfAtLeastOneWalkable:
tD0 = tS3 || tS0;
tD1 = tS0 || tS1;
tD2 = tS1 || tS2;
tD3 = tS2 || tS3;
break;
case DiagonalMovement.OnlyWhenNoObstacles:
tD0 = tS3 && tS0;
tD1 = tS0 && tS1;
tD2 = tS1 && tS2;
tD3 = tS2 && tS3;
break;
default:
break;
}
if (tD0 && this.IsWalkableAt(pos.Set(tX - 1, tY - 1)))
{
neighbors.Add(GetNodeAt(pos));
}
if (tD1 && this.IsWalkableAt(pos.Set(tX + 1, tY - 1)))
{
neighbors.Add(GetNodeAt(pos));
}
if (tD2 && this.IsWalkableAt(pos.Set(tX + 1, tY + 1)))
{
neighbors.Add(GetNodeAt(pos));
}
if (tD3 && this.IsWalkableAt(pos.Set(tX - 1, tY + 1)))
{
neighbors.Add(GetNodeAt(pos));
}
return neighbors;
}
public abstract void Reset();
public abstract BaseGrid Clone();
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Grid/DynamicGrid.cs
================================================
/*!
@file DynamicGrid.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief DynamicGrid Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the DynamicGrid Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class DynamicGrid : BaseGrid
{
protected Dictionary m_nodes;
private bool m_notSet;
public override int width
{
get
{
if (m_notSet)
setBoundingBox();
return m_gridRect.maxX - m_gridRect.minX + 1;
}
protected set
{
}
}
public override int height
{
get
{
if (m_notSet)
setBoundingBox();
return m_gridRect.maxY - m_gridRect.minY + 1;
}
protected set
{
}
}
public DynamicGrid(List iWalkableGridList = null)
: base()
{
m_gridRect = new GridRect();
m_gridRect.minX = 0;
m_gridRect.minY = 0;
m_gridRect.maxX = 0;
m_gridRect.maxY = 0;
m_notSet = true;
buildNodes(iWalkableGridList);
}
public DynamicGrid(DynamicGrid b)
: base(b)
{
m_notSet = b.m_notSet;
m_nodes = new Dictionary(b.m_nodes);
}
protected void buildNodes(List iWalkableGridList)
{
m_nodes = new Dictionary();
if (iWalkableGridList == null)
return;
foreach (GridPos gridPos in iWalkableGridList)
{
SetWalkableAt(gridPos.x, gridPos.y, true);
}
}
public override Node GetNodeAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return GetNodeAt(pos);
}
public override bool IsWalkableAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return IsWalkableAt(pos);
}
private void setBoundingBox()
{
m_notSet = true;
foreach (KeyValuePair pair in m_nodes)
{
if (pair.Key.x < m_gridRect.minX || m_notSet)
m_gridRect.minX = pair.Key.x;
if (pair.Key.x > m_gridRect.maxX || m_notSet)
m_gridRect.maxX = pair.Key.x;
if (pair.Key.y < m_gridRect.minY || m_notSet)
m_gridRect.minY = pair.Key.y;
if (pair.Key.y > m_gridRect.maxY || m_notSet)
m_gridRect.maxY = pair.Key.y;
m_notSet = false;
}
m_notSet = false;
}
public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
{
GridPos pos = new GridPos(iX, iY);
if (iWalkable)
{
if (m_nodes.ContainsKey(pos))
{
// this.m_nodes[pos].walkable = iWalkable;
return true;
}
else
{
if (iX < m_gridRect.minX || m_notSet)
m_gridRect.minX = iX;
if (iX > m_gridRect.maxX || m_notSet)
m_gridRect.maxX = iX;
if (iY < m_gridRect.minY || m_notSet)
m_gridRect.minY = iY;
if (iY > m_gridRect.maxY || m_notSet)
m_gridRect.maxY = iY;
m_nodes.Add(new GridPos(pos.x, pos.y), new Node(pos.x, pos.y, iWalkable));
//m_notSet = false;
}
}
else
{
if (m_nodes.ContainsKey(pos))
{
m_nodes.Remove(pos);
if (iX == m_gridRect.minX || iX == m_gridRect.maxX || iY == m_gridRect.minY || iY == m_gridRect.maxY)
m_notSet = true;
}
}
return true;
}
public override Node GetNodeAt(GridPos iPos)
{
if (m_nodes.ContainsKey(iPos))
{
return m_nodes[iPos];
}
return null;
}
public override bool IsWalkableAt(GridPos iPos)
{
return m_nodes.ContainsKey(iPos);
}
public override bool SetWalkableAt(GridPos iPos, bool iWalkable)
{
return SetWalkableAt(iPos.x, iPos.y, iWalkable);
}
public override void Reset()
{
Reset(null);
}
public void Reset(List iWalkableGridList)
{
foreach (KeyValuePair keyValue in m_nodes)
{
keyValue.Value.Reset();
}
if (iWalkableGridList == null)
return;
foreach (KeyValuePair keyValue in m_nodes)
{
if (iWalkableGridList.Contains(keyValue.Key))
SetWalkableAt(keyValue.Key, true);
else
SetWalkableAt(keyValue.Key, false);
}
}
public override BaseGrid Clone()
{
DynamicGrid tNewGrid = new DynamicGrid();
foreach (KeyValuePair keyValue in m_nodes)
{
tNewGrid.SetWalkableAt(keyValue.Key.x, keyValue.Key.y, true);
}
return tNewGrid;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Grid/DynamicGridWPool.cs
================================================
/*!
@file DynamicGridWPool.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief DynamicGrid with Pool Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the DynamicGrid with Pool Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class DynamicGridWPool : BaseGrid
{
private bool m_notSet;
private NodePool m_nodePool;
public override int width
{
get
{
if (m_notSet)
setBoundingBox();
return m_gridRect.maxX - m_gridRect.minX + 1;
}
protected set
{
}
}
public override int height
{
get
{
if (m_notSet)
setBoundingBox();
return m_gridRect.maxY - m_gridRect.minY + 1;
}
protected set
{
}
}
public DynamicGridWPool(NodePool iNodePool)
: base()
{
m_gridRect = new GridRect();
m_gridRect.minX = 0;
m_gridRect.minY = 0;
m_gridRect.maxX = 0;
m_gridRect.maxY = 0;
m_notSet = true;
m_nodePool = iNodePool;
}
public DynamicGridWPool(DynamicGridWPool b)
: base(b)
{
m_notSet = b.m_notSet;
m_nodePool = b.m_nodePool;
}
public override Node GetNodeAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return GetNodeAt(pos);
}
public override bool IsWalkableAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return IsWalkableAt(pos);
}
private void setBoundingBox()
{
m_notSet = true;
foreach (KeyValuePair pair in m_nodePool.Nodes)
{
if (pair.Key.x < m_gridRect.minX || m_notSet)
m_gridRect.minX = pair.Key.x;
if (pair.Key.x > m_gridRect.maxX || m_notSet)
m_gridRect.maxX = pair.Key.x;
if (pair.Key.y < m_gridRect.minY || m_notSet)
m_gridRect.minY = pair.Key.y;
if (pair.Key.y > m_gridRect.maxY || m_notSet)
m_gridRect.maxY = pair.Key.y;
m_notSet = false;
}
m_notSet = false;
}
public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
{
GridPos pos = new GridPos(iX, iY);
m_nodePool.SetNode(pos, iWalkable);
if (iWalkable)
{
if (iX < m_gridRect.minX || m_notSet)
m_gridRect.minX = iX;
if (iX > m_gridRect.maxX || m_notSet)
m_gridRect.maxX = iX;
if (iY < m_gridRect.minY || m_notSet)
m_gridRect.minY = iY;
if (iY > m_gridRect.maxY || m_notSet)
m_gridRect.maxY = iY;
//m_notSet = false;
}
else
{
if (iX == m_gridRect.minX || iX == m_gridRect.maxX || iY == m_gridRect.minY || iY == m_gridRect.maxY)
m_notSet = true;
}
return true;
}
public override Node GetNodeAt(GridPos iPos)
{
return m_nodePool.GetNode(iPos);
}
public override bool IsWalkableAt(GridPos iPos)
{
return m_nodePool.Nodes.ContainsKey(iPos);
}
public override bool SetWalkableAt(GridPos iPos, bool iWalkable)
{
return SetWalkableAt(iPos.x, iPos.y, iWalkable);
}
public override void Reset()
{
foreach (KeyValuePair keyValue in m_nodePool.Nodes)
{
keyValue.Value.Reset();
}
}
public override BaseGrid Clone()
{
DynamicGridWPool tNewGrid = new DynamicGridWPool(m_nodePool);
return tNewGrid;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Grid/PartialGridWPool.cs
================================================
/*!
@file PartialGridWPool.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief PartialGrid with Pool Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the PartialGrid with Pool Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class PartialGridWPool : BaseGrid
{
private NodePool m_nodePool;
public override int width
{
get
{
return m_gridRect.maxX - m_gridRect.minX + 1;
}
protected set
{
}
}
public override int height
{
get
{
return m_gridRect.maxY - m_gridRect.minY + 1;
}
protected set
{
}
}
public PartialGridWPool(NodePool iNodePool, GridRect iGridRect = null)
: base()
{
if (iGridRect == null)
m_gridRect = new GridRect();
else
m_gridRect = iGridRect;
m_nodePool = iNodePool;
}
public PartialGridWPool(PartialGridWPool b)
: base(b)
{
m_nodePool = b.m_nodePool;
}
public void SetGridRect(GridRect iGridRect)
{
m_gridRect = iGridRect;
}
public bool IsInside(int iX, int iY)
{
if (iX < m_gridRect.minX || iX > m_gridRect.maxX || iY < m_gridRect.minY || iY > m_gridRect.maxY)
return false;
return true;
}
public override Node GetNodeAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return GetNodeAt(pos);
}
public override bool IsWalkableAt(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return IsWalkableAt(pos);
}
public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
{
if (!IsInside(iX,iY))
return false;
GridPos pos = new GridPos(iX, iY);
m_nodePool.SetNode(pos, iWalkable);
return true;
}
public bool IsInside(GridPos iPos)
{
return IsInside(iPos.x, iPos.y);
}
public override Node GetNodeAt(GridPos iPos)
{
if (!IsInside(iPos))
return null;
return m_nodePool.GetNode(iPos);
}
public override bool IsWalkableAt(GridPos iPos)
{
if (!IsInside(iPos))
return false;
return m_nodePool.Nodes.ContainsKey(iPos);
}
public override bool SetWalkableAt(GridPos iPos, bool iWalkable)
{
return SetWalkableAt(iPos.x, iPos.y, iWalkable);
}
public override void Reset()
{
int rectCount=(m_gridRect.maxX-m_gridRect.minX) * (m_gridRect.maxY-m_gridRect.minY);
if (m_nodePool.Nodes.Count > rectCount)
{
GridPos travPos = new GridPos(0, 0);
for (int xTrav = m_gridRect.minX; xTrav <= m_gridRect.maxX; xTrav++)
{
travPos.x = xTrav;
for (int yTrav = m_gridRect.minY; yTrav <= m_gridRect.maxY; yTrav++)
{
travPos.y = yTrav;
Node curNode=m_nodePool.GetNode(travPos);
if (curNode!=null)
curNode.Reset();
}
}
}
else
{
foreach (KeyValuePair keyValue in m_nodePool.Nodes)
{
keyValue.Value.Reset();
}
}
}
public override BaseGrid Clone()
{
PartialGridWPool tNewGrid = new PartialGridWPool(m_nodePool,m_gridRect);
return tNewGrid;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Grid/StaticGrid.cs
================================================
/*!
@file StaticGrid.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief StaticGrid Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the StaticGrid Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class StaticGrid : BaseGrid
{
public override int width { get; protected set; }
public override int height { get; protected set; }
private Node[][] m_nodes;
public StaticGrid(int iWidth, int iHeight, bool[][] iMatrix = null):base()
{
width = iWidth;
height = iHeight;
m_gridRect.minX = 0;
m_gridRect.minY = 0;
m_gridRect.maxX = iWidth-1;
m_gridRect.maxY = iHeight - 1;
this.m_nodes = buildNodes(iWidth, iHeight, iMatrix);
}
public StaticGrid(StaticGrid b)
: base(b)
{
bool[][] tMatrix = new bool[b.width][];
for (int widthTrav = 0; widthTrav < b.width; widthTrav++)
{
tMatrix[widthTrav] = new bool[b.height];
for (int heightTrav = 0; heightTrav < b.height; heightTrav++)
{
if(b.IsWalkableAt(widthTrav,heightTrav))
tMatrix[widthTrav][heightTrav] = true;
else
tMatrix[widthTrav][heightTrav] = false;
}
}
this.m_nodes = buildNodes(b.width, b.height, tMatrix);
}
private Node[][] buildNodes(int iWidth, int iHeight, bool[][] iMatrix)
{
Node[][] tNodes = new Node[iWidth][];
for (int widthTrav = 0; widthTrav < iWidth; widthTrav++)
{
tNodes[widthTrav] = new Node[iHeight];
for (int heightTrav = 0; heightTrav < iHeight; heightTrav++)
{
tNodes[widthTrav][heightTrav] = new Node(widthTrav, heightTrav, null);
}
}
if (iMatrix == null)
{
return tNodes;
}
if (iMatrix.Length != iWidth || iMatrix[0].Length != iHeight)
{
throw new System.Exception("Matrix size does not fit");
}
for (int widthTrav = 0; widthTrav < iWidth; widthTrav++)
{
for (int heightTrav = 0; heightTrav < iHeight; heightTrav++)
{
if (iMatrix[widthTrav][heightTrav])
{
tNodes[widthTrav][heightTrav].walkable = true;
}
else
{
tNodes[widthTrav][heightTrav].walkable = false;
}
}
}
return tNodes;
}
public override Node GetNodeAt(int iX, int iY)
{
return this.m_nodes[iX][iY];
}
public override bool IsWalkableAt(int iX, int iY)
{
return isInside(iX, iY) && this.m_nodes[iX][iY].walkable;
}
protected bool isInside(int iX, int iY)
{
return (iX >= 0 && iX < width) && (iY >= 0 && iY < height);
}
public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
{
this.m_nodes[iX][iY].walkable = iWalkable;
return true;
}
protected bool isInside(GridPos iPos)
{
return isInside(iPos.x, iPos.y);
}
public override Node GetNodeAt(GridPos iPos)
{
return GetNodeAt(iPos.x, iPos.y);
}
public override bool IsWalkableAt(GridPos iPos)
{
return IsWalkableAt(iPos.x, iPos.y);
}
public override bool SetWalkableAt(GridPos iPos, bool iWalkable)
{
return SetWalkableAt(iPos.x, iPos.y, iWalkable);
}
public override void Reset()
{
Reset(null);
}
public void Reset(bool[][] iMatrix)
{
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
m_nodes[widthTrav][heightTrav].Reset();
}
}
if (iMatrix == null)
{
return;
}
if (iMatrix.Length != width || iMatrix[0].Length != height)
{
throw new System.Exception("Matrix size does not fit");
}
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (iMatrix[widthTrav][heightTrav])
{
m_nodes[widthTrav][heightTrav].walkable = true;
}
else
{
m_nodes[widthTrav][heightTrav].walkable = false;
}
}
}
}
public override BaseGrid Clone()
{
int tWidth = width;
int tHeight = height;
Node[][] tNodes = this.m_nodes;
StaticGrid tNewGrid = new StaticGrid(tWidth, tHeight, null);
Node[][] tNewNodes = new Node[tWidth][];
for (int widthTrav = 0; widthTrav < tWidth; widthTrav++)
{
tNewNodes[widthTrav] = new Node[tHeight];
for (int heightTrav = 0; heightTrav < tHeight; heightTrav++)
{
tNewNodes[widthTrav][heightTrav] = new Node(widthTrav, heightTrav, tNodes[widthTrav][heightTrav].walkable);
}
}
tNewGrid.m_nodes = tNewNodes;
return tNewGrid;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/GridPos.cs
================================================
/*!
@file GridPos.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief Grid Position Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the Grid Position Struct.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class GridPos : IEquatable
{
public int x;
public int y;
public GridPos()
{
x = 0;
y = 0;
}
public GridPos(int iX, int iY)
{
this.x = iX;
this.y = iY;
}
public GridPos(GridPos b)
{
x = b.x;
y = b.y;
}
public override int GetHashCode()
{
return x ^ y;
}
public override bool Equals(System.Object obj)
{
// Unlikely to compare incorrect type so removed for performance
// if (!(obj.GetType() == typeof(GridPos)))
// return false;
GridPos p = (GridPos)obj;
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
public bool Equals(GridPos p)
{
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
public static bool operator ==(GridPos a, GridPos b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
if (ReferenceEquals(null, a))
{
return false;
}
if (ReferenceEquals(null, b))
{
return false;
}
// Return true if the fields match:
return a.x == b.x && a.y == b.y;
}
public static bool operator !=(GridPos a, GridPos b)
{
return !(a == b);
}
public GridPos Set(int iX, int iY)
{
this.x = iX;
this.y = iY;
return this;
}
public override string ToString()
{
return string.Format("({0},{1})", x, y);
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/GridRect.cs
================================================
/*!
@file GridRect.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief GridRect Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the GridRect Struct.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class GridRect
{
public int minX;
public int minY;
public int maxX;
public int maxY;
public GridRect()
{
minX = 0;
minY = 0;
maxX = 0;
maxY = 0;
}
public GridRect(int iMinX, int iMinY, int iMaxX, int iMaxY)
{
minX = iMinX;
minY = iMinY;
maxX = iMaxX;
maxY = iMaxY;
}
public GridRect(GridRect b)
{
minX = b.minX;
minY = b.minY;
maxX = b.maxX;
maxY = b.maxY;
}
public override int GetHashCode()
{
return minX ^ minY ^ maxX ^ maxY;
}
public override bool Equals(System.Object obj)
{
// Unlikely to compare incorrect type so removed for performance
//if (!(obj.GetType() == typeof(GridRect)))
// return false;
GridRect p = (GridRect)obj;
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (minX == p.minX) && (minY == p.minY) && (maxX == p.maxX) && (maxY == p.maxY);
}
public bool Equals(GridRect p)
{
if (ReferenceEquals(null, p))
{
return false;
}
// Return true if the fields match:
return (minX == p.minX) && (minY == p.minY) && (maxX == p.maxX) && (maxY == p.maxY);
}
public static bool operator ==(GridRect a, GridRect b)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(a, b))
{
return true;
}
if (ReferenceEquals(null, a))
{
return false;
}
if (ReferenceEquals(null, b))
{
return false;
}
// Return true if the fields match:
return (a.minX == b.minX) && (a.minY == b.minY) && (a.maxX == b.maxX) && (a.maxY == b.maxY);
}
public static bool operator !=(GridRect a, GridRect b)
{
return !(a == b);
}
public GridRect Set(int iMinX, int iMinY, int iMaxX, int iMaxY)
{
this.minX = iMinX;
this.minY = iMinY;
this.maxX = iMaxX;
this.maxY = iMaxY;
return this;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Heuristic.cs
================================================
/*!
@file Heuristic.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief Heuristic Function Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the Heuristic Function Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public enum HeuristicMode
{
MANHATTAN,
EUCLIDEAN,
CHEBYSHEV,
};
public class Heuristic
{
public static float Manhattan(int iDx, int iDy)
{
return (float)iDx + iDy;
}
public static float Euclidean(int iDx, int iDy)
{
float tFdx = (float)iDx;
float tFdy = (float)iDy;
return (float)Math.Sqrt((double)(tFdx * tFdx + tFdy * tFdy));
}
public static float Chebyshev(int iDx, int iDy)
{
return (float)Math.Max(iDx, iDy);
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/JumpPointFinder.cs
================================================
/*!
@file JumpPointFinder.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief Jump Point Search Algorithm Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the Jump Point Search Algorithm Class.
*/
using C5;
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public enum IterationType
{
LOOP,
RECURSIVE,
};
public enum EndNodeUnWalkableTreatment
{
ALLOW,
DISALLOW
};
public class JumpPointParam : ParamBase
{
[System.Obsolete("This constructor is deprecated, please use the Constructor with EndNodeUnWalkableTreatment and DiagonalMovement instead.")]
public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
:base(iGrid, iStartPos, iEndPos, Util.GetDiagonalMovement(iCrossCorner, iCrossAdjacentPoint), iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
[System.Obsolete("This constructor is deprecated, please use the Constructor with EndNodeUnWalkableTreatment and DiagonalMovement instead.")]
public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, bool iCrossCorner = true, bool iCrossAdjacentPoint = true, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid, Util.GetDiagonalMovement(iCrossCorner, iCrossAdjacentPoint), iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
[System.Obsolete("This constructor is deprecated, please use the Constructor with EndNodeUnWalkableTreatment and DiagonalMovement instead.")]
public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, bool iAllowEndNodeUnWalkable = true, DiagonalMovement iDiagonalMovement= DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid,iStartPos,iEndPos, iDiagonalMovement, iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
[System.Obsolete("This constructor is deprecated, please use the Constructor with EndNodeUnWalkableTreatment and DiagonalMovement instead.")]
public JumpPointParam(BaseGrid iGrid, bool iAllowEndNodeUnWalkable = true, DiagonalMovement iDiagonalMovement= DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid, iDiagonalMovement, iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
public JumpPointParam(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, EndNodeUnWalkableTreatment iAllowEndNodeUnWalkable = EndNodeUnWalkableTreatment.ALLOW, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid, iStartPos, iEndPos, iDiagonalMovement, iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
public JumpPointParam(BaseGrid iGrid, EndNodeUnWalkableTreatment iAllowEndNodeUnWalkable = EndNodeUnWalkableTreatment.ALLOW, DiagonalMovement iDiagonalMovement = DiagonalMovement.Always, HeuristicMode iMode = HeuristicMode.EUCLIDEAN)
: base(iGrid, iDiagonalMovement, iMode)
{
CurEndNodeUnWalkableTreatment = iAllowEndNodeUnWalkable;
openList = new IntervalHeap();
CurIterationType = IterationType.LOOP;
}
public JumpPointParam(JumpPointParam b):base(b)
{
m_heuristic = b.m_heuristic;
CurEndNodeUnWalkableTreatment = b.CurEndNodeUnWalkableTreatment;
openList = new IntervalHeap();
openList.AddAll(b.openList);
CurIterationType = b.CurIterationType;
}
internal override void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
{
openList = new IntervalHeap();
//openList.Clear();
}
[System.Obsolete("This property is deprecated, please use the CurEndNodeUnWalkableTreatment instead.")]
public bool AllowEndNodeUnWalkable
{
get
{
return CurEndNodeUnWalkableTreatment == EndNodeUnWalkableTreatment.ALLOW;
}
set
{
CurEndNodeUnWalkableTreatment = value ? EndNodeUnWalkableTreatment.ALLOW : EndNodeUnWalkableTreatment.DISALLOW;
}
}
[System.Obsolete("This property is deprecated, please use the CurIterationType instead.")]
public bool UseRecursive
{
get
{
return CurIterationType==IterationType.RECURSIVE;
}
set
{
CurIterationType = value ? IterationType.RECURSIVE : IterationType.LOOP;
}
}
public EndNodeUnWalkableTreatment CurEndNodeUnWalkableTreatment
{
get;
set;
}
public IterationType CurIterationType
{
get;
set;
}
//public List openList;
public IntervalHeap openList;
}
public class JumpPointFinder
{
public static List GetFullPath(List routeFound)
{
if (routeFound == null)
return null;
List consecutiveGridList = new List();
if (routeFound.Count > 1)
consecutiveGridList.Add(new GridPos(routeFound[0]));
for (int routeTrav = 0; routeTrav < routeFound.Count - 1; routeTrav++)
{
GridPos fromGrid = new GridPos(routeFound[routeTrav]);
GridPos toGrid = routeFound[routeTrav + 1];
int dX = toGrid.x - fromGrid.x;
int dY = toGrid.y - fromGrid.y;
int nDX = 0;
int nDY = 0;
if (dX != 0)
{
nDX = (dX / Math.Abs(dX));
}
if (dY != 0)
{
nDY = (dY / Math.Abs(dY));
}
while (fromGrid != toGrid)
{
fromGrid.x += nDX;
fromGrid.y += nDY;
consecutiveGridList.Add(new GridPos(fromGrid));
}
}
return consecutiveGridList;
}
public static List FindPath(JumpPointParam iParam)
{
IntervalHeap tOpenList = iParam.openList;
Node tStartNode = iParam.StartNode;
Node tEndNode = iParam.EndNode;
Node tNode;
bool revertEndNodeWalkable = false;
// set the `g` and `f` value of the start node to be 0
tStartNode.startToCurNodeLen = 0;
tStartNode.heuristicStartToEndLen = 0;
// push the start node into the open list
tOpenList.Add(tStartNode);
tStartNode.isOpened = true;
if (iParam.CurEndNodeUnWalkableTreatment == EndNodeUnWalkableTreatment.ALLOW && !iParam.SearchGrid.IsWalkableAt(tEndNode.x, tEndNode.y))
{
iParam.SearchGrid.SetWalkableAt(tEndNode.x, tEndNode.y, true);
revertEndNodeWalkable = true;
}
// while the open list is not empty
while (tOpenList.Count > 0)
{
// pop the position of node which has the minimum `f` value.
tNode = tOpenList.DeleteMin();
tNode.isClosed = true;
if (tNode.Equals(tEndNode))
{
if (revertEndNodeWalkable)
{
iParam.SearchGrid.SetWalkableAt(tEndNode.x, tEndNode.y, false);
}
return Node.Backtrace(tNode); // rebuilding path
}
identifySuccessors(iParam, tNode);
}
if (revertEndNodeWalkable)
{
iParam.SearchGrid.SetWalkableAt(tEndNode.x, tEndNode.y, false);
}
// fail to find the path
return new List();
}
private static void identifySuccessors(JumpPointParam iParam, Node iNode)
{
HeuristicDelegate tHeuristic = iParam.HeuristicFunc;
IntervalHeap tOpenList = iParam.openList;
int tEndX = iParam.EndNode.x;
int tEndY = iParam.EndNode.y;
GridPos tNeighbor;
GridPos tJumpPoint;
Node tJumpNode;
List tNeighbors = findNeighbors(iParam, iNode);
for (int i = 0; i < tNeighbors.Count; i++)
{
tNeighbor = tNeighbors[i];
if (iParam.CurIterationType==IterationType.RECURSIVE)
tJumpPoint = jump(iParam, tNeighbor.x, tNeighbor.y, iNode.x, iNode.y);
else
tJumpPoint = jumpLoop(iParam, tNeighbor.x, tNeighbor.y, iNode.x, iNode.y);
if (tJumpPoint != null)
{
tJumpNode = iParam.SearchGrid.GetNodeAt(tJumpPoint.x, tJumpPoint.y);
if (tJumpNode == null)
{
if (iParam.EndNode.x == tJumpPoint.x && iParam.EndNode.y == tJumpPoint.y)
tJumpNode = iParam.SearchGrid.GetNodeAt(tJumpPoint);
}
if (tJumpNode.isClosed)
{
continue;
}
// include distance, as parent may not be immediately adjacent:
float tCurNodeToJumpNodeLen = tHeuristic(Math.Abs(tJumpPoint.x - iNode.x), Math.Abs(tJumpPoint.y - iNode.y));
float tStartToJumpNodeLen = iNode.startToCurNodeLen + tCurNodeToJumpNodeLen; // next `startToCurNodeLen` value
if (!tJumpNode.isOpened || tStartToJumpNodeLen < tJumpNode.startToCurNodeLen)
{
tJumpNode.startToCurNodeLen = tStartToJumpNodeLen;
tJumpNode.heuristicCurNodeToEndLen = (tJumpNode.heuristicCurNodeToEndLen == null ? tHeuristic(Math.Abs(tJumpPoint.x - tEndX), Math.Abs(tJumpPoint.y - tEndY)) : tJumpNode.heuristicCurNodeToEndLen);
tJumpNode.heuristicStartToEndLen = tJumpNode.startToCurNodeLen + tJumpNode.heuristicCurNodeToEndLen.Value;
tJumpNode.parent = iNode;
if (!tJumpNode.isOpened)
{
tOpenList.Add(tJumpNode);
tJumpNode.isOpened = true;
}
}
}
}
}
private class JumpSnapshot
{
public int iX;
public int iY;
public int iPx;
public int iPy;
public int tDx;
public int tDy;
public int stage;
public JumpSnapshot()
{
iX = 0;
iY = 0;
iPx = 0;
iPy = 0;
tDx = 0;
tDy = 0;
stage = 0;
}
}
private static GridPos jumpLoop(JumpPointParam iParam, int iX, int iY, int iPx, int iPy)
{
GridPos retVal = null;
Stack stack = new Stack();
JumpSnapshot currentSnapshot = new JumpSnapshot();
JumpSnapshot newSnapshot = null;
currentSnapshot.iX = iX;
currentSnapshot.iY = iY;
currentSnapshot.iPx = iPx;
currentSnapshot.iPy = iPy;
currentSnapshot.stage = 0;
stack.Push(currentSnapshot);
while (stack.Count != 0)
{
currentSnapshot = stack.Pop();
switch (currentSnapshot.stage)
{
case 0:
if (!iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY))
{
retVal = null;
continue;
}
else if (iParam.SearchGrid.GetNodeAt(currentSnapshot.iX, currentSnapshot.iY).Equals(iParam.EndNode))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
currentSnapshot.tDx = currentSnapshot.iX - currentSnapshot.iPx;
currentSnapshot.tDy = currentSnapshot.iY - currentSnapshot.iPy;
if (iParam.DiagonalMovement == DiagonalMovement.Always || iParam.DiagonalMovement == DiagonalMovement.IfAtLeastOneWalkable)
{
// check for forced neighbors
// along the diagonal
if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0)
{
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY - currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - currentSnapshot.tDy)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
// horizontally/vertically
else
{
if (currentSnapshot.tDx != 0)
{
// moving along x
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + 1)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY - 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - 1)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
else
{
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
}
// when moving diagonally, must check for vertical/horizontal jump points
if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0)
{
currentSnapshot.stage = 1;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
// moving diagonally, must make sure one of the vertical/horizontal
// neighbors is open to allow the path
// moving diagonally, must make sure one of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) || iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
else if (iParam.DiagonalMovement==DiagonalMovement.Always)
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
}
else if (iParam.DiagonalMovement == DiagonalMovement.OnlyWhenNoObstacles)
{
// check for forced neighbors
// along the diagonal
if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0)
{
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY + currentSnapshot.tDy) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
// horizontally/vertically
else
{
if (currentSnapshot.tDx != 0)
{
// moving along x
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY + 1)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY - 1) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - currentSnapshot.tDx, currentSnapshot.iY - 1)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
else
{
if ((iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + 1, currentSnapshot.iY - currentSnapshot.tDy)) ||
(iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY) && !iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX - 1, currentSnapshot.iY - currentSnapshot.tDy)))
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
}
}
// when moving diagonally, must check for vertical/horizontal jump points
if (currentSnapshot.tDx != 0 && currentSnapshot.tDy != 0)
{
currentSnapshot.stage = 3;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
// moving diagonally, must make sure both of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
}
else // if(iParam.DiagonalMovement == DiagonalMovement.Never)
{
if (currentSnapshot.tDx != 0)
{
// moving along x
if (!iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY))
{
retVal= new GridPos(iX, iY);
continue;
}
}
else
{
if (!iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
retVal = new GridPos(iX, iY);
continue;
}
}
// must check for perpendicular jump points
if (currentSnapshot.tDx != 0)
{
currentSnapshot.stage = 5;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX;
newSnapshot.iY = currentSnapshot.iY + 1;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
else // tDy != 0
{
currentSnapshot.stage = 6;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + 1;
newSnapshot.iY = currentSnapshot.iY;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
}
retVal = null;
break;
case 1:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
currentSnapshot.stage = 2;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
break;
case 2:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
// moving diagonally, must make sure one of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) || iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
else if (iParam.DiagonalMovement==DiagonalMovement.Always)
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
retVal = null;
break;
case 3:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
currentSnapshot.stage = 4;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
break;
case 4:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
// moving diagonally, must make sure both of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
retVal = null;
break;
case 5:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
currentSnapshot.stage = 7;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX;
newSnapshot.iY = currentSnapshot.iY - 1;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
break;
case 6:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
currentSnapshot.stage = 7;
stack.Push(currentSnapshot);
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX - 1;
newSnapshot.iY = currentSnapshot.iY;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
break;
case 7:
if (retVal != null)
{
retVal = new GridPos(currentSnapshot.iX, currentSnapshot.iY);
continue;
}
// keep going
if (iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX + currentSnapshot.tDx, currentSnapshot.iY) && iParam.SearchGrid.IsWalkableAt(currentSnapshot.iX, currentSnapshot.iY + currentSnapshot.tDy))
{
newSnapshot = new JumpSnapshot();
newSnapshot.iX = currentSnapshot.iX + currentSnapshot.tDx;
newSnapshot.iY = currentSnapshot.iY + currentSnapshot.tDy;
newSnapshot.iPx = currentSnapshot.iX;
newSnapshot.iPy = currentSnapshot.iY;
newSnapshot.stage = 0;
stack.Push(newSnapshot);
continue;
}
retVal = null;
break;
}
}
return retVal;
}
private static GridPos jump(JumpPointParam iParam, int iX, int iY, int iPx, int iPy)
{
if (!iParam.SearchGrid.IsWalkableAt(iX, iY))
{
return null;
}
else if (iParam.SearchGrid.GetNodeAt(iX, iY).Equals(iParam.EndNode))
{
return new GridPos(iX, iY);
}
int tDx = iX - iPx;
int tDy = iY - iPy;
if (iParam.DiagonalMovement == DiagonalMovement.Always || iParam.DiagonalMovement == DiagonalMovement.IfAtLeastOneWalkable)
{
// check for forced neighbors
// along the diagonal
if (tDx != 0 && tDy != 0)
{
if ((iParam.SearchGrid.IsWalkableAt(iX - tDx, iY + tDy) && !iParam.SearchGrid.IsWalkableAt(iX - tDx, iY)) ||
(iParam.SearchGrid.IsWalkableAt(iX + tDx, iY - tDy) && !iParam.SearchGrid.IsWalkableAt(iX, iY - tDy)))
{
return new GridPos(iX, iY);
}
}
// horizontally/vertically
else
{
if (tDx != 0)
{
// moving along x
if ((iParam.SearchGrid.IsWalkableAt(iX + tDx, iY + 1) && !iParam.SearchGrid.IsWalkableAt(iX, iY + 1)) ||
(iParam.SearchGrid.IsWalkableAt(iX + tDx, iY - 1) && !iParam.SearchGrid.IsWalkableAt(iX, iY - 1)))
{
return new GridPos(iX, iY);
}
}
else
{
if ((iParam.SearchGrid.IsWalkableAt(iX + 1, iY + tDy) && !iParam.SearchGrid.IsWalkableAt(iX + 1, iY)) ||
(iParam.SearchGrid.IsWalkableAt(iX - 1, iY + tDy) && !iParam.SearchGrid.IsWalkableAt(iX - 1, iY)))
{
return new GridPos(iX, iY);
}
}
}
// when moving diagonally, must check for vertical/horizontal jump points
if (tDx != 0 && tDy != 0)
{
if (jump(iParam, iX + tDx, iY, iX, iY) != null)
{
return new GridPos(iX, iY);
}
if (jump(iParam, iX, iY + tDy, iX, iY) != null)
{
return new GridPos(iX, iY);
}
}
// moving diagonally, must make sure one of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(iX + tDx, iY) || iParam.SearchGrid.IsWalkableAt(iX, iY + tDy))
{
return jump(iParam, iX + tDx, iY + tDy, iX, iY);
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
return jump(iParam, iX + tDx, iY + tDy, iX, iY);
}
else
{
return null;
}
}
else if (iParam.DiagonalMovement == DiagonalMovement.OnlyWhenNoObstacles)
{
// check for forced neighbors
// along the diagonal
if (tDx != 0 && tDy != 0)
{
if (iParam.SearchGrid.IsWalkableAt(iX + tDx, iY + tDy) && ( !iParam.SearchGrid.IsWalkableAt(iX, iY + tDy) || !iParam.SearchGrid.IsWalkableAt(iX + tDx, iY)))
{
return new GridPos(iX, iY);
}
}
// horizontally/vertically
else
{
if (tDx != 0)
{
// moving along x
if ((iParam.SearchGrid.IsWalkableAt(iX, iY + 1) && !iParam.SearchGrid.IsWalkableAt(iX - tDx, iY + 1)) ||
(iParam.SearchGrid.IsWalkableAt(iX, iY - 1) && !iParam.SearchGrid.IsWalkableAt(iX - tDx, iY - 1)))
{
return new GridPos(iX, iY);
}
}
else
{
if ((iParam.SearchGrid.IsWalkableAt(iX + 1, iY) && !iParam.SearchGrid.IsWalkableAt(iX + 1, iY - tDy)) ||
(iParam.SearchGrid.IsWalkableAt(iX - 1, iY) && !iParam.SearchGrid.IsWalkableAt(iX - 1, iY - tDy)))
{
return new GridPos(iX, iY);
}
}
}
// when moving diagonally, must check for vertical/horizontal jump points
if (tDx != 0 && tDy != 0)
{
if (jump(iParam, iX + tDx, iY, iX, iY) != null) return new GridPos(iX, iY);
if (jump(iParam, iX, iY + tDy, iX, iY) != null) return new GridPos(iX, iY);
}
// moving diagonally, must make sure both of the vertical/horizontal
// neighbors is open to allow the path
if (iParam.SearchGrid.IsWalkableAt(iX + tDx, iY) && iParam.SearchGrid.IsWalkableAt(iX, iY + tDy))
{
return jump(iParam, iX + tDx, iY + tDy, iX, iY);
}
else
{
return null;
}
}
else // if(iParam.DiagonalMovement == DiagonalMovement.Never)
{
if (tDx != 0)
{
// moving along x
if (!iParam.SearchGrid.IsWalkableAt(iX + tDx, iY))
{
return new GridPos(iX, iY);
}
}
else
{
if (!iParam.SearchGrid.IsWalkableAt(iX, iY + tDy))
{
return new GridPos(iX, iY);
}
}
// must check for perpendicular jump points
if (tDx != 0 )
{
if (jump(iParam, iX, iY + 1, iX, iY) != null) return new GridPos(iX, iY);
if (jump(iParam, iX, iY - 1, iX, iY) != null) return new GridPos(iX, iY);
}
else // tDy != 0
{
if (jump(iParam, iX + 1, iY, iX, iY) != null) return new GridPos(iX, iY);
if (jump(iParam, iX - 1, iY, iX, iY) != null) return new GridPos(iX, iY);
}
// keep going
if (iParam.SearchGrid.IsWalkableAt(iX + tDx, iY) && iParam.SearchGrid.IsWalkableAt(iX, iY + tDy))
{
return jump(iParam, iX + tDx, iY + tDy, iX, iY);
}
else
{
return null;
}
}
}
private static List findNeighbors(JumpPointParam iParam, Node iNode)
{
Node tParent = (Node)iNode.parent;
//var diagonalMovement = Util.GetDiagonalMovement(iParam.CrossCorner, iParam.CrossAdjacentPoint);
int tX = iNode.x;
int tY = iNode.y;
int tPx, tPy, tDx, tDy;
List tNeighbors = new List();
List tNeighborNodes;
Node tNeighborNode;
// directed pruning: can ignore most neighbors, unless forced.
if (tParent != null)
{
tPx = tParent.x;
tPy = tParent.y;
// get the normalized direction of travel
tDx = (tX - tPx) / Math.Max(Math.Abs(tX - tPx), 1);
tDy = (tY - tPy) / Math.Max(Math.Abs(tY - tPy), 1);
if (iParam.DiagonalMovement == DiagonalMovement.Always || iParam.DiagonalMovement == DiagonalMovement.IfAtLeastOneWalkable)
{
// search diagonally
if (tDx != 0 && tDy != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy))
{
tNeighbors.Add(new GridPos(tX, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY + tDy))
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy) || iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY + tDy));
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
tNeighbors.Add(new GridPos(tX + tDx, tY + tDy));
}
}
if (iParam.SearchGrid.IsWalkableAt(tX - tDx, tY + tDy) && !iParam.SearchGrid.IsWalkableAt(tX - tDx, tY))
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy))
{
tNeighbors.Add(new GridPos(tX - tDx, tY + tDy));
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
tNeighbors.Add(new GridPos(tX - tDx, tY + tDy));
}
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY - tDy) && !iParam.SearchGrid.IsWalkableAt(tX, tY - tDy))
{
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY - tDy));
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
tNeighbors.Add(new GridPos(tX + tDx, tY - tDy));
}
}
}
// search horizontally/vertically
else
{
if (tDx != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY));
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY + 1) && !iParam.SearchGrid.IsWalkableAt(tX, tY + 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY + 1));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY - 1) && !iParam.SearchGrid.IsWalkableAt(tX, tY - 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY - 1));
}
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY + 1) && !iParam.SearchGrid.IsWalkableAt(tX, tY + 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY + 1));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY - 1) && !iParam.SearchGrid.IsWalkableAt(tX, tY - 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY - 1));
}
}
}
else
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy))
{
tNeighbors.Add(new GridPos(tX, tY + tDy));
if (iParam.SearchGrid.IsWalkableAt(tX + 1, tY + tDy) && !iParam.SearchGrid.IsWalkableAt(tX + 1, tY))
{
tNeighbors.Add(new GridPos(tX + 1, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX - 1, tY + tDy) && !iParam.SearchGrid.IsWalkableAt(tX - 1, tY))
{
tNeighbors.Add(new GridPos(tX - 1, tY + tDy));
}
}
else if (iParam.DiagonalMovement == DiagonalMovement.Always)
{
if (iParam.SearchGrid.IsWalkableAt(tX + 1, tY + tDy) && !iParam.SearchGrid.IsWalkableAt(tX + 1, tY))
{
tNeighbors.Add(new GridPos(tX + 1, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX - 1, tY + tDy) && !iParam.SearchGrid.IsWalkableAt(tX - 1, tY))
{
tNeighbors.Add(new GridPos(tX - 1, tY + tDy));
}
}
}
}
}
else if (iParam.DiagonalMovement == DiagonalMovement.OnlyWhenNoObstacles)
{
// search diagonally
if (tDx != 0 && tDy != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy))
{
tNeighbors.Add(new GridPos(tX, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY + tDy))
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy) && iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
tNeighbors.Add(new GridPos(tX + tDx, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX - tDx, tY + tDy))
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy) && iParam.SearchGrid.IsWalkableAt(tX - tDx, tY))
tNeighbors.Add(new GridPos(tX - tDx, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY - tDy))
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY - tDy) && iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
tNeighbors.Add(new GridPos(tX + tDx, tY - tDy));
}
}
// search horizontally/vertically
else
{
if (tDx != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY));
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY + 1) && iParam.SearchGrid.IsWalkableAt(tX, tY + 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY + 1));
}
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY - 1) && iParam.SearchGrid.IsWalkableAt(tX, tY - 1))
{
tNeighbors.Add(new GridPos(tX + tDx, tY - 1));
}
}
if (iParam.SearchGrid.IsWalkableAt(tX, tY + 1))
tNeighbors.Add(new GridPos(tX, tY + 1));
if (iParam.SearchGrid.IsWalkableAt(tX, tY - 1))
tNeighbors.Add(new GridPos(tX, tY - 1));
}
else
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY + tDy))
{
tNeighbors.Add(new GridPos(tX, tY + tDy));
if (iParam.SearchGrid.IsWalkableAt(tX + 1, tY + tDy) && iParam.SearchGrid.IsWalkableAt(tX + 1, tY))
{
tNeighbors.Add(new GridPos(tX + 1, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX - 1, tY + tDy) && iParam.SearchGrid.IsWalkableAt(tX - 1, tY))
{
tNeighbors.Add(new GridPos(tX - 1, tY + tDy));
}
}
if (iParam.SearchGrid.IsWalkableAt(tX + 1, tY))
tNeighbors.Add(new GridPos(tX + 1, tY));
if (iParam.SearchGrid.IsWalkableAt(tX - 1, tY))
tNeighbors.Add(new GridPos(tX - 1, tY));
}
}
}
else // if(iParam.DiagonalMovement == DiagonalMovement.Never)
{
if (tDx != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX + tDx, tY))
{
tNeighbors.Add(new GridPos(tX + tDx, tY));
}
if (iParam.SearchGrid.IsWalkableAt(tX, tY + 1))
{
tNeighbors.Add(new GridPos(tX, tY +1));
}
if (iParam.SearchGrid.IsWalkableAt(tX, tY - 1))
{
tNeighbors.Add(new GridPos(tX, tY - 1));
}
}
else // if (tDy != 0)
{
if (iParam.SearchGrid.IsWalkableAt(tX, tY +tDy))
{
tNeighbors.Add(new GridPos(tX, tY + tDy));
}
if (iParam.SearchGrid.IsWalkableAt(tX + 1, tY))
{
tNeighbors.Add(new GridPos(tX + 1, tY));
}
if (iParam.SearchGrid.IsWalkableAt(tX - 1, tY))
{
tNeighbors.Add(new GridPos(tX - 1, tY));
}
}
}
}
// return all neighbors
else
{
tNeighborNodes = iParam.SearchGrid.GetNeighbors(iNode, iParam.DiagonalMovement);
for (int i = 0; i < tNeighborNodes.Count; i++)
{
tNeighborNode = tNeighborNodes[i];
tNeighbors.Add(new GridPos(tNeighborNode.x, tNeighborNode.y));
}
}
return tNeighbors;
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/NodePool.cs
================================================
/*!
@file NodePool.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief NodePool Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the NodePool Class.
*/
using System;
using System.Collections.Generic;
using System.Collections;
namespace EpPathFinding.cs
{
public class NodePool
{
protected Dictionary m_nodes;
public NodePool()
{
m_nodes = new Dictionary();
}
public Dictionary Nodes
{
get { return m_nodes; }
}
public Node GetNode(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
return GetNode(pos);
}
public Node GetNode(GridPos iPos)
{
Node retVal = null;
m_nodes.TryGetValue(iPos, out retVal);
return retVal;
}
public Node SetNode(int iX, int iY, bool? iWalkable = null)
{
GridPos pos = new GridPos(iX, iY);
return SetNode(pos, iWalkable);
}
public Node SetNode(GridPos iPos, bool? iWalkable = null)
{
if (iWalkable.HasValue)
{
if (iWalkable.Value == true)
{
Node retVal = null;
if (m_nodes.TryGetValue(iPos, out retVal))
{
return retVal;
}
Node newNode = new Node(iPos.x, iPos.y, iWalkable);
m_nodes.Add(iPos, newNode);
return newNode;
}
else
{
removeNode(iPos);
}
}
else
{
Node newNode = new Node(iPos.x, iPos.y, true);
m_nodes.Add(iPos, newNode);
return newNode;
}
return null;
}
protected void removeNode(int iX, int iY)
{
GridPos pos = new GridPos(iX, iY);
removeNode(pos);
}
protected void removeNode(GridPos iPos)
{
if (m_nodes.ContainsKey(iPos))
m_nodes.Remove(iPos);
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/ParamBase.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EpPathFinding.cs
{
public delegate float HeuristicDelegate(int iDx, int iDy);
public abstract class ParamBase
{
public ParamBase(BaseGrid iGrid, GridPos iStartPos, GridPos iEndPos, DiagonalMovement iDiagonalMovement, HeuristicMode iMode) : this(iGrid, iDiagonalMovement, iMode)
{
m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
m_endNode = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
if (m_startNode == null)
m_startNode = new Node(iStartPos.x, iStartPos.y, true);
if (m_endNode == null)
m_endNode = new Node(iEndPos.x, iEndPos.y, true);
}
public ParamBase(BaseGrid iGrid, DiagonalMovement iDiagonalMovement, HeuristicMode iMode)
{
SetHeuristic(iMode);
m_searchGrid = iGrid;
DiagonalMovement = iDiagonalMovement;
m_startNode = null;
m_endNode = null;
}
public ParamBase(ParamBase param)
{
m_searchGrid = param.m_searchGrid;
DiagonalMovement = param.DiagonalMovement;
m_startNode = param.m_startNode;
m_endNode = param.m_endNode;
}
internal abstract void _reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null);
public void Reset(GridPos iStartPos, GridPos iEndPos, BaseGrid iSearchGrid = null)
{
_reset(iStartPos, iEndPos, iSearchGrid);
m_startNode = null;
m_endNode = null;
if (iSearchGrid != null)
m_searchGrid = iSearchGrid;
m_searchGrid.Reset();
m_startNode = m_searchGrid.GetNodeAt(iStartPos.x, iStartPos.y);
m_endNode = m_searchGrid.GetNodeAt(iEndPos.x, iEndPos.y);
if (m_startNode == null)
m_startNode = new Node(iStartPos.x, iStartPos.y, true);
if (m_endNode == null)
m_endNode = new Node(iEndPos.x, iEndPos.y, true);
}
public DiagonalMovement DiagonalMovement;
public HeuristicDelegate HeuristicFunc
{
get
{
return m_heuristic;
}
}
public BaseGrid SearchGrid
{
get
{
return m_searchGrid;
}
}
public Node StartNode
{
get
{
return m_startNode;
}
}
public Node EndNode
{
get
{
return m_endNode;
}
}
public void SetHeuristic(HeuristicMode iMode)
{
m_heuristic = null;
switch (iMode)
{
case HeuristicMode.MANHATTAN:
m_heuristic = new HeuristicDelegate(Heuristic.Manhattan);
break;
case HeuristicMode.EUCLIDEAN:
m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
break;
case HeuristicMode.CHEBYSHEV:
m_heuristic = new HeuristicDelegate(Heuristic.Chebyshev);
break;
default:
m_heuristic = new HeuristicDelegate(Heuristic.Euclidean);
break;
}
}
protected BaseGrid m_searchGrid;
protected Node m_startNode;
protected Node m_endNode;
protected HeuristicDelegate m_heuristic;
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/PathFinder/Util.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EpPathFinding.cs
{
public class Util
{
public static DiagonalMovement GetDiagonalMovement(bool iCrossCorners, bool iCrossAdjacentPoint)
{
if (iCrossCorners && iCrossAdjacentPoint)
{
return DiagonalMovement.Always;
}
else if (iCrossCorners)
{
return DiagonalMovement.IfAtLeastOneWalkable;
}
else
{
return DiagonalMovement.OnlyWhenNoObstacles;
}
}
}
}
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EpPathFinding.cs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EpPathFinding.cs")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2ad88772-7442-4978-b4e1-df1a2e0ded77")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs/packages.config
================================================
================================================
FILE: EpPathFinding.cs/EpPathFinding.cs.sln
================================================
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpPathFinding.cs", "EpPathFinding.cs\EpPathFinding.cs.csproj", "{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
================================================
FILE: EpPathFindingDemo/EpPathFindingDemo.csproj
================================================
Debug
x86
8.0.30703
2.0
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}
WinExe
Properties
PathTest2010
PathTest2010
v4.0
Client
512
publish\
true
Disk
false
Foreground
7
Days
false
false
true
0
1.0.0.%2a
false
false
true
x86
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
x86
pdbonly
true
bin\Release\
TRACE
prompt
4
Form
SearchGridForm.cs
SearchGridForm.cs
Designer
ResXFileCodeGenerator
Resources.Designer.cs
Designer
True
Resources.resx
SettingsSingleFileGenerator
Settings.Designer.cs
True
Settings.settings
True
False
Microsoft .NET Framework 4 Client Profile %28x86 and x64%29
true
False
.NET Framework 3.5 SP1 Client Profile
false
False
.NET Framework 3.5 SP1
false
False
Windows Installer 3.1
true
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}
EpPathFinding.cs
================================================
FILE: EpPathFindingDemo/EpPathFindingDemo.sln
================================================
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpPathFindingDemo", "EpPathFindingDemo.csproj", "{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpPathFinding.cs", "..\EpPathFinding.cs\EpPathFinding.cs\EpPathFinding.cs.csproj", "{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Debug|Any CPU.ActiveCfg = Debug|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Debug|Mixed Platforms.Build.0 = Debug|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Debug|x86.ActiveCfg = Debug|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Debug|x86.Build.0 = Debug|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Release|Any CPU.ActiveCfg = Release|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Release|Mixed Platforms.ActiveCfg = Release|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Release|Mixed Platforms.Build.0 = Release|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Release|x86.ActiveCfg = Release|x86
{82FE700A-0BA3-49D0-ACE0-C1F87FBE5021}.Release|x86.Build.0 = Release|x86
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Debug|x86.ActiveCfg = Debug|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Any CPU.Build.0 = Release|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4BC2B4B0-2A38-4274-98A2-37CEF5F03B42}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
================================================
FILE: EpPathFindingDemo/General/SingletonHolder.cs
================================================
/*!
@file SingletonHolder.cs
@author Woong Gyu La a.k.a Chris.
@date September 27, 2013
@brief SingletonHolder Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the SingletonHolder Class.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace EpPathFinding.cs
{
public class SingletonHolder where T : new()
{
private static T m_instance;
private SingletonHolder()
{
}
public static T Instance
{
get
{
if (m_instance == null)
{
m_instance = new T();
}
return m_instance;
}
}
}
}
================================================
FILE: EpPathFindingDemo/GridBox.cs
================================================
/*!
@file GridBox.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief GridBox Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the GridBox Class.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace EpPathFinding.cs
{
enum BoxType { Start, End, Wall, Normal };
class GridBox:IDisposable
{
public int x, y, width, height;
public SolidBrush brush;
public Rectangle boxRec;
public BoxType boxType;
public GridBox(int iX, int iY,BoxType iType)
{
this.x = iX;
this.y = iY;
this.boxType = iType;
switch (iType)
{
case BoxType.Normal:
brush = new SolidBrush(Color.WhiteSmoke);
break;
case BoxType.End:
brush = new SolidBrush(Color.Red);
break;
case BoxType.Start:
brush = new SolidBrush(Color.Green);
break;
case BoxType.Wall:
brush = new SolidBrush(Color.Gray);
break;
}
width = 18;
height = 18;
boxRec = new Rectangle(x, y, width, height);
}
public void DrawBox(Graphics iPaper,BoxType iType)
{
if (iType == boxType)
{
boxRec.X = x;
boxRec.Y = y;
iPaper.FillRectangle(brush, boxRec);
}
}
public void SwitchBox()
{
switch (this.boxType)
{
case BoxType.Normal:
if (this.brush != null)
this.brush.Dispose();
this.brush = new SolidBrush(Color.Gray);
this.boxType = BoxType.Wall;
break;
case BoxType.Wall:
if (this.brush != null)
this.brush.Dispose();
this.brush = new SolidBrush(Color.WhiteSmoke);
this.boxType = BoxType.Normal;
break;
}
}
public void SetNormalBox()
{
if (this.brush != null)
this.brush.Dispose();
this.brush = new SolidBrush(Color.WhiteSmoke);
this.boxType = BoxType.Normal;
}
public void SetStartBox()
{
if (this.brush != null)
this.brush.Dispose();
this.brush = new SolidBrush(Color.Green);
this.boxType = BoxType.Start;
}
public void SetEndBox()
{
if (this.brush != null)
this.brush.Dispose();
this.brush = new SolidBrush(Color.Red);
this.boxType = BoxType.End;
}
public void Dispose()
{
if(this.brush!=null)
this.brush.Dispose();
}
}
}
================================================
FILE: EpPathFindingDemo/GridLine.cs
================================================
/*!
@file GridLine.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief GridLine Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the GridLine Class.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace EpPathFinding.cs
{
class GridLine
{
public int fromX, fromY, toX, toY;
public Pen pen;
public GridLine(GridBox iFrom, GridBox iTo)
{
this.fromX = iFrom.boxRec.X + 9;
this.fromY = iFrom.boxRec.Y + 9;
this.toX = iTo.boxRec.X + 9;
this.toY = iTo.boxRec.Y + 9;
pen = new Pen(Color.Yellow);
pen.Width = 2;
}
public void drawLine(Graphics iPaper)
{
iPaper.DrawLine(pen, fromX, fromY, toX, toY);
}
public void Dispose()
{
if (this.pen != null)
this.pen.Dispose();
}
}
}
================================================
FILE: EpPathFindingDemo/LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
================================================
FILE: EpPathFindingDemo/Program.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EpPathFindingDemo
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SearchGridForm());
}
}
}
================================================
FILE: EpPathFindingDemo/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PathTest2010")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Woong Gyu La")]
[assembly: AssemblyProduct("PathTest2010")]
[assembly: AssemblyCopyright("Copyright © Woong Gyu La 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7fd522da-b279-4de9-85fb-ab35ff160ed5")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: EpPathFindingDemo/Properties/Resources.Designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.18047
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PathTest2010.Properties
{
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PathTest2010.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
================================================
FILE: EpPathFindingDemo/Properties/Resources.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: EpPathFindingDemo/Properties/Settings.Designer.cs
================================================
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.18047
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace PathTest2010.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
================================================
FILE: EpPathFindingDemo/Properties/Settings.settings
================================================
================================================
FILE: EpPathFindingDemo/ResultBox.cs
================================================
/*!
@file ResultBox.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief ResultBox Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the ResultBox Class.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace EpPathFinding.cs
{
enum ResultBoxType { Opened,Closed };
class ResultBox
{
public int x, y, width, height;
public SolidBrush brush;
public Rectangle boxRec;
public ResultBoxType boxType;
public ResultBox(int iX, int iY, ResultBoxType iType)
{
this.x = iX;
this.y = iY;
this.boxType = iType;
switch (iType)
{
case ResultBoxType.Opened:
brush = new SolidBrush(Color.AliceBlue);
break;
case ResultBoxType.Closed:
brush = new SolidBrush(Color.LightGreen);
break;
}
width = 18;
height = 18;
boxRec = new Rectangle(x, y, width, height);
}
public void drawBox(Graphics iPaper)
{
boxRec.X = x;
boxRec.Y = y;
iPaper.FillRectangle(brush, boxRec);
}
public void Dispose()
{
if(this.brush!=null)
this.brush.Dispose();
}
}
}
================================================
FILE: EpPathFindingDemo/SearchGridForm.Designer.cs
================================================
namespace EpPathFindingDemo
{
partial class SearchGridForm
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnSearch = new System.Windows.Forms.Button();
this.btnClearPath = new System.Windows.Forms.Button();
this.btnClearWall = new System.Windows.Forms.Button();
this.cbUseRecursive = new System.Windows.Forms.CheckBox();
this.cbbJumpType = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(11, 14);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(64, 25);
this.btnSearch.TabIndex = 0;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnClearPath
//
this.btnClearPath.Location = new System.Drawing.Point(81, 13);
this.btnClearPath.Name = "btnClearPath";
this.btnClearPath.Size = new System.Drawing.Size(64, 25);
this.btnClearPath.TabIndex = 1;
this.btnClearPath.Text = "Clear Path";
this.btnClearPath.UseVisualStyleBackColor = true;
this.btnClearPath.Click += new System.EventHandler(this.btnClearPath_Click);
//
// btnClearWall
//
this.btnClearWall.Location = new System.Drawing.Point(152, 12);
this.btnClearWall.Name = "btnClearWall";
this.btnClearWall.Size = new System.Drawing.Size(89, 25);
this.btnClearWall.TabIndex = 2;
this.btnClearWall.Text = "Clear Walls";
this.btnClearWall.UseVisualStyleBackColor = true;
this.btnClearWall.Click += new System.EventHandler(this.btnClearWall_Click);
//
// cbUseRecursive
//
this.cbUseRecursive.AutoSize = true;
this.cbUseRecursive.Location = new System.Drawing.Point(533, 17);
this.cbUseRecursive.Name = "cbUseRecursive";
this.cbUseRecursive.Size = new System.Drawing.Size(96, 17);
this.cbUseRecursive.TabIndex = 6;
this.cbUseRecursive.Text = "Use Recursive";
this.cbUseRecursive.UseVisualStyleBackColor = true;
//
// cbbJumpType
//
this.cbbJumpType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbbJumpType.FormattingEnabled = true;
this.cbbJumpType.Location = new System.Drawing.Point(338, 16);
this.cbbJumpType.Name = "cbbJumpType";
this.cbbJumpType.Size = new System.Drawing.Size(189, 21);
this.cbbJumpType.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(247, 18);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(85, 13);
this.label1.TabIndex = 8;
this.label1.Text = "Diagonal Mode: ";
//
// SearchGridForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.ClientSize = new System.Drawing.Size(693, 284);
this.Controls.Add(this.label1);
this.Controls.Add(this.cbbJumpType);
this.Controls.Add(this.cbUseRecursive);
this.Controls.Add(this.btnClearWall);
this.Controls.Add(this.btnClearPath);
this.Controls.Add(this.btnSearch);
this.MaximizeBox = false;
this.Name = "SearchGridForm";
this.Text = "EpPathFinding.cs Demo";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnClearPath;
private System.Windows.Forms.Button btnClearWall;
private System.Windows.Forms.CheckBox cbUseRecursive;
private System.Windows.Forms.ComboBox cbbJumpType;
private System.Windows.Forms.Label label1;
}
}
================================================
FILE: EpPathFindingDemo/SearchGridForm.cs
================================================
/*!
@file SearchGridForm.cs
@author Woong Gyu La a.k.a Chris.
@date July 16, 2013
@brief SearchGridForm Interface
@version 2.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2013 Woong Gyu La
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for the SearchGridForm Class.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EpPathFinding.cs;
namespace EpPathFindingDemo
{
public partial class SearchGridForm : Form
{
const int width = 64;
const int height = 32;
Graphics paper;
GridBox[][] m_rectangles;
List m_resultBox;
List m_resultLine;
GridBox m_lastBoxSelect;
BoxType m_lastBoxType;
BaseGrid searchGrid;
JumpPointParam jumpParam;
public SearchGridForm()
{
InitializeComponent();
this.DoubleBuffered = true;
m_resultBox = new List();
this.Width = (width+1) * 20;
this.Height = (height+1) * 20 +100;
this.MaximumSize = new Size(this.Width, this.Height);
this.MaximizeBox = false;
m_rectangles = new GridBox[width][];
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
m_rectangles[widthTrav] = new GridBox[height];
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if(widthTrav==(width/3) && heightTrav==(height/2))
m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Start);
else if (widthTrav == 41 && heightTrav == (height / 2))
m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20 , heightTrav * 20 + 50, BoxType.End);
else
m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Normal);
}
}
cbbJumpType.Items.Add("Always");
cbbJumpType.Items.Add("Never");
cbbJumpType.Items.Add("IfAtLeastOneWalkable");
cbbJumpType.Items.Add("OnlyWhenNoObstacles");
cbbJumpType.SelectedIndex = 0;
m_resultLine = new List();
searchGrid = new StaticGrid(width, height);
// searchGrid = new DynamicGrid();
//searchGrid = new DynamicGridWPool(SingletonHolder.Instance);
jumpParam = new JumpPointParam(searchGrid, EndNodeUnWalkableTreatment.ALLOW,(DiagonalMovement)cbbJumpType.SelectedIndex, HeuristicMode.EUCLIDEAN);//new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR);
jumpParam.CurIterationType = cbUseRecursive.Checked ? IterationType.RECURSIVE : IterationType.LOOP;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
paper = e.Graphics;
//Draw
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
m_rectangles[widthTrav][heightTrav].DrawBox(paper,BoxType.Normal);
}
}
for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
{
m_resultBox[resultTrav].drawBox(paper);
}
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
m_rectangles[widthTrav][heightTrav].DrawBox(paper, BoxType.Start);
m_rectangles[widthTrav][heightTrav].DrawBox(paper, BoxType.End);
m_rectangles[widthTrav][heightTrav].DrawBox(paper, BoxType.Wall);
}
}
for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
{
m_resultLine[resultTrav].drawLine(paper);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
m_lastBoxSelect = null;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (m_lastBoxSelect == null)
{
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
{
m_lastBoxType = m_rectangles[widthTrav][heightTrav].boxType;
m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
switch (m_lastBoxType)
{
case BoxType.Normal:
case BoxType.Wall:
m_rectangles[widthTrav][heightTrav].SwitchBox();
this.Invalidate();
break;
case BoxType.Start:
case BoxType.End:
break;
}
}
}
}
return;
}
else
{
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
{
if (m_rectangles[widthTrav][heightTrav] == m_lastBoxSelect)
{
return;
}
else
{
switch (m_lastBoxType)
{
case BoxType.Normal:
case BoxType.Wall:
if (m_rectangles[widthTrav][heightTrav].boxType == m_lastBoxType)
{
m_rectangles[widthTrav][heightTrav].SwitchBox();
m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
this.Invalidate();
}
break;
case BoxType.Start:
m_lastBoxSelect.SetNormalBox();
m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
m_lastBoxSelect.SetStartBox();
this.Invalidate();
break;
case BoxType.End:
m_lastBoxSelect.SetNormalBox();
m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
m_lastBoxSelect.SetEndBox();
this.Invalidate();
break;
}
}
}
}
}
}
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
{
m_lastBoxType=m_rectangles[widthTrav][heightTrav].boxType;
m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
switch(m_lastBoxType)
{
case BoxType.Normal:
case BoxType.Wall:
m_rectangles[widthTrav][heightTrav].SwitchBox();
this.Invalidate();
break;
case BoxType.Start:
case BoxType.End:
break;
}
}
}
}
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
{
m_resultLine[resultTrav].Dispose();
}
m_resultLine.Clear();
for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
{
m_resultBox[resultTrav].Dispose();
}
m_resultBox.Clear();
GridPos startPos = new GridPos();
GridPos endPos = new GridPos();
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
if (m_rectangles[widthTrav][heightTrav].boxType != BoxType.Wall)
{
searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), true);
}
else
{
searchGrid.SetWalkableAt(new GridPos(widthTrav, heightTrav), false);
}
if(m_rectangles[widthTrav][heightTrav].boxType==BoxType.Start)
{
startPos.x=widthTrav;
startPos.y=heightTrav;
}
if(m_rectangles[widthTrav][heightTrav].boxType==BoxType.End)
{
endPos.x=widthTrav;
endPos.y=heightTrav;
}
}
}
jumpParam.DiagonalMovement = (DiagonalMovement)cbbJumpType.SelectedIndex;
jumpParam.CurIterationType = cbUseRecursive.Checked ? IterationType.RECURSIVE : IterationType.LOOP;
jumpParam.Reset(startPos, endPos);
List resultList = JumpPointFinder.FindPath(jumpParam);
for (int resultTrav = 0; resultTrav < resultList.Count-1; resultTrav++)
{
m_resultLine.Add(new GridLine(m_rectangles[resultList[resultTrav].x][resultList[resultTrav].y],m_rectangles[resultList[resultTrav+1].x][resultList[resultTrav+1].y]));
}
for (int widthTrav = 0; widthTrav < jumpParam.SearchGrid.width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < jumpParam.SearchGrid.height; heightTrav++)
{
if(jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav)==null)
continue;
if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isOpened)
{
ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Opened);
m_resultBox.Add(resultBox);
}
if (jumpParam.SearchGrid.GetNodeAt(widthTrav, heightTrav).isClosed)
{
ResultBox resultBox = new ResultBox(widthTrav * 20, heightTrav * 20 + 50, ResultBoxType.Closed);
m_resultBox.Add(resultBox);
}
}
}
this.Invalidate();
}
private void btnClearPath_Click(object sender, EventArgs e)
{
for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
{
m_resultLine[resultTrav].Dispose();
}
m_resultLine.Clear();
for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
{
m_resultBox[resultTrav].Dispose();
}
m_resultBox.Clear();
this.Invalidate();
}
private void btnClearWall_Click(object sender, EventArgs e)
{
for (int resultTrav = 0; resultTrav < m_resultLine.Count; resultTrav++)
{
m_resultLine[resultTrav].Dispose();
}
m_resultLine.Clear();
for (int resultTrav = 0; resultTrav < m_resultBox.Count; resultTrav++)
{
m_resultBox[resultTrav].Dispose();
}
m_resultBox.Clear();
for (int widthTrav = 0; widthTrav < width; widthTrav++)
{
for (int heightTrav = 0; heightTrav < height; heightTrav++)
{
switch (m_rectangles[widthTrav][heightTrav].boxType)
{
case BoxType.Normal:
case BoxType.Start:
case BoxType.End:
break;
case BoxType.Wall:
m_rectangles[widthTrav][heightTrav].SetNormalBox();
break;
}
}
}
this.Invalidate();
}
}
}
================================================
FILE: EpPathFindingDemo/SearchGridForm.resx
================================================
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
================================================
FILE: README.md
================================================
EpPathFinding.cs
================
#### A jump point search algorithm for grid based games in C# ####
For 3D Environment
-----------------
You may take a look at [EpPathFinding3D.cs](https://github.com/juhgiyo/EpPathFinding3D.cs)
Introduction
------------
This project was started after I was inspired by [PathFinding.js by Xueqiao Xu](https://github.com/qiao/PathFinding.js) and [the article by D. Harabor](http://harablog.wordpress.com/2011/09/07/jump-point-search/).
It comes along with a demo to show how the agorithm execute as similar to Xueqiao Xu's [Online Demo](http://qiao.github.com/PathFinding.js/visual).
Unity Integration Guide
------------
Copy `EpPathFinding.cs\PathFinder` folder intto your `Unity Project's Assets` folder. Then within the script file, you want to use the `EpPathFinding.cs`, just add `using EpPathFinding.cs;` namespace at the top of the file, and use it as the guide below.
(If you have a problem when compiling, please refer to [Unity Forum](http://forum.unity3d.com/threads/monodevelop-problems-with-default-parameters.67867/#post-898994))
Also `EpPathFinding.cs` depends on [C5](https://github.com/sestoft/C5).
Pre-compiled C5.dll for Unity is included in `EpPathFinding3D.cs\PathFinder\UnityC5` folder.
(Please refer to [C5 on Unity3D](https://github.com/sestoft/C5#c5-on-unity3d), if you have any dependency issue with C5.)
Nuget Package
------------
[Nuget Package](https://www.nuget.org/packages/EpPathFinding.cs/)
Basic Usage
------------
The usage and the demo has been made very similar to [PathFinding.js](https://github.com/qiao/PathFinding.js) for ease of usage.
You first need to build a grid-map. (For example: width 64 and height 32):
```c#
BaseGrid searchGrid = new StaticGrid(64, 32);
```
By default, every nodes in the grid will NOT allow to be walked through. To set whether a node at a given coordinate is walkable or not, use the `SetWalkableAt` function.
For example, in order to set the node at (10 , 20) to be walkable, where 10 is the x coordinate (from left to right), and 20 is the y coordinate (from top to bottom):
```c#
searchGrid.SetWalkableAt(10, 20, true);
// OR
searchGrid.SetWalkableAt(new GridPos(10,20),true);
```
You may also use in a 2-d array while instantiating the `StaticGrid` class. It will initiate all the nodes in the grid with the walkability indicated by the array. (`true` for walkable otherwise not walkable):
```c#
bool [][] movableMatrix = new bool [width][];
for(int widthTrav=0; widthTrav< 64; widthTrav++)
{
movableMatrix[widthTrav]=new bool[height];
for(int heightTrav=0; heightTrav < 32; heightTrav++)
{
movableMatrix[widthTrav][heightTrav]=true;
}
}
Grid searchGrid = new StaticGrid(64,32, movableMatrix);
```
In order to search the route from (10,10) to (20,10), you need to create `JumpPointParam` class with grid and start/end positions. (Note: both the start point and end point must be walkable):
```c#
GridPos startPos=new GridPos(10,10);
GridPos endPos = new GridPos(20,10);
JumpPointParam jpParam = new JumpPointParam(searchGrid,startPos,endPos );
```
You can also set/change the start and end positions later. (However the start and end positions must be set before the actual search):
```c#
JumpPoinParam jpParam = new JumpPointParam(searchGrid);
jpParam.Reset(new GridPos(10,10), new GridPos(20,10));
```
To find a path, simply run `FindPath` function with `JumpPointParam` object created above:
```c#
List resultPathList = JumpPointFinder.FindPath(jpParam);
```
`JumpPointParam` class can be used as much as you want with different start/end positions unlike [PathFinding.js](https://github.com/qiao/PathFinding.js):
```c#
jpParam.Reset(new GridPos(15,15), new GridPos(20,15));
resultPathList = JumpPointFinder.FindPath(jpParam);
```
Advanced Usage
------------
#### Find the path even the end node is unwalkable ####
When instantiating the `JumpPointParam`, you may pass in additional parameter to make the search able to find path even the end node is unwalkable grid:
```
Note that it automatically sets to ALLOW as a default when the parameter is not specified.
```
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW);
```
If `iAllowEndNodeUnWalkable` is DISALLOW the FindPath will return the empty path if the end node is unwalkable:
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.DISALLOW);
```
#### DiagonalMovement.Always (Cross Adjacent Point) ####
In order to make search able to walk diagonally across corner of two diagonal unwalkable nodes:
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW,DiagonalMovement.Always);
```
#### DiagonalMovement.IfAtLeastOneWalkable (Cross Corner) ####
When instantiating the `JumpPointParam`, to make the search able to walk diagonally when one of the side is unwalkable grid:
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW,DiagonalMovement.IfAtLeastOneWalkable);
```
#### DiagonalMovement.OnlyWhenNoObstacles ####
To make it unable to walk diagonally when one of the side is unwalkable and rather go around the corner:
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW,DiagonalMovement.OnlyWhenNoObstacles);
```
#### DiagonalMovement.Never ####
To make it unable to walk diagonally:
```c#
// Special thanks to Nil Amar for the idea!
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW,DiagonalMovement.Never);
```
#### Heuristic Functions ####
The predefined heuristics are `Heuristic.EUCLIDEAN` (default), `Heuristic.MANHATTAN`, and `Heuristic.CHEBYSHEV`.
To use the `MANHATTAN` heuristic:
```c#
JumpPointParam jpParam = new JumpPointParam(searchGrid,EndNodeUnWalkableTreatment.ALLOW, DiagonalMovement.Always, Heuristic.MANHATTAN);
```
You can always change the heuristics later with `SetHeuristic` function:
```c#
jpParam.SetHeuristic(Heuristic.MANHATTAN);
```
#### Dynamic Grid ####
For my grid-based game, I had much less walkable grid nodes than un-walkable grid nodes. So above `StaticGrid` was wasting too much memory to hold un-walkable grid nodes. To avoid the memory waste, I have created `DynamicGrid`, which allocates the memory for only walkable grid nodes.
(Please note that there is trade off of memory and performance. This degrades the performance to improve memory usage.)
```c#
BaseGrid seachGrid = new DynamicGrid();
```
You may also use a `List` of walkable `GridPos`, while instantiating the `DynamicGrid` class. It will initiate only the nodes in the grid where the walkability is `true`:
```c#
List walkableGridPosList= new List();
for(int widthTrav=0; widthTrav< 64; widthTrav++)
{
movableMatrix[widthTrav]=new bool[height];
for(int heightTrav=0; heightTrav < 32; heightTrav++)
{
walkableGridPosList.Add(new GridPos(widthTrav, heightTrav));
}
}
BaseGrid searchGrid = new DynamicGrid(walkableGridPosList);
```
Rest of the functionality like `SetWalkableAt`, `Reset`, etc. are same as `StaticGrid`.
#### Dynamic Grid With Pool ####
In many cases, you might want to reuse the same grid for next search. And this can be extremely useful when used with `PartialGridWPool`, since you don't have to allocate the grid again.
```c#
NodePool nodePool = new NodePool();
BaseGrid seachGrid = new DynamicGridWPool(nodePool);
```
Rest of the functionality like `SetWalkableAt`, `Reset`, etc. are same as `DynamicGrid`.
#### Partial Grid With Pool ####
As mentioned above, if you want to search only partial of the grid for performance reason, you can use `PartialGridWPool`. Just give the `GridRect` which shows the portion of the grid you want to search within.
```c#
NodePool nodePool = new NodePool();
...
BaseGrid seachGrid = new PartialGridWPool(nodePool, new GridRect(1,3,15,30);
```
Rest of the functionality like `SetWalkableAt`, `Reset`, etc. are same as `DynamicGridWPool`.
#### IterationType ####
You may use recursive function or loop function to find the path. This can be simply done by setting IterationType flag in JumpPointParam:
```
Note that the default is IterationType.LOOP, which uses loop function.
```
```c#
// To use recursive function
JumpPointParam jpParam = new JumpPointParam(...);
jpParam.IterationType = IterationType.RECURSIVE;
```
To change back to loop function
```c#
// To change back to loop function
jpParam.IterationType = IterationType.LOOP;
```
#### Extendability ####
You can also create a sub-class of `BaseGrid` to create your own way of `Grid` class to best support your situation.
License
-------
[The MIT License](http://opensource.org/licenses/mit-license.php)
Copyright (c) 2013 Woong Gyu La <[juhgiyo@gmail.com](mailto:juhgiyo@gmail.com)>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
================================================
FILE: _config.yml
================================================
theme: jekyll-theme-cayman