Computer Snakes

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Motig
Prole
Posts: 28
Joined: Fri Oct 15, 2010 3:43 am

Computer Snakes

Post 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
Attachments
ComputerSnake.love
(26.97 KiB) Downloaded 216 times
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Computer Snakes

Post 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.
User avatar
Motig
Prole
Posts: 28
Joined: Fri Oct 15, 2010 3:43 am

Re: Computer Snakes

Post 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!
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Computer Snakes

Post by RPG »

Tron:)
Waiting for mode "human vs computer"
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Computer Snakes

Post 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.
Kurosuke needs beta testers
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Computer Snakes

Post by Jasoco »

Where can one find A*?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Computer Snakes

Post by Robin »

Jasoco wrote:Where can one find A*?
http://lmddgtfy.com/?q=A* :3
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Computer Snakes

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Computer Snakes

Post 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.
Help us help you: attach a .love.
User avatar
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Computer Snakes

Post 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 ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests