a-star

A* Admissible Heuristic for die rolling on grid

微笑、不失礼 提交于 2019-11-29 20:36:38
I need some help finding a good heuristic for the following problem: You are given an R -by- C grid and a six-sided die. Let start and end be two distinct cells on this grid. Find a path from start to end such that the sum of the faces of the die looking up, as the die is turning along the path, is minimal. The starting orientation of the die is the following (the "2" is facing south): The way I modeled this problem is by considering the value of the die's face as the cost of an edge in a graph. The graph's vertices are of the form (row, col, die) (i.e, a position in the grid and the current

Python - Speed up an A Star Pathfinding Algorithm

我怕爱的太早我们不能终老 提交于 2019-11-29 19:20:40
I've coded my first slightly-complex algorithm, an implementation of the A Star Pathfinding algorithm. I followed some Python.org advice on implementing graphs so a dictionary contains all the nodes each node is linked too. Now, since this is all for a game, each node is really just a tile in a grid of nodes, hence how I'm working out the heuristic and my occasional reference to them. Thanks to timeit I know that I can run this function successfully a little over one hundred times a second. Understandably this makes me a little uneasy, this is without any other 'game stuff' going on, like

A-star: heuristic for multiple goals

不问归期 提交于 2019-11-29 10:47:19
Let's consider a simple grid, where any point is connected with at most 4 other points (North-East-West-South neighborhood). I have to write program, that computes minimal route from selected initial point to any of goal points, which are connected (there is route consisting of goal points between any two goals). Of course there can be obstacles on grid. My solution is quite simple: I'm using A* algorithm with variable heuristic function h(x) - manhattan distance from x to nearest goal point. To find nearest goal point I have to do linear search (in O(n), where n - number of goal points). Here

Implementation of A Star (A*) Algorithm in Java

 ̄綄美尐妖づ 提交于 2019-11-28 21:33:49
Disclaimer: I have little background in Java, since I am predominantly a C# developer. Would like to have the java implementation of A* algorithm. Yes, I saw many versions of the same online and I am unable to choose between them. I am looking for an A* algorithm implementation that uses all new features of java that makes the algorithm faster(even if a tad bit). The reason is that we are implementing that for path-finding on an MMO and so, performance is the top priority. Any pointers ( on atleast where to look ) ? Try several, measure, pick the fastest, adapt to your needs. Performance is

Using A* to solve Travelling Salesman

天涯浪子 提交于 2019-11-28 18:48:20
I've been tasked to write an implementation of the A* algorithm (heuristics provided) that will solve the travelling salesman problem. I understand the algorithm, it's simple enough, but I just can't see the code that implements it. I mean, I get it. Priority queue for the nodes, sorted by distance + heuristic(node), add the closest node on to the path. The question is, like, what happens if the closest node can't be reached from the previous closest node? How does one actually take a "graph" as a function argument? I just can't see how the algorithm actually functions, as code. I read the

A* Admissible Heuristic for die rolling on grid

纵然是瞬间 提交于 2019-11-28 16:41:10
问题 I need some help finding a good heuristic for the following problem: You are given an R -by- C grid and a six-sided die. Let start and end be two distinct cells on this grid. Find a path from start to end such that the sum of the faces of the die looking up, as the die is turning along the path, is minimal. The starting orientation of the die is the following (the "2" is facing south): The way I modeled this problem is by considering the value of the die's face as the cost of an edge in a

How to optimally solve the flood fill puzzle?

大城市里の小女人 提交于 2019-11-28 16:06:26
I like playing the puzzle game Flood-It, which can be played online at: https://www.lemoda.net/javascript/flood-it/game.html It's also available as an iGoogle gadget. The aim is to fill the whole board with the least number of successive flood-fills. I'm trying to write a program which can solve this puzzle optimally. What's the best way to approach this problem? Ideally I want to use the A* algorithm, but I have no idea what should be the function estimating the number of steps left. I did write a program which conducted a depth-4 brute force search to maximize the filled area. It worked

Consistent and Admissible Heuristics

社会主义新天地 提交于 2019-11-28 06:46:15
Any consistent heuristic is also admissible. But when is a heuristic admissible but not consistent (monotone)? Please provide an example in which this is the case. As Russel and Norvig point out in Artificial Intelligence: A Modern Approach (the most commonly used AI textbook) it is challenging to come up with a heuristic that is admissible but not consistent. Obviously, you can select values for nodes in a graph such that the heuristic they represent is admissible but not consistent. This paper by Felner et al has a nice example of the two ways that this is possible, but it's a little dense,

How can I use the A star algorithm to find the first 100 shortest paths?

拜拜、爱过 提交于 2019-11-28 05:49:54
问题 How can I use the A star algorithm to find the first 100 shortest paths? 回答1: The problem of finding k'th shortest path is NP-Hard, so any modification to A-Star that will do what you are after - will be exponential in the size of the input. Proof: (Note: I will show on simple paths) Assume you had a polynomial algorithm that runs in polynomial time and returns the length of k the shortest path let the algorithm be A(G,k) The maximal number of paths is n! , and by applying binary search on

Need an idea for A star search algorithm with multiple goals

微笑、不失礼 提交于 2019-11-28 05:14:08
问题 The algorithm of A star search with a specified goal is pretty straightforward. However, what if there are multiple goals in a graph. For instance; you may want to find a shortest path that must include previously specified nodes. Constraint here is say your path must include A, B and C nodes( or more) not just find a path to node A or B or C. And of course the graph includes one or more A, B, C type nodes. So there is a question how can I adapt the A star search algorithm for multiple goals