]> git.itanic.dy.fi Git - matopeli/log
matopeli
2 months agoTransform dead worm segments back to apples master
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>
2 months agomato_ai: Avoit NULL pointer dereference when no apples
Timo Kokkonen [Tue, 6 Feb 2024 19:02:48 +0000 (21:02 +0200)]
mato_ai: Avoit NULL pointer dereference when no apples

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
2 months agoAdd score for killing enemy
Timo Kokkonen [Tue, 6 Feb 2024 17:46:58 +0000 (19:46 +0200)]
Add score for killing enemy

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
19 months agomato_ai: Partial rewrite
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>
19 months agoputpixel: Add boundary checks
Timo Kokkonen [Sat, 17 Sep 2022 14:37:59 +0000 (17:37 +0300)]
putpixel: Add boundary checks

Do not draw outside of the screen. That will lead to a crash.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
19 months agoAdd "autopilot" key for human players
Timo Kokkonen [Sat, 17 Sep 2022 12:40:04 +0000 (15:40 +0300)]
Add "autopilot" key for human players

If human player is bored and don't want to control the worm
him/herself, just press the "autopilot" key and the worm will play it
itself.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
19 months agoAdd OMPPU_IS_OWN_SEGMENT macro
Timo Kokkonen [Sat, 17 Sep 2022 12:35:43 +0000 (15:35 +0300)]
Add OMPPU_IS_OWN_SEGMENT macro

Just to check conveniently whether an apple is actually a leftover
segment of our own.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
19 months agoAdd score counting
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>
22 months agomato_ai: reduce worms getting suck next to walls
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>
22 months agoRemove head segment off mato struct
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>
22 months agomato_ai: Add wall stuck avoidance feature
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>
22 months agomato_ai: Add collision avoidance
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>
22 months agoAdd computer worms
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>
22 months agoMake it possible for a worm to die
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>
22 months agoInherit "goldiness" from apples to worm segments
Timo Kokkonen [Sun, 29 May 2022 17:39:01 +0000 (20:39 +0300)]
Inherit "goldiness" from apples to worm segments

Golden segments have golden color. If you eat a golden segment, you
will gain third of the full boost.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
22 months agoImplement extra penalty when cutting a worm
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>
22 months agoImplement Turbo Boost indicator
Timo Kokkonen [Sun, 29 May 2022 16:38:00 +0000 (19:38 +0300)]
Implement Turbo Boost indicator

This is just a simple rectangular bar that shrinks as boost time is
gone.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoShrink the "smooth end" time in turbo boost time to 3 seconds
Timo Kokkonen [Sun, 29 May 2022 15:02:14 +0000 (18:02 +0300)]
Shrink the "smooth end" time in turbo boost time to 3 seconds

Otherwise you need to collect too many apples until you see any boost
effect, so boos becomes usable faster.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoImplement element position scaling when resizing window
Timo Kokkonen [Sun, 29 May 2022 14:59:53 +0000 (17:59 +0300)]
Implement element position scaling when resizing window

Scale every object on the screen as we resize the window so that all
element stay relatively on the same location on the window.

This looks bit funny, but it's better than causing some objects to be
left outside of the window when we shrink the window.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoGive boost penalty for player cutting a worm
Timo Kokkonen [Sun, 29 May 2022 14:15:21 +0000 (17:15 +0300)]
Give boost penalty for player cutting a worm

Give disadvantage for a player who cuts a worm by slashing boost time
to zero instantly.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoImprove turbo feature
Timo Kokkonen [Sun, 29 May 2022 14:11:54 +0000 (17:11 +0300)]
Improve turbo feature

Now it starts and stops smoothly when there is only small amount of
turbo time left.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoRefactor time step variable into context structure
Timo Kokkonen [Sun, 29 May 2022 12:51:49 +0000 (15:51 +0300)]
Refactor time step variable into context structure

This is used commonly in various functions. It is better to make it
accessible from the context instaed of passing as separate function
argument.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoRefactor key handling code into single generic function
Timo Kokkonen [Sun, 29 May 2022 12:47:42 +0000 (15:47 +0300)]
Refactor key handling code into single generic function

This way it is common for each worm.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoAdd Turbo apples
Timo Kokkonen [Sun, 29 May 2022 12:37:07 +0000 (15:37 +0300)]
Add Turbo apples

Turbo apples boost your turbo to max instantly!

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoInitialize random number generator
Timo Kokkonen [Sun, 29 May 2022 12:30:11 +0000 (15:30 +0300)]
Initialize random number generator

This prevents the game from becoming repeatable from one run to
another.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoImplement turbo feature
Timo Kokkonen [Sun, 29 May 2022 12:27:41 +0000 (15:27 +0300)]
Implement turbo feature

Eating real apples increase "turbo" counter, which allows the worm to
go faster for short moment. This way you can eat more apples than your
opponent.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoLet each worm have different color
Timo Kokkonen [Sun, 29 May 2022 12:22:53 +0000 (15:22 +0300)]
Let each worm have different color

It is more fun when you can know which parts of the lost segments
belong to which worm.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoAdd collision checks between worms
Timo Kokkonen [Sun, 29 May 2022 10:55:08 +0000 (13:55 +0300)]
Add collision checks between worms

One worm can eat each others, or itself, now. If head collides with a
segment, worm is cut and remaining segments are converted to worms.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoAdd support for second worm
Timo Kokkonen [Sun, 29 May 2022 08:59:04 +0000 (11:59 +0300)]
Add support for second worm

This can be controlled with a and d keys

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoFix crash when eating apples
Timo Kokkonen [Sun, 29 May 2022 08:45:52 +0000 (11:45 +0300)]
Fix crash when eating apples

Whe must advance to the next entry on the list when deleting apples to
avoid handling the entry after it's freed.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoAdd screen boundary collision check
Timo Kokkonen [Sun, 29 May 2022 08:17:12 +0000 (11:17 +0300)]
Add screen boundary collision check

If head collides to screen edges, do not advance past the edge.

Some minor refactoring required to get it done neatly.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
23 months agoSimple matopeli
Timo Kokkonen [Sun, 29 May 2022 07:49:59 +0000 (10:49 +0300)]
Simple matopeli

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>