Page 1 of 2

Computer Snakes

Posted: Thu Mar 03, 2011 5:45 pm
by Motig
I thought it'd be fun to try and make the computer play a game of snake.

These snakes may not have turned out very smart but are still pretty fun to watch! I'm hoping to make their movement a lot smarter in future versions. The biggest issue is just them killing each other because they are only looking 1 step ahead. Instead I'd like them to plot a route to the food every time they have to move.

Features:
- You can let as much snakes play as you want.
- You can place obstacles for the snakes to navigate around
- 2 different drawmodes (drawmode "line" is fairly useless but still fun to try)
- You can manually place food
- Change the speed of the snakes
- Change the amount of bodies the snake should grow when eating
- Chang the scale(how big everything is)
- Option to remove dead snakes

Controls:
Up/down to change settings, left/right to decrease/increase values.
Left mouse button places obstacles, right mouse button removes them.
Middle mouse button places food.
Space pauses the game and enter lets you start/restart

Screenshot of a snake navigating around a simple obstacle (this was made with a higher scale setting):
Image

This is what happens with drawmode "line" and _a lot_ of snakes:
http://wtfrandom.com/love%202011-03-01% ... -50-53.png

A movie I made a while ago and posted on the irc channel:
http://www.youtube.com/watch?v=DNMzVhpc_6s

Re: Computer Snakes

Posted: Thu Mar 03, 2011 5:55 pm
by nevon
Maybe you've already figured this out, but you could just use a pathfinding algorithm (like A*) and treat the snake bodies like walls. That would make the snakes appear far more intelligent.

Re: Computer Snakes

Posted: Thu Mar 03, 2011 6:01 pm
by Motig
Yeah I guess I could've used an algorithm, my goal was really just to try and make this myself though. But that's a good tip and I may try implementing something like that!

Re: Computer Snakes

Posted: Thu Mar 03, 2011 7:12 pm
by RPG
Tron:)
Waiting for mode "human vs computer"

Re: Computer Snakes

Posted: Thu Mar 03, 2011 8:15 pm
by tentus
RPG wrote:Tron:)
Waiting for mode "human vs computer"
Aw man, I miss KTron, I spent a lot of my old Networking class playing that.

Re: Computer Snakes

Posted: Sat Mar 05, 2011 9:08 am
by Jasoco
Where can one find A*?

Re: Computer Snakes

Posted: Sat Mar 05, 2011 10:05 am
by Robin
Jasoco wrote:Where can one find A*?
http://lmddgtfy.com/?q=A* :3

Re: Computer Snakes

Posted: Sat Mar 05, 2011 10:38 am
by Jasoco
Robin wrote:
Jasoco wrote:Where can one find A*?
http://lmddgtfy.com/?q=A* :3
I Googled but Google dropped the * and gave me the definition of the letter A. Which, by the way is the first letter in the English alphabet.

Is there any A* library for Löve already made?

Re: Computer Snakes

Posted: Sat Mar 05, 2011 10:49 am
by Robin
Jasoco wrote:I Googled but Google dropped the * and gave me the definition of the letter A. Which, by the way is the first letter in the English alphabet.
That's why I introduced you to the magic that is DuckDuckGo. ;)
Jasoco wrote:Is there any A* library for Löve already made?
Dunno, but A* isn't hard to implement. A general A* library wouldn't really work well either, I think, since it needs either knowledge about the specific representation used in your game or some sort of API.

A* is simply: minimize (steps taken + distance to goal). I think Wikipedia explains it well enough for someone like you to implement.

Re: Computer Snakes

Posted: Sun Mar 06, 2011 5:42 pm
by kalle2990
Jasoco wrote:
Robin wrote:
Jasoco wrote:Where can one find A*?
http://lmddgtfy.com/?q=A* :3
I Googled but Google dropped the * and gave me the definition of the letter A. Which, by the way is the first letter in the English alphabet.
Because of the same reason that you cannot use # in searches you cannot use *. Just like replacing C# with C-Sharp I guess you can replace A* with A-Star ;)