Timo Kokkonen [Sun, 11 Feb 2024 12:42:57 +0000 (14:42 +0200)]
Transform dead worm segments back to apples
When a worm is cut in half, transform the dead segments into fresh
apples. In the middle of the transformation, they first become stale
worm sgements that can be eaten, but this does not yield any score nor
does it extend the worm.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sat, 17 Sep 2022 14:39:10 +0000 (17:39 +0300)]
mato_ai: Partial rewrite
Now that we have a scoring mechanism where eating your own worm
segments is penalized, the ai should avoid doing that. Therefore, as
we are searching for nearest apple, we now are also searching for
nearest stale segment that belongs to us. If stale segments are too
close, they are avoided instead of trying to reach to the closest
apple.
This alone leads to a lot of worms getting stuck next to the walls, so
new heuristics are needed to ensure we don't try to avoid stale
segments if we are close to the wall. Instead, we try to get out of
the wall first.
And as we were solving the problem with stuck worms, we also detect
when apples are next to us and thus unreachable because we can't make
tight enough turn. Such apples are ignored as well until we get far
enough from them and consider them again.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sat, 17 Sep 2022 09:57:32 +0000 (12:57 +0300)]
Add score counting
First implementation of the score counting mechanism:
* Golden apples are best
* Normal apples and golden worm segments count well
* Leftover worm segments give a little score
* Eating your own worm segments is penalized, don't do it
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sun, 19 Jun 2022 09:00:54 +0000 (12:00 +0300)]
mato_ai: reduce worms getting suck next to walls
We AI is in wall avoidance mode, it must not do any other checks.
Also if it is stuck against a wall trying to avoid colliding itself,
it should not succeed in making turns back and forth towards the
wall. Instead, if the number of self collision avoidance segments is
reduced so that the worm will cut itself when it is in this condition,
it no longer needs to avoid colliding itself and it is released out of
the stuck.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sat, 4 Jun 2022 14:37:07 +0000 (17:37 +0300)]
Remove head segment off mato struct
The mato structure doesn't need to have head segment in it. If it is
dead, it simply doesn't have a head at all. This removes the need to
have a separate variable that tells whether the worm is alive or
not. We can just check whether it has a head or not.
This is quite large and invasive change. And due to the large code
churn that is causes, many smaller bugs become more visible and had to
be fixed to get this working at all. Thus, this appears to be quite
significant improvement all over.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sat, 4 Jun 2022 08:52:26 +0000 (11:52 +0300)]
mato_ai: Add wall stuck avoidance feature
Some times there are two conflicting conditions that cause the worm to
try to aim into the wall and it gets stuck. If the worm is touching a
wall, continue executing the last turn command, whichever it was, in
order to ensure it will keep on turning until it gets away from the
wall. This ensures it doesn't get stuck.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Thu, 2 Jun 2022 17:01:47 +0000 (20:01 +0300)]
mato_ai: Add collision avoidance
Try to avoid hitting any existing worm segments. See which of them is
closest to you and in front of you, and turn away from it. Simple, but
mostly effective.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Thu, 2 Jun 2022 14:06:01 +0000 (17:06 +0300)]
Add computer worms
Computer worms have their own simple AI that controls them. They are
attracted to the nearest apple on the screen. A new computer worm is
created every 30 seconds, until there are total of 10 worms.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sun, 29 May 2022 18:09:33 +0000 (21:09 +0300)]
Make it possible for a worm to die
For now, it can die by losing all of its segments. Basically, this can
happen if a worm is significantly longer than other, it can head the
other's head and then the smaller worm dies.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Timo Kokkonen [Sun, 29 May 2022 16:58:34 +0000 (19:58 +0300)]
Implement extra penalty when cutting a worm
It would be too easy to bully your friend just by cutting him/her
shorter whenever you have the chance. So, now we add penalty to
cutting a worm. You will get split to half by your self too. You can
still do it at occassions, if you feel like it, but it will quickly
become unfavourable if you do it too much.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>