
Show HN: Space invaders, but the invaders evolve with genetic algorithm - atum47
https://github.com/victorqribeiro/invaderz
======
spicytunacone
I really liked how you justified the gameplay with story re: "When a InvaderZ
dies, they upload their progress to the mothership, so it can generate more
InvaderZ like the ones who did well before."

The evolving enemy concept made me look up an old boss-rushing shooter that
selected the next boss's upgrades based on your performance[1]. Is this
something you're interested in refining further?

[1]:
[https://en.wikipedia.org/wiki/Warning_Forever](https://en.wikipedia.org/wiki/Warning_Forever)

~~~
atum47
The idea began with me wanting to generate space Invaders character design
using genetic algorithm, so I thought, what the heck: if I do that I might as
well do a sort of game play to justify they design. That's how this project
was borned. Who knows what it becomes? But very nice of you to comment and
leave a link.

------
NickBusey
While this is very cool, using the distance each invader survives as the
fitness score seems like maybe not the best choice for this scenario.

With so many invaders spawning at the same time, and the 'bullet' you shoot
moving so slow, the last invader to be destroyed seems to me to be a result of
random choice (which one did you get around to shooting last) rather than it
being any 'healthier' than the other invaders.

I don't really have a suggestion on how to improve it other than maybe slow
down the vertical progress of the invaders and speed up the bullet so that
distance made vertically is actually tied more closely to it's ability to
evade your shots.

~~~
thaumasiotes
> using the distance each invader survives as the fitness score seems like
> maybe not the best choice for this scenario

> With so many invaders spawning at the same time, and the 'bullet' you shoot
> moving so slow, the last invader to be destroyed seems to me to be a result
> of random choice (which one did you get around to shooting last) rather than
> it being any 'healthier' than the other invaders.

I couldn't disagree more. The fitness score is correct, because the invader
wins by covering distance.

What happens by chance early will happen by design late -- that is nearly the
entire concept of evolutionary approaches. They always improve on their
fitness function, and what matters is that you chose the right one. In this
case, improving on the distance invaders travel is the point of being an
invader, and the point of the game, so that distance is very obviously the
correct fitness function.

~~~
flashman
> the invader wins by covering distance

The invader wins by crossing the baseline. This fitness function lets me use
evolution against the invaders by letting the dumbest ones approach the
baseline before killing them, making future waves easier than if I killed the
easiest invaders first.

Perhaps the fitness score could include the number of projectiles that passed
nearby without impacting, as a measure of difficulty to hit.

~~~
thaumasiotes
>> the invader wins by covering distance

> The invader wins by crossing the baseline.

Both are true, but covering distance is a better fitness function because it
is continuous and crossing the baseline is discrete (and not just discrete --
binary). Your strategy can make the difficulty rise more slowly than
otherwise, but it can't make the difficulty plateau or drop.

------
disqard
This is very cool work! I particularly like the idea of a "human in the loop"
as objective function for the GA.

Yes, it's slow and I didn't end up playing more than a few rounds, but the
core idea is a Good One.

Thank you for making and sharing!

------
hellbanner
Cool stuff. Check out Quantum Pilot where the enemies literally mirror your
previously recorded actions. Steam / Android / iOS

~~~
chaoticmass
I tried the game you mentioned. Surprisingly hard!

------
jonathankoren
I played through 70+ generations before I stopped, and it certainly seemed
like they were getting more jiggly as it went on, albeit, very slowly.

It would be nice if there was genome display or something, so you could see
how the population was evolving. Towards the generations that were multiples
of 7, it would look like the population started to converge. So some sort of
display information about that would be interesting.

It would negatively effect gameplay because it would be essentially a cheat
for the human, but it would be an interesting visualization none the less.

~~~
atum47
The design of the InvaderZ is his genome and the way it behaves. It as vector
of size 16 with zeros or ones. If it's a one it draws a "pixel". So you have
to think of it as a 4x4 Matrix ```[ 0,0,1,1, 0,0,1,1, 1,1,1,1, 0,1,1,1 ]```

~~~
jonathankoren
Yeah I get that, but I’d like more insight into the the semantics. Like
“horizontal speed 16”, “move fequency 11” etc.

------
Insanity
Really cool idea! Went to wave 32, had a lot of fun with it actually.

But, knowing the algorithm, I tried to shoot the hard ones first and wait as
long as I could to shoot the easy ones by just letting them descent :)

------
torvald
It would have been interesting to see an evolving agent playing against these
evolving invaders. Cool project!

~~~
atum47
I'm thinking about using a NN I made a while back to play it. =)

------
atum47
I just increased the player's speed, after a lot of requests.

~~~
atum47
the manifest.appcache should take care of the update; but if it don't, clear
the storage and visit victorribeiro.com/invaderz again

------
mywittyname
Suggestion: support 'a' for left and 'd' for right.

~~~
laurent123456
The problem if you use "a" and "d" is that it will only work with qwerty
keyboards. In azerty for instance the equivalent would be "q" and "d".

So for a small demo it's probably better to just use arrows as this will work
everywhere, and there won't be a need to support all keyboard layouts out
there.

~~~
why_only_15
Be real - what percent of people are using azerty, even on HN?

~~~
pluma
Ah, yes, the "fuck internationalisation, we're all living in America anyway"
argument.

EDIT: Data point of 1: I'm German and use a QWERTZ layout because it's a
hassle to type umlauts on QWERTY even with a compose key. If I were French
that'd mean I'd be using AZERTY.

~~~
pierrec
That's not the argument. They just seem to believe that it's a nerdy
alternative layout like Dvorak ("...even on HN"). Not everyone is familiar
with international layouts.

~~~
pluma
I would think the kind of people interested in technical posts on HN should
better be aware of at least the most basic i18n issues.

------
newnewpdro
63 generations later, I didn't get the impression the invaders were getting
any better. Not consistently anyways, they would kind of vascillate between
moving a lot and not much at all.

It's an interesting idea, but I think the implementation needs more tuning.

------
nacs
Live demo here:
[https://victorribeiro.com/invaderz/](https://victorribeiro.com/invaderz/)

I'm finding that I can barely last 7 generations to be able to see it
'evolving'. Handicapping the player by waiting for the previous shot to hit
before firing again _and_ making the move speed ridiculously slow makes this
game too hard even before the genetic algorithm makes an impact.

Also, because the player's move speed is so slow, the easy tactic for the
algorithm to head towards is to simply push each enemy to opposite ends of the
screen -- ie: hug the wall. If you're clearing one side, the player won't be
able to reach the other end of the board even if you move as fast as possible.

TLDR: Interesting concept but to really demo this concept you need to make the
game a little easier for the player / don't handicap so much.

~~~
krisroadruck
I'm confused, I was able to get to generation 9 in my first go and that was
with it taking me 2 rounds before I figured out I could use the keyboard to
move and shoot instead of the mouse...

~~~
atum47
I will put a welcome informing the controls

------
clusmore
This made me think that it'd be interesting to see a variant on Space Invaders
where you play as the invaders - you would write a little program that takes
the state of the world and determines the next move for each invader and play
against an AI cannon. Does anybody know if something like this already exists?

------
dbg31415
Cute, but way too slow to be fun.

------
d0m
What if: \- kill the "hard ones" first \- wait for the easier one to get very
close to atmosphere, and then kill it. \- will the algorithm learn to evolve
toward easy ones?

------
rambojazz
Is there a playable demo?

~~~
cpeterso
Live demo here:
[https://victorribeiro.com/invaderz/](https://victorribeiro.com/invaderz/)

~~~
O_H_E
Not working for me

"victorribeiro.com’s server IP address could not be found"

~~~
atum47
I don't have a server; I pay a hosting service, it's what I can afford right
now, and I called them and asked for more resource, cause it's been receiving
a lot of visitors. Maybe it went down for a moment.

~~~
mikekchar
It's just static data, so you can host it on Github's servers using Github
Pages: [https://pages.github.com/](https://pages.github.com/) Gitlab even goes
one better and allows you a build step if you ever wanted to use webpack,
etc...

------
mhb
Space Evaders?

