|
Holy crap. My head hurts. I give you a 5 for being smarter than I.
---
Shawn Poulson
spoulson@explodingcoder.com
|
|
|
|
|
Im having a problem with a A* path finding algorithm I made. Its able to find the path but it will rarely make diagonal moves when it should.
Strart
X
X
X X X End
I think I got the math right, its the algorithm that isnt working right. Iv googled around and found some good articals but most fail to explain how to impliment it. Some come with source code but is too complex and bloated for me to grasp. Im close to giving up on using the internet to help solve my problem.
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
Henize wrote: it will rarely make diagonal moves when it should
Are diagonal cells considered as neighbours in your algorithm ? If no, then that is your problem
|
|
|
|
|
pathfinding isn't simple. FI you don't believe me, just look at teh number of RTS games that have had totally fubar systems over the years.
|
|
|
|
|
The first step is to find out why the A* chose one path over another. For instance if you compare distance, diagnal is longer on a per-case basis, the lookahead may not be evaluating far enough.
A* and D* both use a series of evaluations to reduce testing everything, find out what it is eliminating and why. Walk the through the algorithm and at test cases output evaluations either to your debugger or even with good old print statements. You are trying to understand why it is making the choices it is.
Once you know why the diagnal path is elliminated then the algorithm can be adjusted.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Your right, the look ahead is not looking far enough ahead. That seems to be my problem, I dont know how I could implement that. The A* algorithm seemed strait forward at first glance but it has eluded me. I have came so close to getting it working 3 times now(3 differnent implimintations) but all have failed.
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
|
Thanks but that impimitation is too different than the one im using. The code Im using is barrowed from an artical from codeproject but Iv heavily modified it and improved it. However there is a flaw that will take some time to figure out. The problem is this...
S = start
X = unwalkable
E = end
. = current position
When it makes the next move it will go strait right because it costs less
X
S.X E
X
the next move would be to go up or down by 1, however I need it to calculate the total cost of those two moves and compare it to just moving diagonally in the first place. I cant seem to figure out how to modify it to beable to do that. Once it makes the move it will set its parent to the previous and if it finds a better path then it would have to go through and change the parents. I may need to redesign the whole thing from scratch.
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
which article and was the original working before you modified it?
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Jeffry J. Brickley wrote: which article and was the original working before you modified it?
http://www.codeproject.com/cs/algorithms/seunghyopback.asp[^]
It worked similerly to mine except all nodes has the same gcost so it would move diagonaly much more than it should. I modified it and cleaned it up the best I could so I could put it to good use and I really want to get it working correctly so I can move on. Here is my implimintation.
http://www.codeproject.com/useritems/PathFinding_AI.asp[^]
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
Can anyone suggest me an algorithm or a method to find "Whether a Point is exist on a Bezier Curve or not"?
ie. I have x & y and I want to check whether that coordinate exist on the bezier curve or not.
|
|
|
|
|
Try the following link (from Google 'bezier curves')
http://www.moshplant.com/direct-or/bezier/math.html
John P.
|
|
|
|
|
PremalathaP wrote: Can anyone suggest me an algorithm or a method to find "Whether a Point is exist on a Bezier Curve or not"?
Try to search on the PopCap developer forum, I remember there were lots of discussions about Bezier Curve. (obviously lots of people are trying to clone Zuma )
http://developer.popcap.com/forums.php[^]
|
|
|
|
|
Are you using vb.net if so I have something that might help. If your not using vb you may be able to convert it to c or whatever flvor you like, I think the code I originally got my example from was java and I rewrote and expanded on it for vb.net.
The program draws a curve, then you click on the curve, if the x,y appears on the curve the curve is redrawn showing where you clicked and splitting the curve.
It's not commented but you should be able to figure it out.
If interested let me know and I can send the code, it's app. 68kb and I did not want to clutter up the board.
|
|
|
|
|
Funny![^]
There are II kinds of people in the world, those who understand binary and those who understand Roman numerals. Web - Blog - RSS - Math
|
|
|
|
|
I am getting "Page Not Found" Error.
Regards,
Arun Kumar.A
|
|
|
|
|
It is gone now.
"Patriotism is your conviction that this country is superior to all other countries because you were born in it." - George Bernard Shaw
Web - Blog - RSS - Math - LinkedIn - BM
|
|
|
|
|
I have a problem that I'm sure there must be a mathematical solution for. What I am trying to do is create a random triangle within a square area with as large an area (of the triangle) as possible (i.e. it would cover 50% of the area of the square). It's easy to imagine that you could pick two corners and then pick a random point along the opposite edge and you would achieve this. No problem. My problem is that I want to take this into higher dimensions. So now if you think about a tetrahedron in a 3D cube you could imagine picking any three corners on the same face and then picking a random point on the opposite face and that (I think) will give you the largest volume tetrahedron you can fit in a cube. But now what about a 4D simplex (a pentatope) in a 4D box (a hypercube? I'm not sure of the nomenclature here). Or a nD simplex in a nD box? Does anybody know if there is a general way to do this? Something I can convert to code.
For background, I am playing with the Nelder-Mead simplex method and I'm trying to evaluate the algorithm with random starting simplex, the problem is that, especially in higher dimensions, if I start with a random simplex they tend to be too small to start (for example, with the tetrahedron you could imagine you might end up with 4 points all on the same plane which gives you a volume of 0).
Thanks
|
|
|
|
|
So here's what I tried so far. I thought, after writing my last post, that I could probably select one dimension (of n total dimensions) and hold that constant at the max (or min) for that dimension for the first n points of my simplex with the other dimensions being corners of that "face". Then I make the last point be random in all dimensions except my previously selected dimension where it would have a value putting it on the opposite face to my first n points. This works fine for 2 and 3D simplex, but falls down again once you go to 4D. Sometime it appears to work and gives me a high contents (hypervolume?) for my simplex, but other times it doesn't and I'm not sure what combination of parameters are causing that.
Any geometry wiz got any help here?
|
|
|
|
|
I am not able to give you the exact solution but maybe you can find some useful info from below.
Since your problem is actually a maximal area problem, we have two things to overcome. First, in 4 dimesional space you need the concept of volume ( hypervolume etc ). You can evaluate it bu multiple integrals as in the two or three dimesional case. However, they will loose their natural meanings. Secondly, all of these can be solved analyticly. I mean you can use linear algebra and basic calculus to solve such a question.
I remember that there are exact formulas of volumes for 3 dimensional case and Maple can evaluate them. 4 dimelsional case should be just a generalization. For more information about symmetry of such objects, you can search advanced Groups and Symmetry books .
|
|
|
|
|
for nPr then "set of Permutaion of a string containing n character = Number of Combination of that string + Number of combination of reverse of that string" Provided r != 1
Is this valid
Warm Regards
Mushq
|
|
|
|
|
Please clarify. P= ? r=? - is r the number of different characters?
why would Number of Combinations of string not be inclusive (in fact identical to) Number of combinations of reverse of string, after the reverse is just one of the possible combinations...
|
|
|
|
|
Hi, what is your question ?
|
|
|
|
|
sorry for vague description.
suppose we have string "abc", here n = 3(length of string) and r = 2, then total number of permutation of r sets are.
1)"ab"
2)"ac"
3)"bc"
4)"ba"
5)"ca"
6)"cb"
and for calcuating combination of string "abc" , here n = 3, and r = 2
1)"ab"
2)"ac"
3)"bc"
and similarly for "cba", here n =3, and r = 2
6)"cb"
5)"ca"
4)"ba"
In above example permuations of string is equivalent = combination of string + Combination of Reverse String.
I hope so it is clear now
Warm Regards
Mushq
|
|
|
|
|
Ah! you are imposing an extra condition on the "Combinations" - they must be the subset r memberstaken in order
|
|
|
|