A-star算法Java实现技术咨询:基于20×20网格的实现疑问
Hey folks! I recently wrapped up a class assignment where I implemented the A* algorithm in Java, targeting a 20×20 grid as input data. Here's a breakdown of my process and observations:
核心实现要求
The assignment strictly followed the A* pseudocode, which mandates a key step:
- Every time we select a node to traverse, it has to be the one with the lowest total cost from the open list.
多语言参考的发现
Before diving into Java code, I looked up A* implementations in Ruby, Python, and C++ to get a sense of best practices. I noticed a universal pattern across all these languages:
They all strictly adhere to the core principle of A* algorithm — prioritizing nodes with the smallest
f(n)value, wheref(n) = g(n) + h(n)(g(n)is the actual cost from the start node to current node,h(n)is the heuristic estimate from current node to the goal).
This consistency across languages helped me solidify the key rules I needed to follow, making the Java implementation smoother once I started coding.
内容的提问来源于stack exchange,提问作者Sameeha Rahman

