Code VS Zombies - Optimization - Puzzle discussion

Is the code source for the game referee available somewhere?
I think I have an issue with floating points precision.

If you take a look at the following replay: Coding Games and Programming Challenges to Code Better you can see that, at turn 13, my AI says "13,457 178,300 1" meaning it found a move sequence achieving 178,300 points. It never finds anything better and thus executes the sequence until the end.

Despite this, it ends up scoring only 110k. This is quite difficult to debug and the “Horde” test case is the most obvious one.

This specific replay is using double but I’ve also tried with float and got the same kind of errors. (I’m using C++)

If anyone experienced the same kind of issue, I would be glad to know what I can do to try and fix it.

EDIT: I managed to solve my issue, it had nothing to do with floating-point precision, it was a typical human-made mistake!

Knowing some Pythagoras will help you.
Also functions like atan2, cos and sin.

Hi, actually uses Pythagoras.

You know were Ash must go (x2,y2) and his starting point (x1,y1)
You could compute hypotenuse as square root((x2-x1)(x2-x1)+(y2-y1)(y2-y1))
and use it to compute x3,y3 with his dmax (1000 here)

x3 = x1 + dMax * ((x2-x1)/hypotenuse)
y3 = y1 + dMax * ((y2-y1)/hypotenuse)

in python :
hypotenuse = lambda x1,y1,x2,y2 : math.sqrt((x2-x1)**2+(y2-y1)2)
nextpoint = lambda x1,y1,x2,y2,d : (int(d
(x2-x1)/hypotenuse (x1,y1,x2,y2)+x1),int(d
(y2-y1)/hypotenuse (x1,y1,x2,y2)+y1))

2 Likes

I need to know what is special about the “Split-second reflex” test set. My code fails but I don’t know why. Does anyone know its particularity?
Thx

Hi :slight_smile:
I’ve managed to simulate the game locally and I can also visualize it. Now I want to implement my GA but I’m having trouble to implement Crossover and Mutation. My DNA is a sequence of Direction Vectors from Ash’s Position along with a magnitude ranging from 0 (Ash stands still for this turn) to 1000 (Ash moves at max speed). I calculate the score for all those game states at the end and now I want to Crossover 2 Games that did reach a good score. But how? Lets say Gamestate A finished the game in 30 turns and B in 40. I have no clue how to do the Crossover with DNA squences that have a different length. And even if I figure it out
the result is likely to produce a non-finished game state. So the DNA squence from the result of the Crossover with A and B could be more or less than 30 or 40 turns. Can someone help my out with a hint?

Would this be working for you: always have a fixed amount of genes (say 40) during crossover, while ignoring any extra genes during simulation? e.g. in one simulation, the game ends in 30 turns, so ignore the extra 10 genes; in another simulation, all the genes are considered because the game ends in 40 turns.

3 Likes

Thanks for your quick reply :slight_smile:
Yeah I’ve also thought about that but I’ve produced a lot of unfinished gamestates. I found that bug while visualizing it and saw that Ash stopped moving due his movement queue was out of moves while there were still Humans and Zombies left. My GA could “decide” to kite the zombies a long time to get them all on one spot to make the highest score but eventually it takes only 15 Turns to win or lose. I can try to check the crossover result if its finished when doing all those moves and if not
 I dont know
 maybe fill it with some random moves until its over? But I doubt this GA can converge
 But I can give that a try

1 Like

Abit weird all you have do is print(human_x,human_y)
boom 95% complete and 30,000 score (although its rly bad lol)
any tips?

1 Like

You may read the external resources on the game’s main page to get some ideas for improving your code :wink:

2 Likes

there arent many though :frowning:
( at least i think so
)

The fibonacci sequence starts with 0, 1, 1, 2, 3, 5, 8
, not 1, 2, 3, 5, 8

Might want to clear this up in the rules description.

Hello,

I discovered GA a few days ago and I am trying to implement one for this problem. I managed to get some results offline (like achieving the max score for the combo opportunity test) but my algo takes too much time.

Basically at generation 0, I defined my genomes/individuals as an array of random x,y moves. Then I’m passing those genomes into my fitness function, which is a simulation of a complete game and returns a final score game. Finally I proceed with the selection / crossover / mutation sequence.

After trying this, I realized that I am having it wrong right from the start. Simulating a whole game for each genome is taking too much time, and generating an array of random coordinates for a complete game is still way too random as all of my generation 0 genomes frequently returns a score of 0, even if I have a 200 or 300 population size.

So what do you mean by “you must have simulation for turns ahead” ? A fitness function simulating a complete game doesn’t seem to work for me. Do I need to predict the state of the game for only one turn in the future with a fitness function returning something other than the general score ? And repeating this GA each turn ?

Thanks in advance for your answer :slight_smile:

Hi,

Simulating a whole game shouldn’t take too much time, it’s a linear for loop with 200-300 iterations, updating character positions on each, if you could profile you simulation, see if you have unnecessary memory allocations or copying of big data structures also the language you’re using could affect the performance.
You could simulate the game not until the end but you must come up with very good evaluation function on not finished game, which is very tricky.

The idea of the complete random first population is to give you good distribution over the search space.

Hope this helps.
Cheers

2 Likes

Bonjour.
Je commence ce puzzle en PHP, mais je reçois systĂ©matiquement un “Timeout: the program did not provide 1 input lines in due time
”.
J’ai exĂ©cutĂ© un “microtime()” en dĂ©but de boucle et en fin de boucle Je comprends que chaque boucle dĂ©passe dĂ©jĂ  les 400 ms d’exĂ©cution - et sans avoir mis de code ! - alors que votre contrĂŽle requiert un temps infĂ©rieur Ă  150 ms.
Vous pouvez voir ma capture d’écran ici :
https://drive.google.com/file/d/1sTM8Sks0jk72C2Q1uKfHJeyCD1YO2N9_/view?usp=sharing
Merci pour votre aide !

Sans voir ton code, c’est difficile de dire ce qui ne va pas. DĂ©jĂ , pour ĂȘtre correcte, la mesure de temps doit dĂ©marrer aprĂšs la lecture du premier input.

1 Like

J’ai rĂ©solu mon problĂšme : il me manquait le caractĂšre “\n” en fin de ligne de la sortie-rĂ©ponse.
Merci pour la prĂ©cision d’oĂč prendre le mesure du temps initial pour l’optimisation.

1 Like

Alright, I will try to check the efficiency of my code. I am also using an interpreted language so it might be a part of the problem as well. But even if my code is too slow for the game, it is still very satisfying to get some very good scores offline with this first GA, as I am relatively new to programming.

So thanks a lot for your very useful posts regarding GA, it helped me a lot! :slight_smile:

2 Likes

Same experience. YNext XNext is not actually the next coordinate of the zombie. instead, I think it is the target coordinate. so every game loop, the value will always be the same for that zombie until the first target is killed. But then, YNext value is weird.

Please print the variables to the errors stream and share both the replay link and the console error output here if you find them wrong.

I have just checked one test and in my case I find that they are indeed the next coordinates of the zombies.

Hello Everybody,

I am struggle on the “reflex” case. all other ok for the moment. so i work in Python 3 with “table” base on dict for Zombies and Humans in fill it first.
then i check the distance variation and movement ratio between Ash/zombies/Humans for determine save and loss.
only on reflex during debug i found third data input instead of 2. two had Id 1 but with different move ratio and specially one of the Zombie id 1 looks wrong regarding positionnal on debug interface + move ratio found in write debug.
could someone help me where i am wrong ? or someone already notice that issue ?