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):
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
Computer Snakes
Computer Snakes
- Attachments
-
- ComputerSnake.love
- (26.97 KiB) Downloaded 226 times
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Computer Snakes
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
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
Tron:)
Waiting for mode "human vs computer"
Waiting for mode "human vs computer"
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Computer Snakes
Aw man, I miss KTron, I spent a lot of my old Networking class playing that.RPG wrote:Tron:)
Waiting for mode "human vs computer"
Kurosuke needs beta testers
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Computer Snakes
Where can one find A*?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Computer Snakes
http://lmddgtfy.com/?q=A*Jasoco wrote:Where can one find A*?
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Computer Snakes
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.Robin wrote:http://lmddgtfy.com/?q=A*Jasoco wrote:Where can one find A*?
Is there any A* library for Löve already made?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Computer Snakes
That's why I introduced you to the magic that is DuckDuckGo.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.
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.Jasoco wrote:Is there any A* library for Löve already made?
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.
Re: Computer Snakes
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-StarJasoco 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.Robin wrote:http://lmddgtfy.com/?q=A*Jasoco wrote:Where can one find A*?
Who is online
Users browsing this forum: No registered users and 2 guests