1. 방향성 생성 및 중간에 길이 크로스 될때 들어갈 수 있는 기능 구현 중

2. 4방향 설정 추가
This commit is contained in:
김민구
2020-12-15 18:31:38 +09:00
parent 66a477808a
commit f4ddd11c7b
10 changed files with 115 additions and 17 deletions

View File

@@ -16,6 +16,9 @@ namespace AStarPathFinding
public int F { get; private set; } = 0;//총 비용
public int R { get; private set; } = 0;//로드 비용
public int L { get; private set; } = 0;//로드 비용
public int U { get; private set; } = 0;//로드 비용
public int D { get; private set; } = 0;//로드 비용
public int ROAD { get; private set; } = 0;
public Point ParentDirection;
public AstarNode parent { get; private set; } = null;//부모 노드, 길을 찾고 부모를 따라가면 길이생성됨
@@ -29,6 +32,9 @@ namespace AStarPathFinding
F = 0;
R = 0;
L = 0;
U = 0;
D = 0;
ROAD = 0;
}
public void SetGCost(int gcost)
@@ -126,7 +132,8 @@ namespace AStarPathFinding
case eTileState.Road:
case eTileState.RRoad:
case eTileState.LRoad:
case eTileState.URoad:
case eTileState.DRoad:
break;
default:
tableStateData[i, j] = eTileState.None;
@@ -261,25 +268,49 @@ namespace AStarPathFinding
//if (tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.Wall)
// continue;
//만일 클로즈 리스트에 있어도 무시한다.
if (dicCloseList.ContainsKey(tempChildAxis))
continue;
////포커싱하는 노드는 오픈리스트에서 뺀 후 클로즈리스트로 보낸다
//if (dicOpenList.ContainsKey(focusNode.axis) & tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.Road)
//{
// openNode = tableNodeData[tempChildAxis.X, tempChildAxis.Y];
// openNode.SetParent(focusNode);
// openNode.SetGCost(gCost + openNode.parent.ROAD);
// openNode.SetHCost(openNode.parent.ROAD - 2000);
// openNode.ParentDirection = neerAxis[i];
if (tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.Road)
// dicOpenList.Add(tempChildAxis, openNode);
// tableStateData[tempChildAxis.X, tempChildAxis.Y] = eTileState.Open;
// //dicCloseList.Remove(focusNode.axis);
// //dicOpenList.Add(focusNode.axis, focusNode);
// //tableStateData[focusNode.axis.X, focusNode.axis.Y] = eTileState.Close;
// continue;
//}
if (dicOpenList.ContainsKey(focusNode.axis) & tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.RRoad)
{
openNode = tableNodeData[tempChildAxis.X, tempChildAxis.Y];
openNode.SetParent(focusNode);
openNode.SetGCost(gCost + openNode.parent.R);
openNode.SetHCost(openNode.parent.R + 1000);
openNode.SetHCost(openNode.parent.R - 1000);
openNode.ParentDirection = neerAxis[i];
dicOpenList.Add(tempChildAxis, openNode);
tableStateData[tempChildAxis.X, tempChildAxis.Y] = eTileState.Open;
Form1.Direction = false;
//dicCloseList.Remove(focusNode.axis);
//dicOpenList.Add(focusNode.axis, focusNode);
//tableStateData[focusNode.axis.X, focusNode.axis.Y] = eTileState.Close;
continue;
}
//만일 클로즈 리스트에 있어도 무시한다.
if (dicCloseList.ContainsKey(tempChildAxis))
continue;
// !!!길일 때 오픈리스트에 넣어준다.
if (tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.RRoad & Form1.Direction == true)
{
@@ -295,7 +326,6 @@ namespace AStarPathFinding
continue;
}
// !!!길일 때 오픈리스트에 넣어준다.
if (tableStateData[tempChildAxis.X, tempChildAxis.Y] == eTileState.RRoad & Form1.Direction == false)
{
openNode = tableNodeData[tempChildAxis.X, tempChildAxis.Y];
@@ -338,16 +368,16 @@ namespace AStarPathFinding
continue;
}
//대각선일시 자신의 주변을 체크 후 벽이있다면 무시한다(벽끼고 대각선이동 불가)
if (gCost == 14)
{
Point tempNextIndex = AddPoint(focusNode.axis, neerAxis[i + 1]);
Point tempPrevIndex = AddPoint(focusNode.axis, neerAxis[i - 1 < 0 ? 7 : i - 1]); // i - 1이 0보다 작을 경우 7(참), i - 1이 0보다 클 경우 i - 1을 결과값으로 가져감
////대각선일시 자신의 주변을 체크 후 벽이있다면 무시한다(벽끼고 대각선이동 불가)
//if (gCost == 14)
//{
// Point tempNextIndex = AddPoint(focusNode.axis, neerAxis[i + 1]);
// Point tempPrevIndex = AddPoint(focusNode.axis, neerAxis[i - 1 < 0 ? 7 : i - 1]); // i - 1이 0보다 작을 경우 7(참), i - 1이 0보다 클 경우 i - 1을 결과값으로 가져감
if (tableStateData[tempNextIndex.X, tempNextIndex.Y] == eTileState.Wall ||
tableStateData[tempPrevIndex.X, tempPrevIndex.Y] == eTileState.Wall)
continue;
}
// if (tableStateData[tempNextIndex.X, tempNextIndex.Y] == eTileState.Wall ||
// tableStateData[tempPrevIndex.X, tempPrevIndex.Y] == eTileState.Wall)
// continue;
//}
//심사에 통과한 노드들은 오픈리스트에 넣어준다.
openNode = tableNodeData[tempChildAxis.X, tempChildAxis.Y];