我的A*算法实现需要一些帮助.当我运行算法时,它确实找到了目标,但路径肯定不是最短的:-P
这是我的代码,请帮我发现错误!我认为可能是重建路径是我的问题,但我不确定.
public class Pathfinder {
public List<Node> aStar(Node start, Node goal, WeightedGraph graph) {
Node x, y;
int tentative_g_score;
boolean tentative_is_better;
FScoreComparator comparator = new FScoreComparator();
List<Node> closedset = new ArrayList<Node>();
Queue<Node> openset = new PriorityQueue<Node>(10, comparator);
openset.add(start);
start.g_score = 0;
start.h_score = heuristic_cost_estimate(start, goal);
start.f_score = start.h_score;
while (!openset.isEmpty()) {
x = openset.peek();
if (x == goal) {
return reconstruct_path(goal);
}
x = openset.remove();
closedset.add(x);
for (Edge e : graph.adj(x)) {
if (e.v == x) {
y = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试用C#制作一个简单的绘图程序,但是当我绘图时它会一直闪烁,就像我需要某种双缓冲一样,但我不知道该怎么做.
我正在绘制一个Panel
,我正在使用a Bitmap
来存储图形.
这是我的代码:
public partial class Form1 : Form
{
private Bitmap drawing;
private bool leftDown = false;
private int prevX;
private int prevY;
private int currentX;
private int currentY;
public Form1()
{
InitializeComponent();
drawing = new Bitmap(panel1.Width, panel1.Height);
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
leftDown = true;
prevX = e.X;
prevY = e.Y;
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (leftDown)
{
Graphics g = …
Run Code Online (Sandbox Code Playgroud)