https://www.codingame.com/training/easy/target-firing
Send your feedback or ask for help here!
Created by @UnicornP,validated by @anon79121980,@VirtualAtom and @ludowsky.
If you have any issues, feel free to ping them.
https://www.codingame.com/training/easy/target-firing
Send your feedback or ask for help here!
Created by @UnicornP,validated by @anon79121980,@VirtualAtom and @ludowsky.
If you have any issues, feel free to ping them.
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âŚ
options | benefits |
---|---|
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.
Good Luck
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.
Hi all,
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
Thanks
AFAIK thatâs not a feature on coding game, you can only see others solutions once youâve passed the validators.