Created
April 5, 2013 17:14
-
-
Save rfc1459/5320987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/rfc1459/xmp" | |
| "github.com/rfc1459/xmp/portal" | |
| ) | |
| // Per-resonator attack | |
| func perResAttack(p portal.Portal, x xmp.Xmp) (xmps int) { | |
| orientation := portal.N | |
| angle := portal.AngleMatrix[orientation] | |
| distance := p.MeanResonatorDistance() | |
| xmps = 0 | |
| for { | |
| p.Attack(x, distance, angle) | |
| xmps++ | |
| if p.EnergyAt(orientation) == 0 { | |
| // Switch to next octant | |
| orientation = (orientation + 1) % 8 | |
| angle = portal.AngleMatrix[orientation] | |
| } | |
| if p.Energy() == 0 { | |
| break | |
| } | |
| } | |
| return | |
| } | |
| // Straightforward fixed-point attack | |
| func dumbAttack(p portal.Portal, x xmp.Xmp, distance, angle float64) (xmps int) { | |
| xmps = 0 | |
| for { | |
| p.Attack(x, distance, angle) | |
| xmps++ | |
| if p.Energy() == 0 { | |
| break | |
| } | |
| } | |
| return | |
| } | |
| // Select the best attack profile for the given XMP | |
| func smartAttack(p portal.Portal, x xmp.Xmp) (xmps int) { | |
| lvl := x.Level() | |
| switch { | |
| case lvl <= 5: | |
| // Per resonator-attack profile | |
| xmps = perResAttack(p, x) | |
| case lvl == 6: | |
| // Mid-point attack profile | |
| xmps = dumbAttack(p, x, p.MeanResonatorDistance()/2, 0) | |
| default: | |
| // Full portal attack profile | |
| xmps = dumbAttack(p, x, 0, 0) | |
| } | |
| return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment