User:PEZ

From Robowiki
(Redirected from PEZ)
Jump to navigation Jump to search

I'm an ancient Robocoder. Not active at the moment and my bots are aging. But I like to think some of them has inspired new generations of bots. The bot I spent the most time with was CassiusClay.

Last version

I found a need to clean out old versions of bots in my robots directory. I did it by copying all the latest version away to a new directory. If you are on a unix machine you might find this useful:

ls -1 | awk '{ split($0, a, "_"); bots[a[1]]=(a[1]"_"a[2])} END { for (bot in bots) print bots[bot] }' | xargs -I {} cp -v {} /tmp/robots

(Didn't know where to put this...) -- PEZ 18:42, 2 November 2011 (UTC)

Spring cleaning

My wife got me to clean out a lot of old stuff today. Found a lot of traces from my Robocoding days. This for instance:

Spring cleaning at PEZs.jpg

Looks like I was thinking about how to approach the Melee problem. =)

A friend chat about robocode today, so it bring me here, i remember you PEZ, haha, the old robocoding days. --iiley

Bullet Power Rocket Surgery

This is copied from old robowiki. Seems like people rediscover this lesson now and then. =)

The optimal fire power is about 1.72 something I think. -- PEZ

Is that optimal for like, how to put out energy the fastest? I am really clueless when it comes to deciding firepower. I'll go read up more on deciding firepower and see what I can come up with... -- Vuen

=) I am pretty clueless myself. Some month ago I started to figure about it and draw some curves on bullet damage in relation to max escape angle. This is the graph:

Optimizing Bullet Power.png

It suggests that after 1.72 something you start to get harder to hit the enemy in relation to how much you can gain on hitting it. I think. What's your thoughts on the graphs story? -- PEZ

Well, my thoughts are that your graph assumes a movement that's Flat with Flat juice on top no matter how you split it up. What if your targeting algorithm is more likely than just random to hit? -- Kawigi

I totally agree with Kawigi. Besides, there is whole 'game theory' related issue. What would change if survival bonus was 200? Or damage bonus 45% instead of 20% ? When to start endgame and limit your shooting power even more? When to delay shooting to conserve power? Your solution is 'one fits all', probably good against flat movement and game where bots start with 10000 power. -- Frakir

I don't quite follow. What if my algorithm is better than just random? I haven't proposed a solution. (Unless you count the not-so-seriously-intended "optimal fore power 1.72. =) I just want to hear what you think is the conclusions one could draw from the graph's story, The graph does not assume anything really. It's just probabilities I guess. Selecting fire power is tricky. You need payback on power consumed, right? Let's say you start out with 1.7 while you don't know anything about your enemy's movement. And then you can adjust this if you find out you can get payback enough with another power level in certain segments. I'm just brainstorming here. -- PEZ

What might be more significant here is figuring out what your actual chances are of hitting at the current distance in the current direction at the chosen bearing, and see if such a graph would show a different optimal value for you in that specific situation. After that, the only thing you have to worry about is if the answer is not time efficient, which I suspect is a minor issue, particularly if your movement is remotely good. -- Kawigi

But such a graph could be expressed as a deviation from the general graph above, right? In Marshmallow I have the kind of stats you suggest I think (rating the VirtualGuns). How would I deduce from that what bullet power I should choose? I don't understand the part about time efficency. Can you elaborate some? -- PEZ

I think you could use VG stats for this, or it may make sense to keep more detailed stats (or more segmented stats) than you use to choose VG's. The way to deduce bullet power is to figure out at what power the greatest margin of benefit is. For example, if you have probability of hitting with a certain power is p, the margin of benefit of firing at that power (assuming a 1-on-1 battle) is (your gain in energy + their loss in energy-power)*p-power*(1-p). Basically, the potential "net gain" from hitting times the probability of hitting minus the potential loss times the probability of missing.

The time efficiency I was referring to is maybe some lower power is more beneficial by this definition, but a higher power would still be almost as good, and if you always fire at a lower power, your opponent may win because they just finish killing you faster by using higher-powered bullets. -- Kawigi

I knew this would quickly become rocket science. One size fits all isn't too bad I think. At least as long as you haven't collected enough data to apply the brain surgery on. Quite often before the advice for people who don't want to introduce complexety here has been to shoot with power 3 here. Just maybe it is better to shot, say, 2.2 instead? -- PEZ

Maybe. The main disadvantage of the method that I discribed above is that it may require too many additional calculations to be worth it. The idea, though, is basically like the idea of DynamicDistancing in concept, and is also based on the idea of how much energy advantage you would lose or gain if you fired a certain power 100 times in this same situation. -- Kawigi

The thing I don't get is, how do you figure out what firepower to shoot AFTER selecting the graph segment you're deciding on? Choosing a different firepower based on the graph you find varies the bullet travel time, which varies the segment, so your graph is useless. The only way seems to be pulling off a graph in each segment of bullet travel time, calculating the chances and gains based on firepower for each and every graph, and then comparing them from there. Just seems like a LOT of work, and that usually ends up badly for my robots anyway; besides, in this case you'd be better off segmenting on power and distance rather than flight time. I created a simple firepower selection algorithm in Fractal, and it seems to improve its performance, but I'm sure as soon as I upload it it'l turn to crap. I'm tempted to write a quick firepower optimizer that bases itself on a Flat curve with Flat juice on top; that or I'll change my bullet flight time back to straight distance and just segment on firepower instead, and just compare all the segments of firepower instead of flight time. I'll see what happens. -- Vuen

Interesting to hear such words from MrRocketScientist himself! =) I fully agree that complexety usually means bugs. -- PEZ

Yeah, Vuen, that's what has prevented me from doing choosing firepower based on the segment when I'm segmenting on bullet travel time. Of course, a study needs to be done on the value of using that vs. using distance I think... -- Kawigi

There are two cases: trying to maximize energy gain or trying to get as much score for damage as possible. Let's say you have a function to calculate hit posibility with certain firepower. p - probability to hit (0<=p<=1). Probability to miss is 1-p. 1) If you hit: enemy loses Damage, you gain power_returned-firepower. If you do not hit: you gain -firepower. To sum up: F = p*(Damage+power_returned-firepower) - (1-p)*firepower. 2) If you hit: you get score Damage, and you lose firepower energy, so maximum opponent damage is reduced by firepower, you get +firepower score difference. If you miss: you lose firepower energy, +firepower score diference. F = p*(Damage+firepower) + (1-p)*firepower. You may chose one of these strategies depending on robots' energy. If there is a huge energy difference, it is unworthy to try to win, and so on. It is possible to combine both methods. pWin(myEnergy, opponentEnergy) returns the probability of winning the round using robots' energy. You may use some kind of statistics or anything you can think of. If you hit: you get 120*pWin(my_e+power_returned-firepower, opp_e-Damage) on average (50 for survivor, 10 for the last survivor. You get 60 or opponent gets 60, that makes the difference 120), and you get Damage+firepower score difference for damage (see case 2). If you miss: 120*pWin(my_e-firepower, opp_e) + firepower. F = p*(120*pWin(my_e+power_returned-firepower, opp_e-Damage)+Damage+firepower) + (1-p)*(120*pWin(my_e-firepower, opp_e)+firepower). Maybe you can simplify a little: F = 120*pWin(my_e, opp_e) + <score difference for damage>, but I don't know how much accuracy you may lose (probably not much). You need to maximize F. Possible solution could be calculate all firepower values with certain step (for example, calculate F with firepower 0.1, 0.2, 0.3, ... , 2.9, 3.0). asm

After PEZ's successful experiment with an always-fire-2.4 strategy, I've been playing around with various bullet power strategies and looking at what ought to be optimal, from a theoretical point of view. There are some surprising results....

To maximize bullet damage; the formula for bullet damage per unit time should be (1/Math.ceil(10 + power/.5))*p*(6*power - 2) for 3 >= power > 1, where p is the probability of hitting the opponent. Of course p is not independent of bullet power. However, if we assume that the opponent's movement profile is no better at any one range or bullet power than any other, then p is proportional to atan(18/enemyDistance)/Math.asin(8/(20 - 3*power)) - that is, the angular bot width over the escape area. This assumption will probably be false for a given opponent, but true when averaged over the general population - people tune for a variety of bullet powers.

I ran this equation through a program to find it's value for a given range. The maximum lies at one bullet power for all ranges; that bullet power is... 2.5. A bullet power of 2.5 gives you both a smaller escape angle and faster gun cooling than 3.0, and they balance the slightly higher damage. There are local maxima at both 3 and 2. Interestingly the theoretical difference between the maximum bullet damage and the damage at 2 is always < 7%.

Always-fire-2 seems like a crazy strategy, so I ran some tests against VertiLeach; one with Raiko always firing power 3, one power 2.49 and one power 1.99. Each was over 250 rounds. In each case Raiko's bullet damage was the same to within < 4%, wich is probably margin-of-error; it was actually highest at 1.99. This is at very close range, almost always less than 300.

Interestingly the score was also almost exactly the same, even though survival went up at lower bullet powers. Why? Because Verti's bullet damage also went up... obviously, if I run out of energy faster, then the opponent has less chance to score bullet damage points, which balances the extra survival score.

Conclusion: you can fire pretty much whatever bullet power you like, but 2 isn't a bad number at any range other than point-blank. -- Jamougha

If you are referring to Aristocles 0.3.0 as my "experiment" I must just make clear that it is not the first time I try with "only power 2.X" where X is on the low half towards 3. Griffon does this too. I think it is firing only power 2.2. I have never really figured out why it works so well. As you can see above my only theoretical approach to this problem has lead me to propose maybe the optimum fire power is 1.7 or there about. But you don't see any of my bot fire that low powered bullets. Thanks for sharing your theory and your empirical findings. This gives me some rest in trying to figure this out. "It doesn't really matter much" is the lesson I should have learnt from all my experimentation. But I have been too stubborn and too thick headed to grasp it. Now to a question. The way Tityus gun works is to use a fixed bullet power at each distance index in its segmentation. This to avoid segmenting on bullet power. You know this I see since you have kept this property of the gun. But, if it doesn't matter much what bullet power you use at given distances. Is it worth while to lower your bullet power with distance like Tityus and its descendants do? -- PEZ

Good question... inside a bullet travel time of about 5 it should be possible to write a linear prediction gun with near 100% hit rate, since the opponent just cant change direction or velocity quickly enough. Here it's better to fire power 3, if you have written such a gun... but I haven't, yet. :-) Still, with long learning times firing 3 inside distance 100 is probably a good idea. At very long ranges it might also be worthwhile to fire lower power, so as to increase survival. However between 100 and ~600 I'm pretty certain than constant firepower is just fine, and since 2.5 and 2 are generally 'good' values for bullet damage I'm inclined to pick one and stick to it. Especially in a microbot, where it's saving me enough codesize to introduce wall segmentation and finally thrash Sedan. ;-) - Jamougha


OK. Can't someone just say the words: "it seems like there's some merit to your theory about maximizing the damage / escape_angle ratio PEZ"? =) -- PEZ

It seems like there's some merit to your theory about maximizing the damage / escape_angle ratio, PEZ. I know I've started using 1.9 in Cyanide. -- Alcatraz

Thanks! It took many months for someone to give me those words. And some begging. =) -- PEZ

Well, i already said "Thanks, PEZ!!", but since i really think that it was brilliant there it goes: it seems like there's some merit to your theory about maximizing the damage / escape_angle ratio PEZ! -- Axe

I think the graph is misleading, but I did do quite a bit of tinkering in Excel to find what I think should be a magic number. I did factor in damage, escape angle, and some other stuff. I have plans to factor in some dynamic information as well, but a fixed number will do for now. Previously I was iterating through several firepowers and comparing the damage potential to my historical hit percentages at that range. I'm going to redesign my virtual guns statistics so it is time to revamp my firepower selection, which should speed up my bot quite a bit as well. -- Martin / Ugluk

How do you find out the specific probability for a firepower (to use the formula on top)? --Starrynte

Is it p = atan(18/enemyDistance)/Math.asin(8/(20 - 3*power));?

Do you mean the probability that it will hit the enemy at a certain distance with a certain fire power? If so, I think that would be (approximately) (18 / distance) / Math.asin(8 / bulletVelocity(firepower)), which is the angle that half a bot takes up at a certain distance divided by the angle they could move in one direction (at any distance). Bullet velocity is (20 - 3 * power). -- Voidious