Code vs Zombies - Feedback & Strategies

Hi ,
I do not understand how you get the codingame ide to simulate each loop.
Did I missed a codingame functionality ??


It is not a functionality; you have to write your own simulation code.

maybe just a bug, not working for me too :slight_smile:


When I run a simulation it always fails on rectangle and cross, because there are too many opportunities to kill Zombies in front of him and Ash forgets about the humans to save.

I wonder how I circumvent this.

EDIT: I made a manual check. I don’t start the simulation if all humans are targeted and I’m more than 3000 units away. I’m now at 6680 points.

It’s likely that you don’t have enough simulation to find your best options. The easiest way would be to hard code some initial moves on this particular test cases. Otherwise you need to find a way to get more sim per turn (depending on the language it could be more or less hard)

1 Like

Thank you, yes I’m using Javascript. I assume it’s not the best language. However I’ve seen people up there with 700k points.

I have now a deterministic solution when all humans are targeted and I’m more than 3k units away.

It fails sometimes, but that’s how I got the record. I’m trying to improve my sim now.

Also note that in case of js solutions that are the top of the leaderboard, it might be the result of offline training and hardcoded solutions against the submission validators. So it might be normal that in js you have a hard time reaching 700k (personally in c++ I only manage 400k but maybe my algo/sim sucks)

1 Like

I’m now at 93k with a deterministic approach when my distance to closest Human is >3000 and a sim else.

I just do 3 random moves and pick the first move of the best strategy. I’ve read in the post mortem that that @eldidou is killing all Zombies in random order, which I haven’t tried.

But he’s saying he’s doing 1 million strategies. I performance Checked mine, and it’s more like 3k. I could probably get out a bit more with some precalculations, but I think JS is just not the language for that. One day I’ll pick up another language for that.

What’s the best language for these kind of games here?

A couple of optimization I’ve done already

  • Not calculating root when comparing distances
  • Pre-calculating fibonacci
  • for loops instead of array methods
  • various loop improvements

There are a couple more, but the wins seem really nuanced and the result is anyway variance of the submit. Probably I’m not at the JS limit, but not too far either.

Yep likely your issue comes from the fact that js is slow and your sim is not deep enough. Popular languages for high performance on CG could be C++, Rust and C.
For instance in C++ I have an 18-gene (plays 18 moves which is often the number of moves needed to end the game) “Genetic algorithm” (I only apply mutations on a unique chromosome) and on big maps (with a lot of human/zombies) I would simulate about 90k mutations of the chromosome on the first turn (so 18 * 90k Ashe’s moves in total)
Another thing you can try is to keep the best strategy you computed on the previous turn just in case you rng is not as good on the following one, this way you are guaranteed a minimum score instead of randomly trying something else (but the small depth of 3 moves ahead might be a blocker since you won’t be able to spot great future combos).

1 Like

holy shit. Yeah that’s quite a difference. I might try Rust.

btw: I’m not sure if it’s a bug or not, but when I try to follow Zombies after simulation 1, Ash starts hiding behind the humans and I get terrible results. I don’t know why.

EDIT : 114k



Now I learnt Rust and completely recoded my solution in Rust, just to realize that CG compiles rust in debug mode and not optimized, which makes it even slower than JS…

Nvm. I learned some new stuff definitely

Oups. I thought that at some point rust was in release mode in the arena and debug in ide (I assumed it was the same for optimisation games due to the high rankings of dbdr and mikmak in optimization puzzles, unless they are hard coding).
Also according to post here: Languages update - #98 by _CG_Thibaud it’s now compiled with release libs all the time.

1 Like

Oh I didn’t submit because the results were too bad and I checked the rust forum and there were was no message that Rust was updated.

I’m gonna give it another try, but have to do some extra maintenance work.

Thanks for all your help.

I’ve just moved this thread to the Rust category. You may take a look.

1 Like

Thank you. The community here is amazing!

I also checked the number of simulations and I can see that I can do way more with Rust now. Currently fighting some inaccuracies/bugs. Curious if I’ll be able to beat my JS score today.



125k > 114k.

I probably have some more room for improvement here. Learning Rust teaches me a lot about coding in general. Coming from Javascript I don’t really have a functional background.

It seems like it’s important to have memory as clean as possible and drop everything not needed, is that correct? It is so tough to find proper guidelines for that online.

I don’t know much about Rust, but on Google search I’ve found this: Maybe it’ll be useful to you?

Thank you! This is definitely useful. Currently busy, but will work on it later.

I think I’m coming to an end with this puzzle for the next time and work on other stuff.

I’ve learnt quite a bit about Rust and performance optimization in general, but I’ve spent the last 2 days optimizing without any improvements. A lot of marginal wins, but I don’t yet have enough skills to optimize Rust code and the benchmarks are very variable, since there is obv RNG involved. Even if I track them it’s tough for me to see which ways of coding are the better and which give me more simulations. Even if I achieve more simulations it’s not guaranteed that I’m gonna find those super high point combos.

From what I learnt Rust is memory safe and typed which can be tough to performance optimize. I think my learning curve for now will be higher on other things. And I should probably restructure my whole code once I’ve learned more about rust or I can write my own simulations.

There is definitely more room for improvement. But it’s a problem for another day.

1 Like

On the optimisation problems, would it be possible to put the total score on the “Play All Tests” button, if we pass all tests, the same as you do for each individual button. This way I won’t need to guess if I have an improvement, I will get the actual number