|
-
SaphuA
Need help with a 'scan' pathfinding algorithm
Hi there,
the first thing I should say; I'm not creating this project in Flash, but in Java. (This also explains my absence lately ). I had tried to code it in Flash, but it simply couldn't handle it because of speed-issues. However, I do like all the feedback most people give me here, so that why I'd rather post here.
I'll first explain a bit about the project:
I'm re-creating a game called Kurve. Me and my mates have been playing quite some times lately, and realy enjoyed it. However, the game doesn't have much variety nor doesn't it allow any custom settings. Therefor I decided to remake the game with some nice addons.
The game itself is an offline multiplayer game. Up to 6 people on one keyboard can play the game and each get 2 keys. One to steer left, and one to steer right. Each player controll's a snake (which grows in size each step). The objective is to survive as long as possible. You'll die when you either hit a wall, or another snake.
One of the things I wanted to add, is AI. A computer controlled snake, which won't be very smart, but still tries to avoid wall's or snakes. This is where I need help right away 
I reckon that this AI would mostly concist of a pathfinding algorithm, which will scan the road ahead, and then pick a new direction. But I'd have no clue on how to this, decently. I was hoping someone could give me any tips on how to achieve this, or other idea's to solve this.
What should not be forgotten, is that each snake has a 'rotation' speed, so it can't just change direction whenever it wants to. It take some time to rotate to a desired direction.
Also, something that would be realy great; in the original game (and in mine) every x-steps a hole is created in the snake, where other snakes can pass through (this is to prevent the screen from filling up too soon). It would be neat if the AI would also use these holes, but not neccesary. The AI can be as dumb as it has to be, as long you can still see it atleast tries to do something.
This is the important data or fields I'm using:
- Passable pixels (either a hole in a snake or just normal ground) are stored in a 800x600 boolean array. This should also be used for pathfinding.
- Each snake has a movement speed, thickness and rotation speed.
I hope I've been clear enough and that someone can help me.
Best regards,
~Sph
-
SaphuA
Aww, am I being ignored since it's a Java project?
-
Hype over content...
Yep 
Squize.
-
Hype over content...
Crap posts from me aside mate, it's something not many people here would have put much thought into 'cause it's not something easily done in Flash ( It's like most people here won't have thought about how to code a shader, 'cause it's so far outside of Flash's scope ).
I'd guess you'd use the usual tile based approach ( Or at least a collision array ) and then read x number of tiles ahead, so the snake does have time to rotate out of harms way. With java you should more than enough processing power to read a lot more ahead, and then take AI like choices from there ( So it could almost work like a chess game, with a look ahead, so it'd be aware of where every sprite would be in 10 frames time and calculate it's actions from there ).
Squize.
-
Senior Member
 Originally Posted by SaphuA
Aww, am I being ignored since it's a Java project? 
I would guess not because its Java, but because its bloody difficult.
Something like this perhaps:
*the computer snake looks ahead in the direction it is currently going and finds time it would take it to hit other snake or the wall
*then it calculates new position and new movement direction if it would turn right or left
*then it finds time to hit something after right or left turn
*compare all 3 times
*if time to hit something after turning is longer then current then turn that way
*to make it dumber, dont let it compare times at each step, but make it go on current direction for some number of steps
Last edited by tonypa; 06-30-2006 at 05:51 AM.
-
Feeling adventurous?
Like this? (ins/del to speed up/down)
Made it a while ago.. I think I just used hittest in front of the snake, like 10 checks.. the distance between I used, I think I just used the with of the snake or something.. Doesnt work too good, but it works
I don't have a photograph, but you can have my footprints. They're upstairs in my socks.
-
var x:Number = 1; x /= 0;
That's really cool! I never would have thought to use hittest for something like that!
-
SaphuA
Hey Tiger,
Your file is somewhat in the direction what I need, but not advanced enough, and hitTest is definatly out of the option.
Thanks for showing it though, any feedback is nice.
~Sph
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|