Practical 1
Practical 1: 2D traffic World with "autonomous cars" using A* pathfinding
- Start with
A star World.
- Change grid so it is a bit like streets rather than blocks in random locations.
I am not sure how to do this.
-
I will not be fussy that it is not a perfect street layout.
Just try to make it a bit like streets.
- Have 4 "cars". Put them at random start positions with random destinations.
- Show them using A* to map path to their destination.
- Each time step, all 4 cars get to move one step.
(NOT jump straight to the end.)
- Problem: A car will move and block the path of another car.
- Cars will have to keep re-calculating their paths based on other cars blocking them.
Sometimes an entire street will block and a car will just have to wait until the other car leaves the street.
- So what we mean is that you use A* to figure the best route.
Then make the first step on that route.
Then other cars will move.
Then you do a new A* to get the new route.
And do the first step of that.
And so on.
- Show this happening graphically on screen.
i.e. Draw the paths, and re-draw them when they change.
-
You do not have to base it on
A star World (P5).
You can go your own way, use Three.js or other library for graphics, etc.
I do not mind, so long as it implements a 2D traffic World like the above.
A few thoughts on how people are approaching this
- I do not think a diagonal move looks good if that would allow the car move through an infinitely-small gap.
- People are overthinking what other cars are.
Other cars are like walls.
When you calculate your path, just treat other cars like walls.
A* should route around them.
- A deadlock is not when another car is in the way. That is like a wall. You just route around it.
- A deadlock is when there is no path to the goal at all, because a car is in the way.
Maybe it will move, maybe it will not.
You will just have to skip your turn and wait.
- Maybe deadlock is the wrong word, since the situation may resolve itself.
A deadlock would be when you are both stuck forever.
- Submit it to me through one of the following links.