Send your feedback or ask for help here!
Nice little challenge, finding a good way to prioritize the ships was interesting.
I’m having a hard time sorting the ships to attack first.
I tried to rank the ships by the more damage they are able to make while being shot at, but it doesn’t take into account the fact that every ship deals damage each turn. Thus, my ship shoots at the most hazardous ship first enven if it would be safer to take down smaller ships first.
I don’t know if that’s because I’m missing something here, but the puzzle seems significantly harder than every other “easy” puzzles to me. Am I the only one to think this way?
I treated it as an Economics problem.
Perhaps not many IT people studied Economics , so explaining it a bit.
There is a Micro-Economics concept, “opportunity cost”. Briefly, because time and resources are limited, if you choose option A, you loose the opportunity to follow option B, or C, or D…
A commonly quoted example is that If you choose to go to college to earn a degree, your opportunity cost could be losing 4 years of working experience plus salaries.
In game playing, if you choose to shoot down a big ship in 4 rounds, you earn the benefits of removing a big threat. You lose the opportunity of shooting down four smaller ships in each of the rounds (removing several smaller threats). You have to evaluate the benefits and its opportunity costs to make a decision.
Forget it if you find it is too hard to digest.
I understand the way to think, but I can’t think of a way to code this nicely…
If I’m dealing with a large ammount of ships, I don’t know how explicitely tell if it’s better to focus on one “big ship” or to take down certain smaller ships. Everytime I start to write something, I end up making tons of comparisons…
|Option A||Remove ¼ threat of a big ship|
|Option B||Remove ½ threat of a medium ship|
|Option C||Remove full threat of a small ship|
“Threat” is a variable different in each case. Choosing A, B, or C - depends on var values in your ship list.
You want to find a metric that gives you a value for each ship, and then sort the ships based on their respective value. The key is to find how to build that metric, but once you have it the rest is trivial.
Thanks to you two for your help! I did not find a solution yet but I’m still trying.
Djoums, that’s what I tried to do by taking into account the ships’ attack and endurance. But I think my model isn’t complex enough and my program often makes the wrong decision.
Constraints say HP, ARMOR, DAMAGE are >0. That is not the case.
Say you must choose between target A and B.
Let’s call T the number of turns to kill a target and D the damage a target deals each turn.
If you kill A before B:
You take a total of TA×DA +(TA+TB)×DB damage.
If you kill B before A:
You take a total of TB×DB +(TA+TB)×DA damage.
So which target do you choose?
An important part of the metric is how many turns it takes to kill a ship.
Because the more damage per turn a ship deals, the more you want to prioritize it. But the more turns it takes to kill it, the less interesting it becomes.
Yup I understand on which elements the comparison must be focused, but the issue is that there might be a lot of ships to compare, thus I can’t use the other ships in the comparison formula (because I’m affraid of doing tons and tons of comparisons).
I guess I’ll eventually find a way to achieve 100%, I’m stuck at 75% atm, I’m having troubles with the swarm and close call!
EDIT: I got to 100%, but I don’t think I got there in a very elegant way!
You don’t have to compare each pair of targets, you can just set the best target to be the first one, then iterate over the targets and update the best one if you find better.
And you do that at every turn.
A more efficient way would be to sort all targets from the beginning with a custom comparison function/key.
I noticed multiple strategies being discussed, so let me just leave this here:
There exists a purely mathematical solution to prioritising which ship to damage first. So instead of playing about with weights for the 2 factors (time to kill and health points), you could try deriving this formula. It’s a very simple factor, and playing around with 3 or 4 ships should make it evident.
I managed to do this by giving each ship a score. The score is proportional to the damage of the ship and the turns required to kill it. The higher the turns the lower the score is.
Well if you look at my previous formula, you notice that it all comes to checking if TA * DB < TB * DA which is equivalent to TA / DA < TB / DB.
From this, the sorting key becomes obvious.
How can I get the solution to this puzzle?
This is quite often a dilemma in many games: “Do I kill the strong or the weak units first?”
As it turns (no pun intended) out it’s not that simple. (Although this is quite often a solution you see implemented with weak AI bots, even in AAA games.)
A good comparison function for pairs of targets is to compare targets by the total damage you take if you chose to attack the other unit. Meaning, you need to see what is worse for you: if you focus on enemy A and let enemy B attack you until you’ve killed A or if you focus on enemy B and let enemy A attack you while you deal with B.
This way you deal with targets in optimal way (HP-wise).
This is only one of the ideas you could use to solve this puzzle.
I am new to CodinGame, and was wondering how I can go about seeing the solutions. I have tried everything I can think of to solve it - and I would like to learn how to fix these kind of problems. I am happy to forfeit my ability to ‘solve’ the puzzle in order to learn
AFAIK that’s not a feature on coding game, you can only see others solutions once you’ve passed the validators.