• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How do i apply Dijkstra's algorithm?

V

Vlad13

Guest
Hello, people!
I'm extremely new to GMS/gamedev (few days), have poor computer science background but have desire to figure things out.
Last week by accident I miraculously found a single one IT vacancy (GMS developer) in my small town, requirements weren't so strict.
I got an instant realisation of a chance to become a junior game developer and finally to get a job where someone would teach me.
Got a test technical task from them – to make a platformer.
Now I have only 4 days. After googling stuff i decided to ask you guys for help, especially regarding Dijkstra's algorithm.

If you don't mind i put here whole technical task:
Don't use drag and drop game creation mechanics. Code only.
1. The game must consist of one room. There is a hero in the room that we control.
2. The room should have 2 levels of platforms, each of which can have a vertical wall at the top and / or bottom.
3. When you enter the game, a coin is randomly generated on one of the platforms. After the hero picks up a coin, the coin is generated in a different place, but not next to the hero. After picking up 10 coins, the level restarts.
Знімок екрана 2020-08-10 о 22.04.26.png
4. Position, shape (vertical walls) and the number of platforms are generated randomly.
5. The character (player) is animated and can walk left, right, jump.
6. Implement enemy that chases (flies) after the player at a speed of 0.8 times the speed of the hero, bypassing the platforms (Dijkstra's algorithm).
Do not use the built-in pathfinding capabilities (the game code should not have the mp_grid_path, mp_potential_step, mp_potentional_path functions).
Attention! Tasks are not accepted without this point. This point is key. The rest of the assignment items are optional, but desirable.
7. Implement the hero's ability to shoot at the pterodactyl, after which the pterodaktel will respawn in 5 seconds in a random place, but not next to the player.
8. Any additions or improvements you make will be considered a plus.
I figured out how to create sprites, objects, animations, moving player, platforms, collisions and other basic stuff.
Coins, shooting and random platforms task i'll try after coding Dijkstra's algorithm (but it would be great if you made a little hint).
The main problem is how to implement Dijkstra's algorithm. Googling, reading Wikipedia and our forum couldn't help me to grasp it, maybe i'm too dumb for this...
I've seen a lot of info about A* algorithm, but i guess that's not what i need.
Fortunately, enemy doesn't jump, he must just fly directly to the player avoiding obstacles.
Do i unserstand correctly that somehow I should make nodes and assign them to objects and then force one node to chase another one? Sounds easy...
Could you make a brief description of what should be my steps in order to make the enemy chase the player via Dijkstra's algorithm?
Thanks a lot!
P.S: sorry for grammatical errors, haven't spoken English recently.
 
Last edited by a moderator:

Roldy

Member
Do i unserstand correctly that somehow I should make nodes and assign them to objects and then force one node to chase another one? Sounds easy...
Could you make a brief description of what should be my steps in order to make the enemy chase the player via Dijkstra's algorithm?
Thanks a lot!
I would suggest you describe, to yourself, what Dijkstra does and how it is used. Watch youtube visualizations of it. Step through, by reading, psuedocode and implementations of Dijkstra until you understand it.

Try to implement it. Try to use it. Your failures will teach you more than anything.

If you are able to implement this task they WILL ask you questions about your implementation. You need to understand it.
 
V

Vlad13

Guest
I would suggest you describe, to yourself, what Dijkstra does and how it is used. Watch youtube visualizations of it. Step through, by reading, psuedocode and implementations of Dijkstra until you understand it.

Try to implement it. Try to use it. Your failures will teach you more than anything.

If you are able to implement this task they WILL ask you questions about your implementation. You need to understand it.
Roldy, you are absolutely right, thanks. Even if someone solves this for me it doesn't make me smarter. Then what's the point?
I mustn't give up too early on this and should watch, learn, try, try and try. But sometimes these kind of complex algorithms just doesn't fit into my head and make me upset. Have to be more consistent.
 

Roldy

Member
Just take your time and get an understanding. Briefly put your task to the side and just make a simple Dijkstra demo/implementation. Play with it, mess with it. Once you understand it then go back to your task and implement it there.

Break your problem up and deal with the parts one at a time.

Some things are hard. But the more you do them the more you realize eventually you can always figure it out. It just takes time.
 
Last edited:

Rob

Member
If you check these 2 links you'll see a graphical implementation of the algorithm as well as the difference between A* and Dijkstra's Algorithm.
wiki
difference between

The way I've seen it done (and the way I code it) is by making a grid, and each cell of the grid is a node. I don't think a grid is strictly necessary for your task, and the logic will work the same anyway.
 
V

Vlad13

Guest
If you check these 2 links you'll see a graphical implementation of the algorithm as well as the difference between A* and Dijkstra's Algorithm.
wiki
difference between

The way I've seen it done (and the way I code it) is by making a grid, and each cell of the grid is a node. I don't think a grid is strictly necessary for your task, and the logic will work the same anyway.
Thanks, Rob, you did help me, appreciate it! I was thinking about grid too, will try it.
 
Top