*CORRECTION* 41:44 I used the "step" variable in the search() method but it was supposed to be in the autoSearch() method! It was my silly mistake. (Thank you Aung Linn for pointing this out) Also, I realized I didn't use the checkedList at all in this video. I thought I might use it to check what nodes are checked and when I reset the search result but we can handle both with the checked boolean so the list was not really necessary :P
Theres no way, Ive been following your tutorials and just had to make my own A star pathfinding algorithm in java, I finished it yesterday and now today you upload a video on it.
Hello, I am very grateful to you for this video! Thank you so much. It works; One tip for MacOS users. For me the tiles would not change color by just using the method setBackground(); For example to make the start tile blue, I had to add setOpaque(true) and setBoarderPainted(false) as follows. public void setAsStart() setBackground(Color.BLUE); setForeground(Color.WHITE); setText("S"); setOpaque(true); // ensure that the button completely covers any background behind it. setBorderPainted(false); // if set to true The button will draw its border. start = true; }
Thank you!!!! I also had to use setFocusPainted(false); to get the button outline to go away: public Node(int col, int row) { this.col = col; this.row = row; setBackground(Color.white); setForeground(Color.black); setOpaque(true); // ensure that the button completely covers any background behind it. setBorderPainted(false); // if set to true The button will draw its border. setFocusPainted(false); addActionListener(this); }
Great!!! I just implemented it too... I also learned this: To move many entities, there is also the solution using Flow Fields, its algorithm is similar to A* one, I implemented it in Java recently and the performance are good. With it you have to generate just one field for all the entities, the drawback is you have to generate one vector for each tile of the map, so for big maps you have to make tradeoffs. But with many entities it should outperform A* calculation for each entity.
Really good tutorial! I'm not coding in Java but I was able to follow along just fine implementing this in a C# based project. I was quite suprised at how intuitive A* pathfinding is in terms of set up
Thank you very much, I was struggling to understand A* pathfinding, but this video helped me so much and I adapted it into my project which uses MVC architecture. Great tutorial.
i started off watching your videos but stopped and started working on my own but had a nice base to work off of, this is extremely helpful for me!!!! thank you!!!!!
Hi, I haven't been here for a long time, but I'm slowly coming back. All I can say is that one big WOW. Both this algorithm and the trading system. This is so great, I can't wait to do it myself. Please tell us if you plan to do quests? If I can ask, I would ask for a minimap and a day and night system. And most importantly, that you develop this project. You are the best java game developer na yt: D
Welcome back Michał. No plan for implementing quest system but since I've received a lot of requests for that maybe I will make it once all the essential mechanics are taken care of.
Wow!! I have been trying to implement such an algorithm but you know, I don't understand many of them And now, you have uploaded one with full explanation. Thank you. One Thing I don't understand is why you put ' step ' variable in " search "(i mean manual search) function? Shouldn't it be in " autoSearch " function?
Awesome tutorial, even Java begginer like me could understand the principle. I just noticed something while trying to implement it myself. The way you used the while loop and step counter doesn't really seem to handle the cases when goal is unreachable. At least it did not for me. Unreachable goal would result in index out of bounds exception. Since you placed "step ++" outside the while loop, it seems to me it can't count the repetitions. And it also seems that having "currentNode = openList.get(bestNodeIndex)" outside the forloop leads to a situaton when, at some point, all reachable tiles are checked, the openList is empty and there's nothing left to add (nothing that passes the conditions) and at this point, for loop ends (because openList size is 0) but AFTER that, program tries to get an element from this empty list, which causes the exception. So, should "step++" be inside while loop and "currentNode = openList.get(bestNodeIndex)" be inside the for loop (cause that fixed the issue for me perfectly) or am I missing something?
Hi Ryi! When i set my nodes like that, it doesn't find the shortest path. Is A* algorithm finds the shortest path or am i missing something in my code? //SET START AND GOAL NODE setStartNode(4,7); setGoalNode(11,5); //PLACE SOLID NODES setSolidNode(10,2); setSolidNode(10,3); setSolidNode(10,4); setSolidNode(10,5); setSolidNode(10,6); setSolidNode(10,7); setSolidNode(6,2); setSolidNode(7,2); setSolidNode(8,2); setSolidNode(9,2); setSolidNode(11,7); setSolidNode(12,7); setSolidNode(6,1); setSolidNode(6,2); setSolidNode(6,2); setSolidNode(6,1); setSolidNode(7,7);
Oh, you're right. I tested that setting and the path weren't the shortest one indeed. So I guess the current method doesn't necessarily produce the shortest one. Sorry about that! To always produce the shortest path, I think you need to re-evaluate the path when you set a parent or when you trace back to the start node.
Awesome tutorial, thank you so much! I'm trying to understand the evaluation part. I tried using the H cost for checking against the distance from the goal after the F cost check. It seems to me that the algorithm is faster that way, am I missing something in the logic?
So i stored the best path into a list array and made the entity move to it every second. Now the problem is when the entity reaches the goal i want to set the start node to the goal node and set a new goal node position, how do i do that? I hope you can reply❤❤
@RyiSnow Great video and it has helped me massively to understand the graph traversing. But, I think, a small correction is needed. At 36:33 while defining the best node index, we need to consider hCost and not fcost. because despite of we declaring hcost, it's not being utilized anywhere. Event at the time of comapring fCost == bestNodeFCost, we are only checking for gCost as a secondary check, Shouldn't it be a hCost(which is heuristic cost, to reach to goal?) Without hCost it will be a Dijkstra's Algorithm, with hCost, it will be an A*. Anyway, I've made a simple comparison of these both in a video. ua-cam.com/video/1v918Tmp_QM/v-deo.html&ab_channel=Ashishcw Let me know your thoughts.
*CORRECTION*
41:44 I used the "step" variable in the search() method but it was supposed to be in the autoSearch() method! It was my silly mistake. (Thank you Aung Linn for pointing this out)
Also, I realized I didn't use the checkedList at all in this video. I thought I might use it to check what nodes are checked and when I reset the search result but we can handle both with the checked boolean so the list was not really necessary :P
hello maybe there are some mistakes,300steps is easily passed by,we haven't set the FPS,so one ENTER key doesn't means many times?
Theres no way, Ive been following your tutorials and just had to make my own A star pathfinding algorithm in java, I finished it yesterday and now today you upload a video on it.
Wow you are the first person to make a great algothim demo in java! Thank you so much! Your video's mean so much!
Congrats! You are the first person to make me understand A*
That's great to hear!
@@RyiSnow thank you so much for your help I am making a java game and this will help me
@@RyiSnow I have searched A* in google and I didnt understand anything
Hello, I am very grateful to you for this video! Thank you so much. It works; One tip for MacOS users. For me the tiles would not change color by just using the method setBackground(); For example to make the start tile blue, I had to add setOpaque(true) and setBoarderPainted(false) as follows.
public void setAsStart()
setBackground(Color.BLUE);
setForeground(Color.WHITE);
setText("S");
setOpaque(true); // ensure that the button completely covers any background behind it.
setBorderPainted(false); // if set to true The button will draw its border.
start = true;
}
Thank you!!!! I also had to use setFocusPainted(false); to get the button outline to go away:
public Node(int col, int row) {
this.col = col;
this.row = row;
setBackground(Color.white);
setForeground(Color.black);
setOpaque(true); // ensure that the button completely covers any background behind it.
setBorderPainted(false); // if set to true The button will draw its border.
setFocusPainted(false);
addActionListener(this);
}
Great!!! I just implemented it too... I also learned this: To move many entities, there is also the solution using Flow Fields, its algorithm is similar to A* one, I implemented it in Java recently and the performance are good. With it you have to generate just one field for all the entities, the drawback is you have to generate one vector for each tile of the map, so for big maps you have to make tradeoffs. But with many entities it should outperform A* calculation for each entity.
Really good tutorial! I'm not coding in Java but I was able to follow along just fine implementing this in a C# based project. I was quite suprised at how intuitive A* pathfinding is in terms of set up
I sincerely want to thank you very much for giving me the energy to love coding even more
Thank you very much, I was struggling to understand A* pathfinding, but this video helped me so much and I adapted it into my project which uses MVC architecture. Great tutorial.
Just GREAT!! After a lot of searching this is far the best i have seen from all views.. GREAT JOB!
Thank you so much 😀
I just found your channel and I'm already a fan. I'm already arranging to watch all your videos. Thank you so much for the content, you are amazing!
Welcome and I'm glad you liked it!
Please continue to create these amazing tutorials!
Heeey RyiSnow!! That's awesome. I saw that recently in my cs major, really liked to see it here. Thank you for another video!
You are a treasure for us, thanks for these tutorials
you dont understand how badly i wanted this video
As always amazing! Worth to mention it is closely related to Breadth First Search very useful for solving programming challenges of different sort!
i started off watching your videos but stopped and started working on my own but had a nice base to work off of, this is extremely helpful for me!!!! thank you!!!!!
Hi,
I haven't been here for a long time, but I'm slowly coming back. All I can say is that one big WOW.
Both this algorithm and the trading system. This is so great, I can't wait to do it myself.
Please tell us if you plan to do quests? If I can ask, I would ask for a minimap and a day and night system. And most importantly, that you develop this project. You are the best java game developer na yt: D
Welcome back Michał. No plan for implementing quest system but since I've received a lot of requests for that maybe I will make it once all the essential mechanics are taken care of.
Wow. This is perfect.
This will make my pacman's ghost ai so much better. Thank you.
This is cool! Very well done and meticulously explained.
Thanks Edgar, glad you liked it!
Wow!! I have been trying to implement such an algorithm but you know, I don't understand many of them
And now, you have uploaded one with full explanation. Thank you.
One Thing I don't understand is why you put ' step ' variable in " search "(i mean manual search) function? Shouldn't it be in " autoSearch " function?
Oooops did I? Yes, the step++ should be in the autoSearch(). That's my mistake. Sorry about that and thanks for pointing this out!
Hey Ryi! Please make a video on how to make a grappling hook in Java. I am struggling with it for a week now. Please don't ignore this request
Awesome tutorial, even Java begginer like me could understand the principle.
I just noticed something while trying to implement it myself. The way you used the while loop and step counter doesn't really seem to handle the cases when goal is unreachable. At least it did not for me. Unreachable goal would result in index out of bounds exception.
Since you placed "step ++" outside the while loop, it seems to me it can't count the repetitions. And it also seems that having "currentNode = openList.get(bestNodeIndex)" outside the forloop leads to a situaton when, at some point, all reachable tiles are checked, the openList is empty and there's nothing left to add (nothing that passes the conditions) and at this point, for loop ends (because openList size is 0) but AFTER that, program tries to get an element from this empty list, which causes the exception.
So, should "step++" be inside while loop and "currentNode = openList.get(bestNodeIndex)" be inside the for loop (cause that fixed the issue for me perfectly) or am I missing something?
Thank you man, this video is very helpful and awesome.
ayo im first and also i saw a vid of you the other day and started with the code a game series and i think you explain it very well :)
Thank you very much for the video.
Great Video as always!
Such a legend
Hi! Can you make a video using databases(mySQL) for the game? Please!
Hi Ryi! When i set my nodes like that, it doesn't find the shortest path. Is A* algorithm finds the shortest path or am i missing something in my code?
//SET START AND GOAL NODE
setStartNode(4,7);
setGoalNode(11,5);
//PLACE SOLID NODES
setSolidNode(10,2);
setSolidNode(10,3);
setSolidNode(10,4);
setSolidNode(10,5);
setSolidNode(10,6);
setSolidNode(10,7);
setSolidNode(6,2);
setSolidNode(7,2);
setSolidNode(8,2);
setSolidNode(9,2);
setSolidNode(11,7);
setSolidNode(12,7);
setSolidNode(6,1);
setSolidNode(6,2);
setSolidNode(6,2);
setSolidNode(6,1);
setSolidNode(7,7);
Oh, you're right. I tested that setting and the path weren't the shortest one indeed. So I guess the current method doesn't necessarily produce the shortest one. Sorry about that! To always produce the shortest path, I think you need to re-evaluate the path when you set a parent or when you trace back to the start node.
@@RyiSnow you should actually check the h cost after the f cost instead of the g cost. That's why it isn't working.
@@orangomango you are right. i just tried both and checking the h cost after the g cost was shorter.
@@3bood_kr That makes more sense, because you have to reach the end so the end distance should be the shortest
G cost should be true distance from start node
Awesome tutorial, thank you so much!
I'm trying to understand the evaluation part. I tried using the H cost for checking against the distance from the goal after the F cost check. It seems to me that the algorithm is faster that way, am I missing something in the logic?
Hmm, I tested both and both took exactly the same steps to reach the goal.
Thank you so much!
Great video!
Amazing!
May I ask that is the coding same for Mac OS?
Can you make a video for sorting algorithm as well
If we move diagonally how can we calculate the cost?
Thanks!
If I put a Thread.sleep(1000); in the autosearch metodus for presentation, the program runs but the tiles do not change. Why is this?
Yeahhh all righthhhhht You rock dude!
So i stored the best path into a list array and made the entity move to it every second. Now the problem is when the entity reaches the goal i want to set the start node to the goal node and set a new goal node position, how do i do that? I hope you can reply❤❤
Nice job here
I think every node's cost should be recalculated every step you make, otherwise you are not finding the shortest path. Am I wrong?
what if I got a one dimensional array for nodes?
Nice.
🥰🥰🥰
Hi any git reference to resulting code?
Can you disponibilize the code somewhere??
It's hard to follow along without it.
could you post code please?
@RyiSnow
Great video and it has helped me massively to understand the graph traversing.
But, I think, a small correction is needed. At 36:33 while defining the best node index, we need to consider hCost and not fcost.
because despite of we declaring hcost, it's not being utilized anywhere.
Event at the time of comapring fCost == bestNodeFCost, we are only checking for gCost as a secondary check, Shouldn't it be a hCost(which is heuristic cost, to reach to goal?)
Without hCost it will be a Dijkstra's Algorithm, with hCost, it will be an A*.
Anyway, I've made a simple comparison of these both in a video.
ua-cam.com/video/1v918Tmp_QM/v-deo.html&ab_channel=Ashishcw
Let me know your thoughts.
please give me the source code
where is GIT?
amazing!!