1. 방향성 생성 및 중간에 길이 크로스 될때 들어갈 수 있는 기능 구현 중
2. 4방향 설정 추가
This commit is contained in:
Binary file not shown.
@@ -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];
|
||||
|
||||
28
Form1.Designer.cs
generated
28
Form1.Designer.cs
generated
@@ -41,6 +41,8 @@
|
||||
this.btn_SetRoadPoint = new System.Windows.Forms.Button();
|
||||
this.btn_SetLeftRoadPoint = new System.Windows.Forms.Button();
|
||||
this.btn_SetRightRoadPoint = new System.Windows.Forms.Button();
|
||||
this.btn_SetUpRoadPoint = new System.Windows.Forms.Button();
|
||||
this.btn_SetDownRoadPoint = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pn_Table
|
||||
@@ -175,12 +177,36 @@
|
||||
this.btn_SetRightRoadPoint.UseVisualStyleBackColor = true;
|
||||
this.btn_SetRightRoadPoint.Click += new System.EventHandler(this.btn_SetRightRoadPoint_Click);
|
||||
//
|
||||
// btn_SetUpRoadPoint
|
||||
//
|
||||
this.btn_SetUpRoadPoint.Font = new System.Drawing.Font("Consolas", 10F);
|
||||
this.btn_SetUpRoadPoint.Location = new System.Drawing.Point(818, 408);
|
||||
this.btn_SetUpRoadPoint.Name = "btn_SetUpRoadPoint";
|
||||
this.btn_SetUpRoadPoint.Size = new System.Drawing.Size(125, 30);
|
||||
this.btn_SetUpRoadPoint.TabIndex = 15;
|
||||
this.btn_SetUpRoadPoint.Text = "UpRoadPoint";
|
||||
this.btn_SetUpRoadPoint.UseVisualStyleBackColor = true;
|
||||
this.btn_SetUpRoadPoint.Click += new System.EventHandler(this.btn_SetUpRoadPoint_Click);
|
||||
//
|
||||
// btn_SetDownRoadPoint
|
||||
//
|
||||
this.btn_SetDownRoadPoint.Font = new System.Drawing.Font("Consolas", 10F);
|
||||
this.btn_SetDownRoadPoint.Location = new System.Drawing.Point(820, 453);
|
||||
this.btn_SetDownRoadPoint.Name = "btn_SetDownRoadPoint";
|
||||
this.btn_SetDownRoadPoint.Size = new System.Drawing.Size(125, 30);
|
||||
this.btn_SetDownRoadPoint.TabIndex = 16;
|
||||
this.btn_SetDownRoadPoint.Text = "DownRoadPoint";
|
||||
this.btn_SetDownRoadPoint.UseVisualStyleBackColor = true;
|
||||
this.btn_SetDownRoadPoint.Click += new System.EventHandler(this.btn_SetDownRoadPoint_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.SystemColors.GrayText;
|
||||
this.ClientSize = new System.Drawing.Size(949, 826);
|
||||
this.Controls.Add(this.btn_SetDownRoadPoint);
|
||||
this.Controls.Add(this.btn_SetUpRoadPoint);
|
||||
this.Controls.Add(this.btn_SetRightRoadPoint);
|
||||
this.Controls.Add(this.btn_SetLeftRoadPoint);
|
||||
this.Controls.Add(this.btn_SetRoadPoint);
|
||||
@@ -217,6 +243,8 @@
|
||||
private System.Windows.Forms.Button btn_SetRoadPoint;
|
||||
private System.Windows.Forms.Button btn_SetLeftRoadPoint;
|
||||
private System.Windows.Forms.Button btn_SetRightRoadPoint;
|
||||
private System.Windows.Forms.Button btn_SetUpRoadPoint;
|
||||
private System.Windows.Forms.Button btn_SetDownRoadPoint;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
42
Form1.cs
42
Form1.cs
@@ -13,7 +13,7 @@ namespace AStarPathFinding
|
||||
//타일 속성
|
||||
//기본, 출발점, 목적지, 벽, 열린리스트, 닫힌리스트, 길
|
||||
public enum eTileState
|
||||
{ None, Start, Goal, Wall, Road, RRoad, LRoad, Open, Close, Path }
|
||||
{ None, Start, Goal, Wall, Road, RRoad, LRoad, URoad, DRoad, Open, Close, Path }
|
||||
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
@@ -195,6 +195,12 @@ namespace AStarPathFinding
|
||||
case eTileState.RRoad:
|
||||
color = Color.DarkBlue;
|
||||
break;
|
||||
case eTileState.URoad:
|
||||
color = Color.Bisque;
|
||||
break;
|
||||
case eTileState.DRoad:
|
||||
color = Color.BlueViolet;
|
||||
break;
|
||||
}
|
||||
DrawNode(e, color, pathFinder.GetAstarNode(new Point(i, j)));
|
||||
}
|
||||
@@ -239,6 +245,16 @@ namespace AStarPathFinding
|
||||
SetCurrentAction(sender, eTileState.RRoad);
|
||||
}
|
||||
|
||||
private void btn_SetUpRoadPoint_Click(object sender, EventArgs e)
|
||||
{
|
||||
SetCurrentAction(sender, eTileState.URoad);
|
||||
}
|
||||
|
||||
private void btn_SetDownRoadPoint_Click(object sender, EventArgs e)
|
||||
{
|
||||
SetCurrentAction(sender, eTileState.DRoad);
|
||||
}
|
||||
|
||||
private void pn_Table_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
int x = e.X / tableNodeSize;
|
||||
@@ -320,6 +336,30 @@ namespace AStarPathFinding
|
||||
}
|
||||
|
||||
tableData[x, y] = eTileState.RRoad;
|
||||
break;
|
||||
case eTileState.URoad:
|
||||
if (tableData[x, y] == eTileState.Start || tableData[x, y] == eTileState.Goal)
|
||||
break;
|
||||
|
||||
if (tableData[x, y] == eTileState.URoad)
|
||||
{
|
||||
tableData[x, y] = eTileState.None;
|
||||
break;
|
||||
}
|
||||
|
||||
tableData[x, y] = eTileState.URoad;
|
||||
break;
|
||||
case eTileState.DRoad:
|
||||
if (tableData[x, y] == eTileState.Start || tableData[x, y] == eTileState.Goal)
|
||||
break;
|
||||
|
||||
if (tableData[x, y] == eTileState.DRoad)
|
||||
{
|
||||
tableData[x, y] = eTileState.None;
|
||||
break;
|
||||
}
|
||||
|
||||
tableData[x, y] = eTileState.DRoad;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user