Worm

G

Guest

Guest
Archived from groups: comp.ai.games (More info?)

I'm sure you all know this game... A little worm crawles on rectangle
grid bounded by 4 walls, random food appears, and when it eats, it's
getting longer... So, I am wondering what would be best strategy for
computer-controlled worm? My first try was to make it crawl along the
walls, reach out for food, grab it and get back to the wall. But then,
when I added random obstacles, such a strategy could easily lead worm
into trapping itself occasionally, so... Good strategy - what would it
be?
 
G

Guest

Guest
Archived from groups: comp.ai.games (More info?)

> divide up (in the "snake's mind") the playfield into regions with a
> 1-square-wide entry point, and make sure the snake is completely
inside a
> region (such that there's a path to the open entrance) before eating
a
> pellet in it?

good idea. not-so-tricky part of this is what to do when it is not
inside? where to crowl, if it can't crawl toward the food?
 
G

Guest

Guest
Archived from groups: comp.ai.games (More info?)

"makc.the.great" <makc.the.great@gmail.com> wrote in
news:1116248241.253411.49380@g14g2000cwa.googlegroups.com:

> I'm sure you all know this game... A little worm crawles on rectangle
> grid bounded by 4 walls, random food appears, and when it eats, it's
> getting longer... So, I am wondering what would be best strategy for
> computer-controlled worm? My first try was to make it crawl along the
> walls, reach out for food, grab it and get back to the wall. But then,
> when I added random obstacles, such a strategy could easily lead worm
> into trapping itself occasionally, so... Good strategy - what would it
> be?

Maybe divide up (in the "snake's mind") the playfield into regions with a
1-square-wide entry point, and make sure the snake is completely inside a
region (such that there's a path to the open entrance) before eating a
pellet in it? There may be other sticky points, but they can probably be
handled via similar ideas.

This harkens me back to my days trying to make QBasic "Nibbles" play on
autopilot. Maybe I'll try that again....
 
G

Guest

Guest
Archived from groups: comp.ai.games (More info?)

"makc.the.great" <makc.the.great@gmail.com> wrote in
news:1116332897.167942.68940@g44g2000cwa.googlegroups.com:

>> divide up (in the "snake's mind") the playfield into regions with a
>> 1-square-wide entry point, and make sure the snake is completely
> inside a
>> region (such that there's a path to the open entrance) before eating
> a
>> pellet in it?
>
> good idea. not-so-tricky part of this is what to do when it is not
> inside? where to crowl, if it can't crawl toward the food?

Maybe have the snake zig-zag inside the region, starting as far from the
pellet as possible. Basically, you want the snake to "bunch up", while
leaving a path to the exit, while not eating the pellet. As far as
specific algorithms to do this, I'm not sure.
 
G

Guest

Guest
Archived from groups: comp.ai.games (More info?)

Hi,

That was nice one. Developing a fool-proof AI for the snake can be
difficult.

Ok, here is an idea. I hope this might help you:

Draw an imaginary straight line from snake's head to the food. ( I am
assuming the smallest drawing element is one 'block' e.g. food occupies
one block, width of snake is one block, length of the snake is 'k'
blocks long etc.) Now for every block on the imaginary line, move the
block vertically upwards or downwards to nearest empty block i.e. to
the block which contains no obstacle. You will have the obstacle-less
path to the food. If the length of line (in block measure) is greater
than 'k'(the length of snake) then the snake cuddles itself until its
length is less than the line length. You can also check if there is a
return path is available by drawing another imaginary line (after
drawing the first line) from food to the current position of snake's
head and assuming the first imaginary line as an obstacle. This will
give you alternate return path.