Making A Snake AI (A* Algorithm)

Making A Snake AI (A* Algorithm)

Omer Yalavac

3 года назад

11,911 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@3POnline
@3POnline - 09.03.2021 13:31

How’s this not blowing up 😤😭

Ответить
@superhussein
@superhussein - 05.04.2021 04:01

this algorithm dooesnt work and will lead to failure!

Ответить
@hellioncoder
@hellioncoder - 09.06.2021 18:47

Use Hamiltonian cycle this is the best algorithm you can use for such a game

Ответить
@SianaGearz
@SianaGearz - 08.07.2021 08:20

I can't necessarily tell you how to build a better snake AI, though Code Bullet and AlphaPhoenix can. But if you did come up with an actually great one, you'd have the problem of apple spawning, that it can take an eternity to spawn if it has to check every time whether it's in a snake, and the snake takes up a good chunk of the playfield.

Most efficient is to just calculate the number of non-snake fields by subtracting the snake length from the playfield size. Then you generate a random number in the range up to the number of non-snake fields. Then you just iterate through the playfield, counting all non snake fields as you encounter them, until you reach the number that you just rolled.

Ответить
@not_pockchan3418
@not_pockchan3418 - 24.07.2021 08:00

great job m8

Ответить
@nekomc2394
@nekomc2394 - 07.08.2021 17:40

ur so goooooodd omg

Ответить
@absence9443
@absence9443 - 15.10.2021 01:07

Hmm, I mean it's sorta decent in this case, but pure A* is more useful in many other 2d projects where the instance itself cannot block it's own path. For Snake it's more about preventing deaths while preserving efficiency, for example by using area checks on the three available directions or value heuristics. I tried doing an AI as well with the following order:

1. Choice Elimination
> Border Avoidance
> Body Avoidance (I let multiple snakes compete against each other)
> Next Move Avoidance

2. Path preference
> Movement towards apple in absolute grid
> Movement towards apple in geometric grid
> Movement away from other heads (again with multiple snakes)
> Degradation near border
> Reverse Degredation near apple

3. Area Comparisons
> Basic Area Check
> 10 Stepper Rule

Letting them compete against each other, snakes maintain an incredible lifespan while growing and cutting off others / backing out, once they're alone they cover usually around 40-50% of the map, which is I think pretty astounding when not using any pathfinding or path patterns that the snake follows.

Ответить
@fallencore2216
@fallencore2216 - 28.01.2022 23:56

Can u do the code en C#? :c

Ответить
@fayezhadichbaro6540
@fayezhadichbaro6540 - 27.04.2022 02:05

brooo ur soooooooo underratedddddd

Ответить
@aesvarash3256
@aesvarash3256 - 16.06.2022 22:38

Underrated . Prefect.

Ответить
@younesskherbache7598
@younesskherbache7598 - 24.10.2022 20:52

dude ur king nice and cool video <33

Ответить
@luisfelipedasilva7128
@luisfelipedasilva7128 - 09.11.2022 22:16

So much good, do more videos like this.

Ответить
@imanmagdy6476
@imanmagdy6476 - 30.12.2022 17:30

can i have the code ???

Ответить