📄 program.cs
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
namespace PathFinder
{
public class program
{
private static bool isSame(int[,] map,Stack<Point> s1, Stack<Point> s2, out int total, out int total2)
{
total = 0;
total2 = 0;
Point tempPoint;
bool same = true;
if ((s1 == null && s2 != null) || (s1 != null && s2 == null))
{
same = false;
}
else
{
while (s1.Count > 0)
{
tempPoint = s1.Pop();
total += map[tempPoint.X, tempPoint.Y];
}
while (s2.Count > 0)
{
tempPoint = s2.Pop();
total2 += map[tempPoint.X, tempPoint.Y];
}
if (total != total2) same = false;
}
Console.WriteLine(total);
Console.WriteLine(total2);
return same;
}
delegate void DrawAnswer(Stack<Point> path);
delegate Stack<Point> findPath(Point now, Point to);
public static void Main(string[] args)
{
#region TEST 2008/2/17 AStar 寻路
Random rand = new Random();
HiPerfTimer hf = new HiPerfTimer();
Point now = new Point();
Point to = new Point();
int total = 1;
Map testMap = new Map(200,200);
testMap.iniMap();
findPath myfindpath;
//myfindpath = (new PathFinder()).findWay; //SDK的方法
Stack<Point> shownStack = new Stack<Point>(), shownStack2 = new Stack<Point>(), shownStack3 = new Stack<Point>();
// hf.Start();
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < total; j++)
{
now = new Point(199, 199);
to = new Point(190, 190);
hf.Start();
myfindpath = (new AstarPathFinder(testMap)).FindWay;
shownStack = myfindpath(now, to);
hf.Stop();
Console.WriteLine("Use {1} times, Duration: {0} msec\n", hf.Duration, total);
}
hf.Start();
myfindpath = (new DFSPathFinder(testMap)).FindWay;
shownStack2 = myfindpath(now, to);
hf.Stop();
Console.WriteLine("Use {1} times, Duration: {0} msec\n", hf.Duration, total);
hf.Start();
myfindpath = (new AstarPathFinder(testMap)).FindWay;
shownStack3 = myfindpath( now, to);
testMap.draw(shownStack3);
hf.Stop();
Console.WriteLine("Use {1} times, Duration: {0} msec\n", hf.Duration, total);
int total1=0,total2=0;
isSame(testMap.map,shownStack2,shownStack,out total1,out total2);
}
Console.ReadKey();
#endregion
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -