Add curated legacy Robocode roster (28 bots) and Tank Royale booter
Curated roster: 34 classic-Robocode archives were downloaded, measured in real
Tank Royale battles and curated to 28 usable bots, now in legacy_bots/<Name>/
(<Name>.jar + <Name>.json + <Name>.sh) with checksums in MANIFEST.sha256.
Six were dropped as NOT_USEFUL and deleted from tr_bots/_salvage/legacy_bots/
and tr_bots/_salvage/tr_wrappers/, with the rationale recorded in
legacy_bots/README.md and tools/robocode_shim/LEGACY_BOTS.md:
- Nene, Seraphim - Azuma-framework melee bots, completely inert (0 scans,
0 shots); getRobotRunnable() returns null so the shim has
no driver path for them.
- Aurora - fires 6 shots and crawls.
- FloodMini, LightningBug, Aristocles - near-stationary turrets: they scan and
fire but land 0 hits and take 10+ hits every round.
DrussGT is the reference bot and is deliberately NOT in legacy_bots/: it lives in
tr_bots/DrussGT and is now vendored with its sources under
tools/robocode_shim/vendor/drussgt/.
Repo-relative paths replace /tmp: every <Name>.sh resolves the shim and the
vendor jars via $REPO (../..), and none hardcodes a server URL, a /tmp data
path, or anything under ~/Downloads. SERVER_URL/SERVER_SECRET come from the
environment, which the booter populates from its own -Dserver.url /
-Dsystem.secret system properties.
Booter: tools/booter/robocode-tankroyale-booter-0.35.5-all.jar, copied from a
local tank-royale build, plus a README covering the real CLI. Note the command
is `boot`; the upstream README's `run` is stale. Verified it discovers all 28
kept bots via both `dir` and `info`.
Licensing: every third-party jar here reads "not stated in jar", and DrussGT is
GPL. The repo owner has explicitly waived this - the repository is PRIVATE and
lives on their own LAN. Do not mirror or redistribute without revisiting that.
.gitignore flipped back to tracking legacy_bots/**/*.jar; an over-broad *.jar
rule already cost us the only copy of DrussGT.jar once.
This commit is contained in:
BIN
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
11b65c349e820c93d5f893c63c96b053e72e621041e1f5630c761a35a3cec092 src/jk/math/FastTrig.java
|
||||
ad400156bb011f340d1d9a1f1bd22d5928c0e3861cb910b4a05fe1c9607223f7 src/jk/mega/BufferManager.java
|
||||
325976eeb168e4c4b3e14e5dfc4cb4175a613dd0071d426aaaa9be38aad55626 src/jk/mega/BulletPowerPredictor.java
|
||||
eab6c649ab0dc5690830e53118d77b68cc8e48453f24a723d33a4e6524ec0372 src/jk/mega/DataToGun.java
|
||||
3bce4e894140a4b78cbb391ee4bdc73fd35f0683665ecee586bceeb597ba190e src/jk/mega/dGun/DrussGunDC.java
|
||||
49d987a9e2e7b06eb3882ccdfa3181d4fe0e12c71383a1a74340c3d598a95572 src/jk/mega/dGun/GFRange.java
|
||||
fc15ac5b0e1f1babbf217f7e879ec8f4b2ca5753d5907fce353f5a84da1c6c94 src/jk/mega/dGun/Indice.java
|
||||
3bcb6b78937ad2cf091ecb1b23c18bf868df9ec12b53a7afe134e8525e703617 src/jk/mega/dGun/PreciseMinMaxGFs.java
|
||||
13134d7a94ffaf879ff3fc611c1ba7ec3b200a50851cf4198faae675f8b68f35 src/jk/mega/dMove/BulletTracker.java
|
||||
df3720d46bf6af184e441580b1856f5001f1c40549c463fa2ebf976e0dbbaef7 src/jk/mega/dMove/DrussMoveGT.java
|
||||
0199f53106ae375f5f49c9ba2ec087d17fad69c845be8912e8ecbc8caeccd169 src/jk/mega/dMove/EnemyWave.java
|
||||
b20f9676d6dd42edc149ece3b8f16fb404ed7a1d6f4998b61b98abc09a599f5d src/jk/mega/dMove/MovePredictor.java
|
||||
c984e53b0b27e40bcd3f93dd1725948415b15fa5038cc10d68737eb4e664d259 src/jk/mega/dMove/PlaceTime.java
|
||||
35710e70c77866b999c64ef99bedba0434e0a3fcd5ef5ad4d962146127680ad3 src/jk/mega/dMove/PredictionStatus.java
|
||||
625e6dc21832f989d2b72eba12727afbc80692ad9b9ebaeb12914a5ea7277fd8 src/jk/mega/DrussGT.java
|
||||
1f5bd8d4a795d998d12703eb80ac400889cb07658beb7018105151873d266819 src/jk/mega/DrussGT.properties
|
||||
680e6c1dbe1223f5a46ffcc30c00256814d9f93ec3e08f862f6ff3be057800e6 src/jk/mega/EnemyMoves.java
|
||||
b282982dcfa3538791330552296ec0f5a8feb76cae8f1536b8153dd29ffdc2aa src/jk/mega/Insulter.java
|
||||
8639bde1d0a981a3cc5b2753947ad7f3ea44134089659f1e78feb01e6794074d src/jk/melee/MeleeRadar.java
|
||||
343468158365df1374f96a48e3022612f3db9166579124595d696262d86f24a8 src/jk/precise/EnergyDomeWorker.java
|
||||
e2dac75359c776801f27b9c8df9ec31989d57ada3ae854ae0f1e3576329cd9bf src/jk/precise/util/PreciseUtils.java
|
||||
a88ccec73415e0dd3d47acaab423688038d226e1909b90ca5a9d852f2939a800 src/jk/precise/util/PreciseWave.java
|
||||
9ad7811c7163d8557ab3c5d8c71dd3b46a5888f1a848c1578177c17003ffcccf src/jk/tree/KDTree.java
|
||||
ba9672a543bbda3f8ed419bb51a59aab764d975e67e232cecd256658b2d1cab0 src/META-INF/MANIFEST.MF
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
# DrussGT — vendored decompiled source
|
||||
|
||||
## What this is
|
||||
|
||||
`src/` is **DECOMPILED Java source**, recovered by a Java decompiler (CFR/Procyon-class
|
||||
output) from the compiled `DrussGT.jar` competitive Robocode bot by "jk" (DrussGT 2.0,
|
||||
the Dr. Bloodmoney/G2000 lineage).
|
||||
|
||||
**It is NOT the original author's source.** No debug symbols, comments, or original
|
||||
method names survive; identifiers are decompiler-reconstructed and may be renamed,
|
||||
reordered, or inlined. Do not treat it as a reference implementation for style, and do
|
||||
not "fix up" it as if it were authored code.
|
||||
|
||||
## Where it came from
|
||||
|
||||
- Recovered into `/tmp/drussgt/src/` (also present byte-identically as
|
||||
`/tmp/portaudit/src/` and `/tmp/DrussGT_extracted/`; a near-copy with one patched
|
||||
file lives at `/tmp/dbg_src/`).
|
||||
- Copied into this repo at `tools/robocode_shim/vendor/drussgt/src/` so that a rebuild
|
||||
never depends on `/tmp`, which is wiped on reboot.
|
||||
- `MANIFEST.sha256` records the exact contents; verify with
|
||||
`sha256sum -c MANIFEST.sha256` from this directory.
|
||||
|
||||
`src/` contains 67 files: **22 `.java`** files plus the decompiler-emitted `.class`
|
||||
files that were left alongside them. The `.class` files are gitignored (root
|
||||
`.gitignore` rule `*.class`) and are *not* the build input — `DrussGT.jar` supplies
|
||||
them.
|
||||
|
||||
## Packages contained
|
||||
|
||||
| Package | Files |
|
||||
|---|---|
|
||||
| `jk.mega` | `DrussGT.java` (main bot), `BulletPowerPredictor`, `DataToGun`, `BufferManager`, `EnemyMoves`, `Insulter` |
|
||||
| `jk.mega.dGun` | `DrussGunDC`, `GFRange`, `Indice`, `PreciseMinMaxGFs` |
|
||||
| `jk.mega.dMove` | `DrussMoveGT`, `MovePredictor`, `BulletTracker`, `EnemyWave`, `PlaceTime`, `PredictionStatus` |
|
||||
| `jk.melee` | `MeleeRadar` |
|
||||
| `jk.precise` + `jk.precise.util` | `EnergyDomeWorker`, `PreciseUtils`, `PreciseWave` |
|
||||
| `jk.tree` | `KDTree` |
|
||||
| `jk.math` | `FastTrig` |
|
||||
|
||||
## Provenance and licensing caveat
|
||||
|
||||
DrussGT is third-party, GPL-licensed competitive-bot code by an external author. It is
|
||||
vendored here **for interoperability/port analysis only**. The upstream
|
||||
`DrussGT.jar` itself is deliberately *not* committed to this repo (see
|
||||
`tools/robocode_shim/.gitignore`, rule `*.jar`) — it must be obtained separately from
|
||||
the upstream distribution and passed via the `DRUSSGT_JAR` environment variable.
|
||||
|
||||
Redistributing this decompiled source, like the original, carries the same GPL
|
||||
obligation as the upstream bot. Check the upstream terms before publishing anything
|
||||
derived from it.
|
||||
|
||||
## Relationship to `DrussGT.jar` and `compile_drussgt.sh`
|
||||
|
||||
`compile_drussgt.sh` rebuilds DrussGT from these sources against the genuine
|
||||
Robocode API. Its defaults are all in-repo:
|
||||
|
||||
- `ROBOCODE_JAR` -> `vendor/robocode.jar`
|
||||
- `DRUSSGT_SRC` -> `vendor/drussgt/src` (this directory's `src/`)
|
||||
- `DRUSSGT_JAR` -> `vendor/drussgt/DrussGT.jar` (must exist locally; not tracked)
|
||||
- output -> `out/drussgt/`
|
||||
|
||||
Two files are deliberately excluded from the javac invocation: `jk/mega/dGun/GFRange.java`
|
||||
and `jk/mega/dGun/Indice.java`. The same two classes are also declared inline at the
|
||||
bottom of `DrussGunDC.java`, so compiling all 22 files fails with `duplicate class`.
|
||||
The jar already ships them, so the build lets the jar supply those two plus the six
|
||||
genuinely-unsourced classes (`JKDCUtils`, `NormalDistribution`, `StoreScan`,
|
||||
`DCRobotState`, `DCWave`, `Scan`).
|
||||
|
||||
Run it with:
|
||||
|
||||
ROBOCODE_JAR=vendor/robocode.jar ./compile_drussgt.sh
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
robots: jk.mega.DrussGT
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package jk.math;
|
||||
|
||||
public class FastTrig {
|
||||
public static final double PI = 3.1415926535897932384626433832795D;
|
||||
public static final double TWO_PI = 6.2831853071795864769252867665590D;
|
||||
public static final double HALF_PI = 1.5707963267948966192313216916398D;
|
||||
public static final double QUARTER_PI = 0.7853981633974483096156608458199D;
|
||||
public static final double THREE_OVER_TWO_PI
|
||||
= 4.7123889803846898576939650749193D;
|
||||
|
||||
|
||||
public static void main(String[] args){
|
||||
//accuracy test
|
||||
double maxdiff = 0;
|
||||
double sum = 0;
|
||||
double dv = 0;
|
||||
for(int i = 0; i < 500000; i++){
|
||||
double p = (i-250000)*(1.571/250000);
|
||||
double diff = Math.abs((Math.atan(p) - atan(p)));
|
||||
sum += diff;
|
||||
if(diff > maxdiff){
|
||||
maxdiff = diff;
|
||||
dv = p;
|
||||
}
|
||||
}
|
||||
System.out.println(maxdiff);
|
||||
System.out.println(dv);
|
||||
System.out.println(sum);
|
||||
}
|
||||
public static final double sin(double d) {
|
||||
d += Math.PI;
|
||||
double x2 = Math.floor(d*(1/(2*Math.PI)));
|
||||
d -= x2*(2*Math.PI);
|
||||
d-=Math.PI;
|
||||
|
||||
x2 = d * d;
|
||||
|
||||
|
||||
return //accurate to 6.82e-8, 3.3x faster than Math.sin,
|
||||
//faster than lookup table in real-world conditions due to no cache misses
|
||||
//all values from "Fast Polynomial Approximations to Sine and Cosine", Garret, C. K., 2012
|
||||
(((((-2.05342856289746600727e-08*x2 + 2.70405218307799040084e-06)*x2
|
||||
- 1.98125763417806681909e-04)*x2 + 8.33255814755188010464e-03)*x2
|
||||
- 1.66665772196961623983e-01)*x2 + 9.99999707044156546685e-01)*d;
|
||||
}
|
||||
|
||||
|
||||
public static final double cos(double d) {
|
||||
d += Math.PI;
|
||||
double x2 = Math.floor(d*(1/(2*Math.PI)));
|
||||
d -= x2*(2*Math.PI);
|
||||
d-=Math.PI;
|
||||
|
||||
d *= d;
|
||||
|
||||
return //max error 5.6e-7, 4x faster than Math.cos,
|
||||
//faster than lookup table in real-world conditions due to less cache misses
|
||||
//all values from "Fast Polynomial Approximations to Sine and Cosine", Garret, C. K., 2012
|
||||
((((- 2.21941782786353727022e-07*d + 2.42532401381033027481e-05)*d
|
||||
- 1.38627507062573673756e-03)*d + 4.16610337354021107429e-02)*d
|
||||
- 4.99995582499065048420e-01)*d + 1;
|
||||
}
|
||||
|
||||
public static final double sinInBounds(double d) {
|
||||
double x2 = d * d;
|
||||
|
||||
return //accurate to 6.82e-8, better than 3.3x faster than Math.sin,
|
||||
//faster than lookup table in real-world conditions due to less cache misses
|
||||
//all values from "Fast Polynomial Approximations to Sine and Cosine", Garret, C. K., 2012
|
||||
(((((-2.05342856289746600727e-08*x2 + 2.70405218307799040084e-06)*x2
|
||||
- 1.98125763417806681909e-04)*x2 + 8.33255814755188010464e-03)*x2
|
||||
- 1.66665772196961623983e-01)*x2 + 9.99999707044156546685e-01)*d;
|
||||
}
|
||||
|
||||
public static final double cosInBounds(double d) {
|
||||
|
||||
d *= d;
|
||||
|
||||
return //max error 5.6e-7, better than 4x faster than Math.cos,
|
||||
//faster than lookup table in real-world conditions due to less cache misses
|
||||
//all values from "Fast Polynomial Approximations to Sine and Cosine", Garret, C. K., 2012
|
||||
((((- 2.21941782786353727022e-07*d + 2.42532401381033027481e-05)*d
|
||||
- 1.38627507062573673756e-03)*d + 4.16610337354021107429e-02)*d
|
||||
- 4.99995582499065048420e-01)*d + 9.99999443739537210853e-01;
|
||||
}
|
||||
|
||||
//Takes about 1/3 of the time of Math.tan
|
||||
//chebyshev polynomials calculated with http://metamerist.com/cheby/example38.htm
|
||||
public static final double tan(double x) {
|
||||
x += HALF_PI;
|
||||
double i = Math.floor(x*(1/Math.PI));
|
||||
x -= i*(Math.PI) + HALF_PI;
|
||||
|
||||
if(Math.abs(x) > 0.25*Math.PI){
|
||||
x = Math.signum(x)*HALF_PI - x;
|
||||
i = x*x;
|
||||
return 1/(x * ( 1
|
||||
+ i * ( 0.33555055109755784988404247864565
|
||||
+ i * ( 0.11611832804825573745353974789374
|
||||
+ i * ( 0.0939748057591306776926771332915)))));
|
||||
}
|
||||
|
||||
i = x*x;
|
||||
return
|
||||
x * ( 1
|
||||
+ i * ( 0.33555055109755784988404247864565
|
||||
+ i * ( 0.11611832804825573745353974789374
|
||||
+ i * ( 0.0939748057591306776926771332915))));
|
||||
|
||||
}
|
||||
|
||||
public static final double floor(double value){
|
||||
double d = (long)value;
|
||||
if(value > 0)
|
||||
return d;
|
||||
if(value == d)
|
||||
return d;
|
||||
return d - 1;
|
||||
}
|
||||
|
||||
public static final double asin(double value) {
|
||||
//return atan(x / Math.sqrt(1 - x*x));
|
||||
return HALF_PI - acos(value);
|
||||
}
|
||||
|
||||
public static final double acos(double x){
|
||||
final double a = 1.570758334, b = -0.212875075, c = 0.076897503, d = -0.020892330;
|
||||
if(x<0)
|
||||
return Math.PI-Math.sqrt(1+x)*(a-x*(b-x*(c-x*d)));
|
||||
return Math.sqrt(1-x)*(a+x*(b+x*(c+x*d)));
|
||||
}
|
||||
|
||||
|
||||
//works on range 0 to 1 only!
|
||||
private static final double chebyshev_atan(double x) {
|
||||
// map x to range [-1, 1]
|
||||
final double xn = x * 2 -1;
|
||||
|
||||
// return Chebyshev approximation
|
||||
return 0.46364760900080604
|
||||
+ xn * ( 0.4005785601195767
|
||||
+ xn * ( -0.07982248463207417
|
||||
+ xn * ( -0.007789235359791622
|
||||
+ xn * ( 0.00891247504621044))));
|
||||
}
|
||||
|
||||
public static final double atan(double r) {
|
||||
if (r < 0.0)
|
||||
return -atan(-r);
|
||||
if (r > 1.0)
|
||||
return HALF_PI - chebyshev_atan(1.0 / r);
|
||||
return chebyshev_atan(r);
|
||||
}
|
||||
|
||||
public static final double atan2(final double y, final double x) {
|
||||
if (x==0.0) {
|
||||
if (y==0.0)
|
||||
return 0.0; // should be Double.NaN but Math.atan2 returns 0.0 in this case;
|
||||
return (y > 0.0) ? HALF_PI : -HALF_PI;
|
||||
}
|
||||
double absX = Math.abs(x);
|
||||
double absY = Math.abs(y);
|
||||
|
||||
double absAtan;
|
||||
if(absY > absX)
|
||||
absAtan = HALF_PI - chebyshev_atan(absX/absY);
|
||||
else
|
||||
absAtan = chebyshev_atan(absY/absX);
|
||||
|
||||
if(x < 0)
|
||||
absAtan = PI - absAtan;
|
||||
|
||||
if(y < 0)
|
||||
return -absAtan;
|
||||
|
||||
return absAtan;
|
||||
|
||||
}
|
||||
public static final double sqrt(double x){
|
||||
return Math.sqrt(x);
|
||||
//return x * (1.5d - 0.5*x* (x = Double.longBitsToDouble(0x5fe6ec85e7de30daL - (Double.doubleToLongBits(x)>>1) )) *x) * x;
|
||||
}
|
||||
public static final double normalRelativeAngle(double d){
|
||||
d += Math.PI;
|
||||
double i = Math.floor(d*(1./(2.*Math.PI)));
|
||||
d -= i*(2.*Math.PI);
|
||||
return d-Math.PI;
|
||||
}
|
||||
public static final double normalAbsoluteAngle(double d){
|
||||
double i = Math.floor(d*(1./(2.*Math.PI)));
|
||||
d -= i*(2.*Math.PI);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
package jk.mega;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BufferManager {
|
||||
|
||||
//Featuring "Slice retrieval indexes"
|
||||
static final float[] empty = {};
|
||||
|
||||
static final float[] velSlicesRough = {2.01f ,4.01f ,6.01f};
|
||||
static final float[] velSlices = {1.01f ,3.01f ,5.01f ,7.01f};
|
||||
static final float[] velSlicesFine = {0.5f, 1.5f ,2.5f ,3.5f ,4.5f ,5.5f ,6.5f ,7.5f};
|
||||
|
||||
static final float[] advVelSlicesRough = {-4.01f,-2.01f,1.51f};
|
||||
static final float[] advVelSlices = {-5f, -3f, -1f, 2f};
|
||||
static final float[] advVelSlicesFine = {-6.5f, -5f, -3.5f, -2f, -0.5f, 0.5f, 2f, 4f};
|
||||
|
||||
static final float[] bftSlicesRough = {20f ,40f ,60f};
|
||||
static final float[] bftSlices = {15f , 30f , 45f , 65f};
|
||||
static final float[] bftSlicesFine = {6f , 10f , 25f , 34f , 42f , 50f , 58f , 66f};
|
||||
|
||||
static final float[] tsdcSlicesRough = {0.25f ,0.5f ,0.75f, 1f, 1.25f,1.5f,1.75f};
|
||||
static final float[] tsdcSlices = {0.2f ,0.4f ,0.6f ,0.8f, 1f, 1.2f, 1.4f, 1.6f,1.8f};
|
||||
static final float[] tsdcSlicesFine = {0.1f ,0.2f ,0.3f ,0.4f ,0.5f ,0.6f ,0.8f, 0.9f, 1f, 1.1f, 1.2f, 1.3f,1.4f,1.5f};
|
||||
|
||||
static final float[] accelSlices = {-0.4f ,0.4f};
|
||||
static final float[] accelSlicesFine = {-2.1f, -1.9f, 0.9f, 1.1f};
|
||||
|
||||
static final float[] tsvcSlicesRough = {0.15f ,0.357f ,0.75f, 0.9f, 1.2f};
|
||||
static final float[] tsvcSlices = {0.1f ,0.2f ,0.4f ,0.8f, 0.92f, 1.0f};
|
||||
static final float[] tsvcSlicesFine = {0.05f ,0.1f ,0.16f ,0.2f ,0.4f ,0.6f ,0.85f, 0.96f, 1.1f, 1.3f};
|
||||
|
||||
static final float[] dl10SlicesRough = {20f ,50f ,80f};
|
||||
static final float[] dl10Slices = {10f ,20f ,35f ,50f ,68f ,85f};
|
||||
static final float[] dl10SlicesFine = {5f, 15f , 25f, 35f, 45f, 55f ,65f ,75f ,85f, 95f};
|
||||
|
||||
static final float[] wallSlicesRough = {0.33f , 0.66f, 1f};
|
||||
static final float[] wallSlices = {0.25f , 0.5f , 0.75f, 1.1f};
|
||||
|
||||
public static ArrayList getStatBuffers(){
|
||||
ArrayList statBuffers = new ArrayList(120);
|
||||
final float[][][] sets = new float[][][] {
|
||||
//empty
|
||||
{empty, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
|
||||
//simple
|
||||
{velSlices, advVelSlicesRough, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{empty, advVelSlices, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
{empty, advVelSlicesFine, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{empty, advVelSlicesFine, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlices, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlices, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{empty, advVelSlicesRough, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlices, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlicesFine, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlicesRough, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlicesRough, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, empty, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesRough, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlices, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{empty, advVelSlicesRough, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
|
||||
//Anti-PM
|
||||
{velSlicesRough, advVelSlicesFine, empty, tsdcSlicesFine, empty, empty, dl10Slices, empty, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, empty, tsvcSlices, dl10SlicesRough, empty, empty},
|
||||
{velSlices, advVelSlicesFine, empty, tsdcSlices, empty, tsvcSlicesFine, empty, empty, empty},
|
||||
{velSlicesFine, empty, empty, tsdcSlicesFine, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlices, advVelSlicesRough, empty, empty, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, advVelSlices, empty, tsdcSlicesRough, empty, empty, dl10SlicesRough, empty, empty},
|
||||
{velSlicesFine, advVelSlicesRough, empty, empty, empty, tsvcSlices, dl10Slices, empty, empty},
|
||||
{empty, advVelSlicesRough, empty, empty, accelSlices, tsvcSlicesRough, dl10Slices, empty, empty},
|
||||
{empty, empty, empty, tsdcSlicesFine, accelSlices, tsvcSlicesRough, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlices, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{velSlicesFine, advVelSlices, empty, tsdcSlices, empty, tsvcSlices, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlices, empty, tsdcSlices, accelSlices, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, empty, accelSlices, empty, dl10SlicesRough, empty, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlicesFine, empty, tsvcSlicesRough, dl10SlicesFine, empty, empty},
|
||||
{velSlices, empty, empty, tsdcSlicesRough, empty, tsvcSlices, dl10Slices, empty, empty},
|
||||
{empty, advVelSlices, empty, tsdcSlicesFine, accelSlices, tsvcSlicesFine, empty, empty, empty},
|
||||
{velSlices, advVelSlicesFine, empty, tsdcSlicesFine, accelSlices, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlices, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesFine, empty, tsdcSlices, accelSlices, empty, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesFine, empty, empty, empty, tsvcSlicesFine, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, advVelSlices, empty, tsdcSlicesRough, accelSlices, empty, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, tsdcSlices, empty, tsvcSlicesFine, empty, empty, empty},
|
||||
{empty, advVelSlices, empty, tsdcSlices, empty, tsvcSlices, dl10SlicesFine, empty, empty},
|
||||
{velSlices, advVelSlices, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesFine, empty, empty, accelSlices, empty, dl10SlicesRough, empty, empty},
|
||||
{empty, advVelSlicesRough, empty, tsdcSlicesFine, accelSlices, empty, dl10SlicesRough, empty, empty},
|
||||
{velSlicesFine, advVelSlicesRough, empty, tsdcSlicesRough, accelSlices, empty, empty, empty, empty} ,
|
||||
//main
|
||||
{velSlicesRough, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, empty, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesFine, empty, empty, empty, tsvcSlices, dl10SlicesRough, empty, empty},
|
||||
{velSlices, advVelSlices, bftSlicesFine, empty, accelSlices, empty, empty, wallSlices, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlices, empty, tsvcSlicesFine, dl10Slices, empty, wallSlicesRough},
|
||||
{velSlices, advVelSlicesFine, empty, empty, empty, tsvcSlicesFine, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, empty, empty, empty, tsvcSlicesRough, empty, wallSlicesRough, empty},
|
||||
{empty, advVelSlicesFine, bftSlicesRough, tsdcSlicesFine, empty, empty, dl10Slices, wallSlicesRough, empty},
|
||||
{velSlices, empty, empty, empty, accelSlices, tsvcSlices, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, bftSlices, empty, empty, empty, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesFine, advVelSlicesFine, bftSlicesRough, empty, empty, empty, empty, empty, empty},
|
||||
{empty, empty, bftSlices, empty, accelSlices, empty, dl10SlicesFine, wallSlices, empty},
|
||||
{empty, advVelSlicesRough, bftSlices, empty, accelSlices, empty, empty, empty, empty},
|
||||
{empty, advVelSlices, bftSlicesRough, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesRough, empty, bftSlicesRough, empty, accelSlices, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlicesRough, empty, tsdcSlicesRough, empty, empty, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesRough, empty, empty, tsdcSlicesRough, accelSlices, empty, empty, wallSlices, empty},
|
||||
{empty, advVelSlicesFine, bftSlices, empty, empty, empty, dl10SlicesFine, wallSlicesRough, empty},
|
||||
{velSlices, advVelSlicesFine, bftSlicesRough, tsdcSlicesFine, empty, empty, empty, wallSlicesRough, empty},
|
||||
{velSlices, advVelSlicesFine, bftSlicesRough, tsdcSlicesRough, empty, tsvcSlices, empty, empty, empty},
|
||||
{velSlicesFine, empty, bftSlices, empty, empty, tsvcSlices, empty, wallSlicesRough, empty},
|
||||
{velSlices, advVelSlices, empty, tsdcSlicesFine, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{velSlicesFine, advVelSlicesFine, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, wallSlicesRough},
|
||||
{velSlices, empty, bftSlicesRough, empty, accelSlices, empty, dl10Slices, wallSlicesRough, empty},
|
||||
{velSlicesRough, empty, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlicesFine, bftSlices, empty, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
{velSlices, empty, bftSlicesRough, tsdcSlicesRough, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesRough, advVelSlicesFine, bftSlices, empty, empty, tsvcSlices, empty, empty, wallSlicesRough},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlicesRough, tsdcSlices, empty, empty, empty, empty, wallSlicesRough},
|
||||
{velSlicesFine, advVelSlicesRough, empty, empty, empty, tsvcSlicesFine, empty, wallSlices, wallSlicesRough},
|
||||
{velSlicesRough, empty, bftSlices, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
{velSlices, empty, bftSlicesFine, tsdcSlicesRough, empty, empty, dl10SlicesFine, wallSlices, empty},
|
||||
{empty, advVelSlicesFine, empty, empty, accelSlices, tsvcSlicesFine, empty, empty, empty},
|
||||
{empty, empty, bftSlicesRough, tsdcSlices, accelSlices, tsvcSlicesFine, dl10SlicesRough, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, empty, accelSlices, empty, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, bftSlices, tsdcSlices, empty, tsvcSlicesRough, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesRough, empty, bftSlices, tsdcSlicesFine, empty, empty, empty, empty, empty},
|
||||
{velSlicesRough, empty, bftSlicesFine, tsdcSlices, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{velSlices, empty, empty, empty, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{velSlicesFine, empty, bftSlices, empty, empty, tsvcSlicesFine, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlices, bftSlicesFine, tsdcSlicesRough, empty, empty, empty, empty, wallSlicesRough},
|
||||
{velSlices, advVelSlices, bftSlicesRough, empty, empty, empty, dl10Slices, wallSlices, empty},
|
||||
{velSlices, advVelSlicesFine, empty, empty, accelSlices, tsvcSlicesFine, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, empty, empty, accelSlices, empty, empty, wallSlices, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, accelSlices, empty, empty, wallSlices, empty},
|
||||
{velSlicesFine, empty, empty, tsdcSlices, empty, tsvcSlicesRough, empty, wallSlicesRough, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlices, empty, empty, dl10Slices, wallSlicesRough, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, accelSlices, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlices, bftSlicesFine, empty, empty, tsvcSlicesFine, empty, empty, empty},
|
||||
{velSlices, advVelSlicesRough, empty, empty, empty, tsvcSlicesRough, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, empty, empty, accelSlices, tsvcSlices, dl10SlicesFine, wallSlices, empty},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlicesFine, empty, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
{velSlices, advVelSlicesRough, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, empty, bftSlices, empty, accelSlices, tsvcSlicesRough, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, advVelSlices, bftSlicesRough, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
{empty, empty, bftSlices, empty, empty, empty, dl10SlicesRough, wallSlicesRough, empty},
|
||||
{velSlices, empty, bftSlices, tsdcSlicesRough, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{empty, advVelSlices, empty, empty, empty, tsvcSlices, dl10Slices, wallSlices, empty},
|
||||
{velSlicesFine, empty, empty, tsdcSlices, accelSlices, tsvcSlicesRough, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlices, advVelSlices, bftSlices, empty, empty, empty, empty, empty, empty},
|
||||
{velSlices, advVelSlicesFine, bftSlicesFine, empty, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{velSlicesRough, empty, bftSlices, empty, accelSlices, empty, empty, wallSlices, wallSlicesRough},
|
||||
{velSlicesFine, empty, empty, empty, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, bftSlicesRough, empty, empty, tsvcSlicesRough, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{velSlices, advVelSlices, bftSlicesRough, empty, empty, tsvcSlicesFine, dl10SlicesFine, wallSlicesRough, empty},
|
||||
{velSlices, empty, empty, empty, empty, tsvcSlicesRough, empty, wallSlices, empty},
|
||||
{velSlices, advVelSlicesFine, bftSlices, empty, empty, empty, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesRough, empty, empty, empty, dl10SlicesRough, wallSlicesRough, wallSlicesRough},
|
||||
{velSlices, advVelSlicesRough, bftSlicesFine, empty, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
// {velSlicesRough, empty, bftSlicesFine, empty, accelSlices, empty, dl10SlicesFine, wallSlices, empty},
|
||||
// {velSlicesFine, empty, empty, tsdcSlicesRough, accelSlices, empty, dl10SlicesRough, wallSlices, empty},
|
||||
// {velSlicesFine, advVelSlicesRough, bftSlicesFine, empty, accelSlices, empty, dl10Slices, empty, empty},
|
||||
// {velSlices, advVelSlicesRough, empty, tsdcSlices, empty, tsvcSlicesFine, empty, wallSlicesRough, empty},
|
||||
// {velSlices, advVelSlices, bftSlicesFine, empty, accelSlices, empty, dl10Slices, empty, empty},
|
||||
// {velSlicesRough, empty, bftSlicesFine, tsdcSlicesRough, empty, empty, empty, wallSlices, empty},
|
||||
// {velSlices, advVelSlicesFine, bftSlicesFine, tsdcSlicesRough, accelSlices, empty, empty, empty, empty},
|
||||
// {empty, empty, bftSlicesRough, tsdcSlices, empty, empty, dl10Slices, wallSlices, wallSlicesRough},
|
||||
// {velSlices, empty, bftSlicesFine, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlicesFine, advVelSlices, empty, tsdcSlices, empty, empty, empty, wallSlices, empty},
|
||||
// {velSlicesRough, advVelSlicesRough, empty, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlicesRough, empty, empty, empty, accelSlices, empty, dl10SlicesRough, empty, empty},
|
||||
// {velSlicesFine, advVelSlicesFine, empty, empty, accelSlices, tsvcSlicesRough, empty, empty, empty},
|
||||
// {velSlices, advVelSlicesFine, empty, empty, empty, empty, dl10SlicesRough, wallSlicesRough, empty},
|
||||
// {velSlicesFine, advVelSlicesFine, bftSlicesRough, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlicesFine, advVelSlicesRough, bftSlicesRough, empty, empty, empty, dl10Slices, empty, empty},
|
||||
// {empty, empty, bftSlicesRough, empty, empty, tsvcSlicesFine, dl10Slices, empty, empty},
|
||||
// {empty, advVelSlicesFine, bftSlices, empty, accelSlices, empty, empty, wallSlices, empty},
|
||||
// {velSlices, empty, bftSlicesRough, empty, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
// {velSlicesFine, empty, bftSlices, empty, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlicesRough, empty, empty, tsdcSlicesFine, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlicesFine, empty, empty, empty, accelSlices, empty, empty, wallSlices, empty},
|
||||
// {velSlicesRough, empty, bftSlicesRough, empty, empty, tsvcSlicesFine, empty, empty, empty},
|
||||
// {empty, empty, bftSlices, empty, accelSlices, empty, dl10SlicesRough, wallSlices, empty},
|
||||
// {velSlices, advVelSlicesFine, empty, empty, empty, tsvcSlices, empty, wallSlices, empty},
|
||||
// {velSlices, advVelSlicesRough, bftSlicesFine, empty, empty, empty, empty, wallSlices, empty},
|
||||
// {velSlices, empty, bftSlices, tsdcSlices, empty, empty, empty, empty, empty},
|
||||
// {velSlices, empty, bftSlicesFine, empty, empty, empty, empty, empty, empty},
|
||||
// {velSlices, advVelSlicesFine, empty, empty, accelSlices, tsvcSlices, dl10SlicesRough, wallSlices, empty},
|
||||
// {velSlicesRough, advVelSlices, bftSlicesFine, tsdcSlices, empty, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlices, empty, bftSlicesFine, tsdcSlicesFine, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
// {velSlices, advVelSlices, bftSlices, empty, empty, empty, dl10Slices, wallSlicesRough, empty},
|
||||
// {velSlicesFine, empty, empty, empty, accelSlices, empty, empty, wallSlicesRough, empty}
|
||||
} ;
|
||||
|
||||
putBuffersInto(sets,statBuffers);
|
||||
|
||||
return statBuffers;
|
||||
}
|
||||
public static ArrayList getFlattenerBuffers(){
|
||||
ArrayList flattenerBuffers = new ArrayList(50);
|
||||
|
||||
float[][][] flatSets = new float[][][] {
|
||||
{empty, empty, bftSlicesRough, empty, accelSlices, tsvcSlicesRough, empty, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlices, bftSlicesRough, empty, empty, empty, dl10SlicesFine, wallSlicesRough, wallSlicesRough},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, tsvcSlicesFine, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlicesRough, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, bftSlicesRough, empty, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{empty, empty, empty, tsdcSlices, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{empty, advVelSlicesFine, bftSlices, tsdcSlicesFine, empty, tsvcSlicesRough, dl10SlicesRough, empty, empty},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesRough, empty, bftSlicesRough, empty, accelSlices, tsvcSlicesRough, empty, wallSlices, empty},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, tsvcSlicesRough, dl10Slices, empty, empty},
|
||||
{empty, advVelSlicesRough, bftSlicesFine, empty, accelSlices, empty, dl10SlicesRough, empty, empty},
|
||||
{empty, empty, bftSlices, empty, empty, tsvcSlices, dl10Slices, empty, wallSlicesRough},
|
||||
{velSlicesFine, empty, bftSlices, empty, accelSlices, tsvcSlicesFine, empty, empty, empty},
|
||||
{empty, advVelSlicesRough, bftSlicesRough, empty, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlices, bftSlicesRough, tsdcSlices, empty, tsvcSlicesFine, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{velSlicesFine, empty, bftSlices, empty, accelSlices, tsvcSlicesFine, dl10Slices, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlices, tsdcSlicesRough, empty, tsvcSlicesRough, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{velSlicesRough, empty, bftSlicesFine, empty, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{empty, empty, bftSlices, empty, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, empty, empty, empty, tsvcSlices, dl10SlicesFine, wallSlicesRough, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlicesFine, empty, tsvcSlices, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, empty, bftSlicesRough, empty, accelSlices, tsvcSlices, empty, empty, wallSlicesRough},
|
||||
{velSlicesRough, advVelSlices, bftSlices, empty, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{velSlicesRough, advVelSlices, bftSlices, tsdcSlices, accelSlices, empty, empty, wallSlices, empty},
|
||||
{velSlicesFine, advVelSlicesRough, bftSlicesRough, empty, empty, empty, empty, wallSlices, empty},
|
||||
{empty, empty, empty, tsdcSlices, accelSlices, tsvcSlicesRough, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesRough, empty, empty, tsdcSlicesRough, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, empty, tsdcSlicesFine, empty, empty, dl10SlicesFine, empty, empty},
|
||||
{empty, advVelSlices, empty, empty, empty, tsvcSlicesRough, dl10Slices, wallSlices, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, empty, empty, empty, dl10SlicesFine, wallSlices, wallSlicesRough},
|
||||
{velSlices, advVelSlicesFine, empty, tsdcSlices, empty, tsvcSlices, empty, empty, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, empty, tsdcSlices, empty, empty, dl10Slices, wallSlices, empty},
|
||||
{empty, advVelSlicesFine, empty, tsdcSlicesFine, accelSlices, empty, empty, wallSlices, wallSlicesRough},
|
||||
{velSlicesRough, empty, empty, empty, empty, empty, dl10Slices, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesFine, empty, empty, tsdcSlicesRough, accelSlices, tsvcSlicesRough, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, advVelSlices, bftSlices, empty, accelSlices, tsvcSlicesRough, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlices, tsdcSlicesFine, empty, empty, dl10Slices, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesFine, empty, bftSlicesRough, tsdcSlicesRough, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, empty, empty, empty, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{velSlices, empty, empty, empty, empty, tsvcSlices, dl10SlicesFine, empty, wallSlicesRough},
|
||||
{empty, advVelSlices, bftSlicesFine, empty, empty, tsvcSlices, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, empty, bftSlices, tsdcSlicesRough, accelSlices, empty, empty, empty, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, bftSlicesRough, tsdcSlicesRough, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{empty, advVelSlicesFine, bftSlicesFine, tsdcSlices, empty, empty, dl10SlicesFine, wallSlicesRough, empty},
|
||||
{velSlicesFine, advVelSlicesFine, bftSlices, empty, accelSlices, empty, empty, empty, empty},
|
||||
{empty, advVelSlicesFine, bftSlicesFine, empty, empty, empty, dl10SlicesFine, wallSlicesRough, empty},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, tsvcSlicesFine, empty, empty, wallSlicesRough},
|
||||
{empty, empty, empty, tsdcSlicesFine, accelSlices, tsvcSlices, dl10Slices, empty, empty},
|
||||
{velSlicesRough, empty, empty, empty, accelSlices, tsvcSlices, dl10SlicesFine, empty, empty},
|
||||
{empty, advVelSlicesFine, empty, tsdcSlices, accelSlices, empty, empty, empty, wallSlicesRough}
|
||||
};
|
||||
|
||||
putBuffersInto(flatSets,flattenerBuffers);
|
||||
return flattenerBuffers;
|
||||
|
||||
}
|
||||
public static ArrayList getABSBuffers(){
|
||||
ArrayList ABSBuffers = new ArrayList(50);
|
||||
|
||||
float[][][] flatSets = new float[][][] {
|
||||
{velSlicesRough, empty, empty, empty, empty, tsvcSlicesFine, empty, wallSlicesRough, empty},
|
||||
{empty, empty, bftSlicesRough, empty, empty, empty, dl10SlicesFine, wallSlices, empty},
|
||||
{empty, empty, bftSlices, tsdcSlicesRough, empty, tsvcSlicesRough, empty, wallSlicesRough, wallSlicesRough},
|
||||
{velSlices, advVelSlices, bftSlicesRough, empty, empty, tsvcSlicesRough, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesRough, empty, empty, tsvcSlicesRough, empty, wallSlices, empty},
|
||||
{velSlicesFine, advVelSlicesFine, bftSlices, empty, empty, tsvcSlices, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, tsdcSlicesRough, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{velSlicesRough, empty, empty, empty, accelSlices, tsvcSlicesFine, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesRough, tsdcSlicesFine, accelSlices, tsvcSlicesFine, dl10SlicesFine, empty, empty},
|
||||
{velSlicesRough, empty, empty, tsdcSlices, accelSlices, tsvcSlices, empty, empty, empty},
|
||||
{velSlicesFine, empty, bftSlicesFine, empty, empty, empty, dl10SlicesRough, wallSlicesRough, wallSlicesRough},
|
||||
{velSlicesRough, advVelSlicesRough, empty, tsdcSlices, empty, tsvcSlices, empty, empty, wallSlicesRough},
|
||||
{empty, advVelSlicesRough, empty, empty, accelSlices, tsvcSlices, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, empty, empty, empty, tsvcSlicesFine, dl10SlicesFine, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlicesRough, empty, empty, accelSlices, tsvcSlicesRough, dl10Slices, empty, empty},
|
||||
{velSlicesRough, empty, bftSlicesFine, tsdcSlicesRough, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, empty, bftSlices, tsdcSlicesRough, empty, empty, empty, empty, empty},
|
||||
{velSlicesFine, advVelSlices, bftSlicesFine, empty, empty, tsvcSlices, empty, empty, empty},
|
||||
{velSlicesRough, advVelSlicesFine, empty, empty, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{empty, empty, bftSlices, tsdcSlices, empty, tsvcSlicesRough, dl10Slices, empty, empty},
|
||||
{empty, empty, bftSlices, empty, accelSlices, tsvcSlicesFine, empty, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, empty, empty, accelSlices, tsvcSlices, empty, wallSlicesRough, empty},
|
||||
{velSlicesRough, advVelSlicesRough, bftSlices, empty, empty, tsvcSlices, dl10SlicesFine, empty, empty},
|
||||
{empty, empty, empty, tsdcSlices, empty, tsvcSlicesRough, dl10SlicesRough, empty, empty},
|
||||
{velSlicesFine, empty, empty, tsdcSlices, empty, empty, empty, wallSlices, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, empty, empty, tsvcSlices, dl10SlicesFine, empty, wallSlicesRough},
|
||||
{velSlicesFine, empty, empty, tsdcSlicesRough, empty, empty, dl10Slices, wallSlices, empty},
|
||||
{empty, empty, empty, empty, accelSlices, tsvcSlices, dl10SlicesFine, empty, wallSlicesRough},
|
||||
{empty, empty, empty, tsdcSlicesFine, accelSlices, tsvcSlices, dl10SlicesRough, empty, empty},
|
||||
{empty, empty, bftSlicesRough, tsdcSlicesFine, accelSlices, tsvcSlices, empty, wallSlicesRough, wallSlicesRough}
|
||||
} ;
|
||||
putBuffersInto(flatSets,ABSBuffers);
|
||||
return ABSBuffers;
|
||||
|
||||
}
|
||||
public static ArrayList getFlattenerTickBuffers(){
|
||||
ArrayList flattenerTickBuffers = new ArrayList(15);
|
||||
|
||||
float[][][] flatTickSets = new float[][][] {
|
||||
{empty, empty, empty, empty, accelSlices, empty, dl10SlicesFine, wallSlices, wallSlicesRough},
|
||||
{velSlicesFine, empty, empty, tsdcSlices, empty, empty, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{velSlicesFine, empty, bftSlices, empty, accelSlices, empty, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{empty, advVelSlicesFine, bftSlicesFine, tsdcSlicesFine, accelSlices, empty, dl10SlicesFine, empty, empty},
|
||||
{velSlices, empty, empty, tsdcSlices, empty, tsvcSlicesRough, empty, wallSlices, wallSlicesRough},
|
||||
{empty, advVelSlicesFine, bftSlicesRough, tsdcSlicesFine, empty, empty, dl10SlicesRough, empty, empty},
|
||||
{empty, empty, bftSlices, tsdcSlicesFine, accelSlices, tsvcSlicesRough, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, empty, accelSlices, tsvcSlicesRough, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesRough, empty, accelSlices, tsvcSlicesFine, dl10Slices, wallSlicesRough, empty},
|
||||
{empty, advVelSlicesFine, empty, tsdcSlices, accelSlices, tsvcSlicesRough, empty, wallSlices, empty},
|
||||
{velSlicesFine, advVelSlicesFine, bftSlices, empty, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{empty, empty, bftSlices, empty, empty, tsvcSlicesFine, dl10SlicesRough, wallSlices, wallSlicesRough},
|
||||
{velSlicesRough, advVelSlicesFine, bftSlices, empty, empty, tsvcSlicesRough, dl10SlicesRough, wallSlices, empty},
|
||||
{empty, empty, empty, empty, accelSlices, empty, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, advVelSlicesRough, bftSlicesRough, tsdcSlices, empty, tsvcSlicesFine, empty, wallSlices, empty},
|
||||
{empty, advVelSlicesRough, empty, tsdcSlicesRough, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{velSlicesFine, advVelSlicesFine, empty, empty, accelSlices, empty, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, empty, empty, empty, empty, wallSlicesRough, empty},
|
||||
{velSlices, empty, bftSlices, tsdcSlices, accelSlices, empty, empty, empty, empty},
|
||||
{velSlicesFine, empty, bftSlicesFine, empty, empty, empty, empty, wallSlicesRough, wallSlicesRough},
|
||||
{empty, advVelSlices, bftSlicesRough, empty, empty, empty, dl10Slices, empty, wallSlicesRough},
|
||||
{velSlices, advVelSlicesRough, empty, empty, accelSlices, empty, empty, wallSlicesRough, empty},
|
||||
{empty, advVelSlicesFine, bftSlices, empty, accelSlices, tsvcSlices, empty, wallSlices, empty},
|
||||
{velSlices, advVelSlices, bftSlicesRough, tsdcSlices, accelSlices, empty, empty, empty, empty},
|
||||
{empty, advVelSlices, bftSlicesFine, tsdcSlicesRough, empty, empty, empty, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlices, empty, empty, tsvcSlices, dl10SlicesFine, empty, wallSlicesRough},
|
||||
{empty, empty, bftSlicesFine, tsdcSlices, accelSlices, tsvcSlicesFine, empty, empty, empty},
|
||||
{empty, advVelSlices, empty, empty, accelSlices, tsvcSlices, dl10SlicesRough, empty, wallSlicesRough},
|
||||
{velSlices, advVelSlices, bftSlicesFine, empty, empty, empty, dl10SlicesRough, empty, empty}
|
||||
};
|
||||
|
||||
putBuffersInto(flatTickSets,flattenerTickBuffers);
|
||||
return flattenerTickBuffers;
|
||||
|
||||
}
|
||||
|
||||
private static void putBuffersInto(float[][][] sets, ArrayList buffers){
|
||||
for(int i = 0; i < sets.length; i++){
|
||||
float[][] set = sets[i];
|
||||
|
||||
int[] sri = new int[9];
|
||||
|
||||
if(set[0] == empty)
|
||||
sri[0] = 0;
|
||||
else if(set[0] == velSlicesRough)
|
||||
sri[0] = 1;
|
||||
else if(set[0] == velSlices)
|
||||
sri[0] = 2;
|
||||
else if(set[0] == velSlicesFine)
|
||||
sri[0] = 3;
|
||||
|
||||
if(set[1] == empty)
|
||||
sri[1] = 0;
|
||||
else if(set[1] == advVelSlicesRough)
|
||||
sri[1] = 1;
|
||||
else if(set[1] == advVelSlices)
|
||||
sri[1] = 2;
|
||||
else if(set[1] == advVelSlicesFine)
|
||||
sri[1] = 3;
|
||||
|
||||
|
||||
if(set[2] == empty)
|
||||
sri[2] = 0;
|
||||
else if(set[2] == bftSlicesRough)
|
||||
sri[2] = 1;
|
||||
else if(set[2] == bftSlices)
|
||||
sri[2] = 2;
|
||||
else if(set[2] == bftSlicesFine)
|
||||
sri[2] = 3;
|
||||
|
||||
|
||||
if(set[3] == empty)
|
||||
sri[3] = 0;
|
||||
else if(set[3] == tsdcSlicesRough)
|
||||
sri[3] = 1;
|
||||
else if(set[3] == tsdcSlices)
|
||||
sri[3] = 2;
|
||||
else if(set[3] == tsdcSlicesFine)
|
||||
sri[3] = 3;
|
||||
|
||||
|
||||
if(set[4] == empty)
|
||||
sri[4] = 0;
|
||||
else if(set[4] == accelSlices)
|
||||
sri[4] = 1;
|
||||
else if(set[4] == accelSlicesFine)
|
||||
sri[4] = 2;
|
||||
|
||||
|
||||
if(set[5] == empty)
|
||||
sri[5] = 0;
|
||||
else if(set[5] == tsvcSlicesRough)
|
||||
sri[5] = 1;
|
||||
else if(set[5] == tsvcSlices)
|
||||
sri[5] = 2;
|
||||
else if(set[5] == tsvcSlicesFine)
|
||||
sri[5] = 3;
|
||||
|
||||
|
||||
if(set[6] == empty)
|
||||
sri[6] = 0;
|
||||
else if(set[6] == dl10SlicesRough)
|
||||
sri[6] = 1;
|
||||
else if(set[6] == dl10Slices)
|
||||
sri[6] = 2;
|
||||
else if(set[6] == dl10SlicesFine)
|
||||
sri[6] = 3;
|
||||
|
||||
|
||||
if(set[7] == empty)
|
||||
sri[7] = 0;
|
||||
else if(set[7] == wallSlicesRough)
|
||||
sri[7] = 1;
|
||||
else if(set[7] == wallSlices)
|
||||
sri[7] = 2;
|
||||
|
||||
|
||||
if(set[8] == empty)
|
||||
sri[8] = 0;
|
||||
else if(set[8] == wallSlicesRough)
|
||||
sri[8] = 1;
|
||||
else if(set[8] == wallSlices)
|
||||
sri[8] = 2;
|
||||
|
||||
StatBuffer sb = new StatBuffer(set[0],set[1],set[2],set[3],set[4],set[5],set[6],set[7],set[8],sri);
|
||||
|
||||
buffers.add(sb);
|
||||
}
|
||||
|
||||
}
|
||||
public static int[][] getIndexes(
|
||||
float latVel,
|
||||
float advVel,
|
||||
float bft,
|
||||
float tsdc,
|
||||
float accel,
|
||||
float tsvc,
|
||||
float dl10,
|
||||
float forwardWall,
|
||||
float reverseWall){
|
||||
|
||||
|
||||
int[][] indexes = new int[4][9];
|
||||
|
||||
/// set up indexes
|
||||
indexes[1][0] = getIndex(velSlicesRough, latVel);
|
||||
indexes[2][0] = getIndex(velSlices, latVel);
|
||||
indexes[3][0] = getIndex(velSlicesFine, latVel);
|
||||
|
||||
indexes[1][1] = getIndex(advVelSlicesRough, advVel);
|
||||
indexes[2][1] = getIndex(advVelSlices, advVel);
|
||||
indexes[3][1] = getIndex(advVelSlicesFine, advVel);
|
||||
|
||||
indexes[1][2] = getIndex(bftSlicesRough, bft);
|
||||
indexes[2][2] = getIndex(bftSlices, bft);
|
||||
indexes[3][2] = getIndex(bftSlicesFine, bft);
|
||||
|
||||
indexes[1][3] = getIndex(tsdcSlicesRough, tsdc);
|
||||
indexes[2][3] = getIndex(tsdcSlices, tsdc);
|
||||
indexes[3][3] = getIndex(tsdcSlicesFine, tsdc);
|
||||
|
||||
indexes[1][4] = getIndex(accelSlices, accel);
|
||||
indexes[2][4] = getIndex(accelSlicesFine, accel);
|
||||
|
||||
indexes[1][5] = getIndex(tsvcSlicesRough, tsvc);
|
||||
indexes[2][5] = getIndex(tsvcSlices, tsvc);
|
||||
indexes[3][5] = getIndex(tsvcSlicesFine, tsvc);
|
||||
|
||||
indexes[1][6] = getIndex(dl10SlicesRough, dl10);
|
||||
indexes[2][6] = getIndex(dl10Slices, dl10);
|
||||
indexes[3][6] = getIndex(dl10SlicesFine, dl10);
|
||||
|
||||
indexes[1][7] = getIndex(wallSlicesRough, forwardWall);
|
||||
indexes[2][7] = getIndex(wallSlices, forwardWall);
|
||||
|
||||
indexes[1][8] = getIndex(wallSlicesRough, reverseWall);
|
||||
indexes[2][8] = getIndex(wallSlices, reverseWall);
|
||||
|
||||
return indexes;
|
||||
|
||||
}
|
||||
public static ArrayList getStats(ArrayList buffers, int[][] indexes){
|
||||
ArrayList stats = new ArrayList(buffers.size());
|
||||
|
||||
for(int i = 0, k = buffers.size(); i < k; i++){
|
||||
stats.add(((StatBuffer)(buffers.get(i))).getStats(indexes));
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
private static int getIndex(float[] slices, float value){
|
||||
int index = 0;
|
||||
while(index < slices.length && value >= slices[index])
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
|
||||
public static class SingleBuffer{
|
||||
public int binsUsed,hits;
|
||||
public int[] bins;
|
||||
public float weight;
|
||||
public float rollingDepth = 0.7f;
|
||||
|
||||
public void addHit(int hitIndex){
|
||||
if(bins == null){
|
||||
bins = new int[(int)Math.ceil(rollingDepth*2) + 1];
|
||||
hits = -1;
|
||||
}
|
||||
|
||||
if(binsUsed < bins.length)
|
||||
binsUsed+=1;
|
||||
|
||||
hits = (hits+1)%bins.length;
|
||||
bins[hits] = hitIndex;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class StatBuffer{
|
||||
|
||||
public float _weight;
|
||||
public float rollingDepth;
|
||||
|
||||
public SingleBuffer [][][][][][][][][] stats;
|
||||
|
||||
public int[] sri;
|
||||
|
||||
public StatBuffer(
|
||||
float[] vSlices,
|
||||
float[] aVSlices,
|
||||
float[] dSlices,
|
||||
float[] tsdcSlices,
|
||||
float[] accSlices,
|
||||
float[] tsvcSlices,
|
||||
float[] dl10Slices,
|
||||
float[] fWallSlices,
|
||||
float[] rWallSlices,
|
||||
int[] sliceRetrieveIndexes){
|
||||
|
||||
stats = new SingleBuffer
|
||||
[vSlices.length + 1]
|
||||
[aVSlices.length + 1]
|
||||
[dSlices.length + 1]
|
||||
[tsdcSlices.length + 1]
|
||||
[accSlices.length + 1]
|
||||
[tsvcSlices.length + 1]
|
||||
[dl10Slices.length + 1]
|
||||
[fWallSlices.length + 1]
|
||||
[rWallSlices.length + 1];
|
||||
|
||||
float weight = (vSlices.length + 1)
|
||||
*(aVSlices.length + 1)
|
||||
*(dSlices.length + 1)
|
||||
*(tsdcSlices.length +1)
|
||||
*(accSlices.length + 1)
|
||||
*(tsvcSlices.length + 1)
|
||||
*(dl10Slices.length + 1)
|
||||
*(fWallSlices.length + 1)
|
||||
*(rWallSlices.length + 1);
|
||||
|
||||
if(weight < 2)
|
||||
rollingDepth = 3;
|
||||
else if(weight < 3)
|
||||
rollingDepth = 1;
|
||||
// else if(weight < 7)
|
||||
// rollingDepth = 1;
|
||||
else if(weight < 10)
|
||||
rollingDepth = 0.7f;
|
||||
else if(weight < 33)
|
||||
rollingDepth = 0.5f;
|
||||
else if(weight < 100)
|
||||
rollingDepth = 0.2f;
|
||||
else rollingDepth = 0.1f;
|
||||
|
||||
// _weight = 1;
|
||||
_weight = weight;
|
||||
sri = sliceRetrieveIndexes;
|
||||
}
|
||||
/*SingleBuffer getStats(float latVel, float advVel, float distance, float tsdc, float accel, float tsvc, float dl10, float forwardWall, float reverseWall){
|
||||
SingleBuffer sb = new SingleBuffer();
|
||||
sb.bins = stats
|
||||
[getIndex(velocitySlices, latVel)]
|
||||
[getIndex(advVelocitySlices, advVel)]
|
||||
[getIndex(distanceSlices, distance)]
|
||||
[getIndex(timeSinceDirChangeSlices, tsdc)]
|
||||
[getIndex(accelSlices,accel)]
|
||||
[getIndex(timeSinceVelChangeSlices, tsvc)]
|
||||
[getIndex(distLast20Slices, dl10)]
|
||||
[getIndex(forwardWallSlices,forwardWall)]
|
||||
[getIndex(reverseWallSlices,reverseWall)];
|
||||
sb.weight = this._weight;
|
||||
sb.rollingDepth = this.rollingDepth;
|
||||
return sb;
|
||||
|
||||
}*/
|
||||
public SingleBuffer getStats(int[][] indexes){
|
||||
SingleBuffer sb = stats
|
||||
[indexes[sri[0]][0]]
|
||||
[indexes[sri[1]][1]]
|
||||
[indexes[sri[2]][2]]
|
||||
[indexes[sri[3]][3]]
|
||||
[indexes[sri[4]][4]]
|
||||
[indexes[sri[5]][5]]
|
||||
[indexes[sri[6]][6]]
|
||||
[indexes[sri[7]][7]]
|
||||
[indexes[sri[8]][8]]
|
||||
;
|
||||
if(sb == null){
|
||||
sb = stats
|
||||
[indexes[sri[0]][0]]
|
||||
[indexes[sri[1]][1]]
|
||||
[indexes[sri[2]][2]]
|
||||
[indexes[sri[3]][3]]
|
||||
[indexes[sri[4]][4]]
|
||||
[indexes[sri[5]][5]]
|
||||
[indexes[sri[6]][6]]
|
||||
[indexes[sri[7]][7]]
|
||||
[indexes[sri[8]][8]] = new SingleBuffer();
|
||||
|
||||
|
||||
sb.weight = this._weight;
|
||||
sb.rollingDepth = this.rollingDepth;
|
||||
sb.hits = -1;
|
||||
}
|
||||
|
||||
|
||||
return sb;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package jk.mega;
|
||||
import java.util.*;
|
||||
import jk.tree.KDTree;
|
||||
|
||||
public class BulletPowerPredictor{
|
||||
KDTree<Float> bulletPowerTree = new KDTree.Euclidean<Float>(3);
|
||||
public void train(double botEnergy, double oppEnergy, double distance, float bulletPower){
|
||||
bulletPowerTree.addPoint(
|
||||
new double[]{botEnergy/200,oppEnergy/200,distance/1200},
|
||||
bulletPower);
|
||||
}
|
||||
|
||||
public double predictBulletPower(double myEnergy, double enemyEnergy, double distance){
|
||||
|
||||
List<KDTree.SearchResult<Float>> cl = bulletPowerTree.nearestNeighbours(
|
||||
new double[]{myEnergy/200, enemyEnergy/200, distance/1200},
|
||||
Math.min((int)Math.ceil(Math.sqrt(bulletPowerTree.size())),20));
|
||||
|
||||
double[][] bullHist = new double[2][cl.size()];
|
||||
|
||||
Iterator<KDTree.SearchResult<Float>> it = cl.iterator();
|
||||
int i = 0;
|
||||
while(it.hasNext()){
|
||||
KDTree.SearchResult<Float> p = it.next();
|
||||
double weight = 1/(p.distance + 0.1);
|
||||
bullHist[0][i] = weight;
|
||||
bullHist[1][i] = p.payload;
|
||||
i++;
|
||||
}
|
||||
double maxScore = 0;
|
||||
double maxPower = 2;
|
||||
for(int j = 0; j < i; j++){
|
||||
double score = 0;
|
||||
for(int k = 0; k < j; k++)
|
||||
score += bullHist[0][k]/(sqr(bullHist[1][j] - bullHist[1][k]) + 0.1);
|
||||
for(int k = j+1; k < i; k++)
|
||||
score += bullHist[0][k]/(sqr(bullHist[1][j] - bullHist[1][k]) + 0.1);
|
||||
score *= bullHist[0][j];
|
||||
|
||||
if(score > maxScore){
|
||||
maxScore = score;
|
||||
maxPower = bullHist[1][j];
|
||||
}
|
||||
}
|
||||
|
||||
return maxPower;
|
||||
}
|
||||
double sqr(double d){
|
||||
return d*d;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package jk.mega;
|
||||
import java.awt.geom.*;
|
||||
|
||||
|
||||
public class DataToGun{
|
||||
|
||||
public Point2D.Double futurePoint = new Point2D.Double();
|
||||
public double futureVelocity, futureHeading, enemyBP;
|
||||
public int timeInFuture;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package jk.mega;
|
||||
|
||||
import robocode.*;
|
||||
import jk.mega.dGun.*;
|
||||
import jk.mega.dMove.*;
|
||||
import jk.melee.*;
|
||||
import jk.precise.*;
|
||||
import java.io.PrintStream;
|
||||
import java.io.IOException;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrussGT extends AdvancedRobot {
|
||||
|
||||
public static final boolean TC = false;
|
||||
public static final boolean MC = false;
|
||||
public static final double SHIELD_THRESHOLD = 98;
|
||||
//train it in the movement, available for the gun to use too
|
||||
public static BulletPowerPredictor bulletPowerPredictor = new BulletPowerPredictor();
|
||||
static boolean shieldEnabled = !MC && !TC;
|
||||
public DrussMoveGT move;
|
||||
public MeleeRadar radar;
|
||||
public DrussGunDC gun;
|
||||
public EnergyDomeWorker shield;
|
||||
|
||||
public void run() {
|
||||
|
||||
setAdjustRadarForGunTurn(true);
|
||||
setAdjustRadarForRobotTurn(true);
|
||||
setAdjustGunForRobotTurn(true);
|
||||
setColors(new Color(40, 40, 0), new Color(0, 40, 0), Color.GRAY);
|
||||
if (!TC) {
|
||||
setTurnRightRadians(Double.POSITIVE_INFINITY);
|
||||
setTurnGunRightRadians(Double.POSITIVE_INFINITY);
|
||||
}
|
||||
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
|
||||
if (!TC)
|
||||
try {
|
||||
move = new DrussMoveGT(this);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
try {
|
||||
radar = new MeleeRadar(this);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
if (!MC)
|
||||
try {
|
||||
gun = new DrussGunDC(this);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (shieldEnabled)
|
||||
try {
|
||||
shield = new EnergyDomeWorker(this);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onTick(!shieldEnabled);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
try {
|
||||
radar.onTick();
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
if (!MC)
|
||||
try {
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(0,1000);
|
||||
} catch (Exception e){}
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void onScannedRobot(ScannedRobotEvent e) {
|
||||
if (!TC && !MC && shieldEnabled) {
|
||||
shieldEnabled = shield.aboveScore(SHIELD_THRESHOLD);
|
||||
if (shieldEnabled) {
|
||||
try {
|
||||
shield.onScannedRobot(e);
|
||||
shield.applyActions();
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DataToGun dtg = new DataToGun();
|
||||
if (!TC)
|
||||
try {
|
||||
move.onScannedRobot(e);
|
||||
if (!shieldEnabled)
|
||||
move.doSurfing();
|
||||
dtg = move.getGunInfo();
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
radar.onScannedRobot(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
|
||||
if (!shieldEnabled || TC) {
|
||||
Bullet b = null;
|
||||
if (!MC)
|
||||
try {
|
||||
b = gun.onScannedRobot(e, dtg.futurePoint, dtg.futureHeading, dtg.futureVelocity, dtg.timeInFuture, dtg.enemyBP, TC);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (!TC)
|
||||
try {
|
||||
move.logMyBullet(b);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onRobotDeath(RobotDeathEvent e) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onRobotDeath(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
radar.onRobotDeath(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
// try{
|
||||
// gun.onRobotDeath(e);
|
||||
// }
|
||||
// catch(Exception ex){contain(ex);}
|
||||
|
||||
}
|
||||
|
||||
public void onHitByBullet(HitByBulletEvent e) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onHitByBullet(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (shieldEnabled)
|
||||
try {
|
||||
shield.onHitByBullet(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void onHitRobot(HitRobotEvent e) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onHitRobot(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void onBulletHitBullet(BulletHitBulletEvent e) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onBulletHitBullet(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
|
||||
if (!shieldEnabled)
|
||||
try {
|
||||
gun.onBulletHitBullet(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (shieldEnabled)
|
||||
try {
|
||||
shield.onBulletHitBullet(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void onBulletHit(BulletHitEvent e) {
|
||||
if (!TC)
|
||||
try {
|
||||
move.onBulletHit(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (!shieldEnabled)
|
||||
try {
|
||||
gun.onBulletHit(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
|
||||
if (shieldEnabled)
|
||||
try {
|
||||
shield.onBulletHit(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPaint(java.awt.Graphics2D g) {
|
||||
if (!TC) move.onPaint(g);
|
||||
if (!shieldEnabled)
|
||||
gun.onPaint(g);
|
||||
}
|
||||
|
||||
public void onDeath(DeathEvent e) {
|
||||
shieldEnabled = false;
|
||||
try {
|
||||
|
||||
if (!MC) gun.onDeath(e);
|
||||
if (!TC) move.onDeath(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void onWin(WinEvent e) {
|
||||
try {
|
||||
if (!TC) move.onWin(e);
|
||||
if (!MC) gun.onWin(e);
|
||||
} catch (Exception ex) {
|
||||
contain(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void contain(Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
PrintStream out = new PrintStream(new RobocodeFileOutputStream(getDataFile((int) (Math.random() * 100) + ".error")));
|
||||
e.printStackTrace(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException ioex) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#Robocode Robot
|
||||
#Sun Sep 10 17:26:09 CEST 2017
|
||||
robot.java.source.included=false
|
||||
robot.classname=jk.mega.DrussGT
|
||||
robot.author.name=Julian Kent AKA Skilgannon
|
||||
uuid=35d3badf-5304-4ad3-8ca7-1561db0e34f1
|
||||
robocode.version=1.9.2.5
|
||||
robot.codesize=48320
|
||||
robot.description=Thou loggerheaded hasty-witted varlet\!\nUses GoTo/VCS surfing, KNN targeting and Bullet Shielding when possible\n3.1.4159\: A wild attempt to bypass the JVM8 ThreadDeath issues
|
||||
robot.version=3.1.4159
|
||||
robot.include.source=true
|
||||
@@ -0,0 +1,265 @@
|
||||
package jk.mega;
|
||||
|
||||
import jk.mega.dGun.*;
|
||||
import jk.precise.util.*;
|
||||
import robocode.*;
|
||||
import robocode.util.Utils;
|
||||
import java.awt.geom.*; // for Point2D's
|
||||
import java.lang.*; // for Double and Integer objects
|
||||
import java.util.*; // for collection of waves
|
||||
import java.awt.Color;
|
||||
//import ags.utils.*;
|
||||
import java.io.*;
|
||||
import jk.math.FastTrig;
|
||||
import jk.tree.KDTree;
|
||||
|
||||
public class EnemyMoves{
|
||||
|
||||
int predictTime;
|
||||
double dirFlip = 1;
|
||||
PointChain predictHead;
|
||||
double predictHeading,
|
||||
predictStartHeading;
|
||||
Point2D.Double predictLocation, predictStartLocation;
|
||||
Locator predictLoc;
|
||||
int maxTime;
|
||||
|
||||
ArrayList<Point2D.Double> futureLocs;// = new ArrayList<Point2D.Double>();
|
||||
|
||||
PointChain currentPoint = null;
|
||||
Locator currentLoc;
|
||||
|
||||
AdvancedRobot bot;
|
||||
|
||||
double timeSinceDecel;
|
||||
double timeSinceDirChange;
|
||||
|
||||
double lastDirection;
|
||||
double lastHeading;
|
||||
double lastVelocity = 0;
|
||||
Point2D.Double enemyLocation;
|
||||
|
||||
ArrayList<Locator> addQueue = new ArrayList<Locator>();
|
||||
|
||||
ArrayList<Point2D.Double> enemyLocations = new ArrayList<Point2D.Double>();
|
||||
|
||||
static KDTree<PointChain> tree = new KDTree.Manhattan<PointChain>(new Locator().getLocation().length);
|
||||
|
||||
|
||||
public void onScannedRobot(ScannedRobotEvent e){
|
||||
|
||||
Point2D.Double myLocation = new Point2D.Double(bot.getX(), bot.getY());
|
||||
double absBearing = bot.getHeadingRadians() + e.getBearingRadians();
|
||||
enemyLocation = project(myLocation, absBearing, e.getDistance());
|
||||
enemyLocations.add(enemyLocation);
|
||||
|
||||
double velocity = e.getVelocity();
|
||||
double heading = e.getHeadingRadians();
|
||||
double offset = Utils.normalAbsoluteAngle(heading - absBearing);
|
||||
double lateralVelocity = velocity*FastTrig.sin(offset);
|
||||
double advancingVelocity = -velocity*FastTrig.cos(offset);
|
||||
double distance = e.getDistance();
|
||||
|
||||
|
||||
double accel = 1;
|
||||
double acc = velocity - lastVelocity;
|
||||
acc = acc * Math.signum(velocity);
|
||||
|
||||
double direction = Math.signum(lateralVelocity);
|
||||
if(direction == 0)
|
||||
direction = lastDirection;
|
||||
if(direction == 0)
|
||||
direction = 1;
|
||||
|
||||
if(acc > 0)
|
||||
accel = 2;
|
||||
else if(acc < 0){
|
||||
accel = 0;
|
||||
}
|
||||
|
||||
if(accel == 0)
|
||||
timeSinceDecel = 0;
|
||||
else
|
||||
timeSinceDecel++;
|
||||
|
||||
if(direction == lastDirection)
|
||||
timeSinceDirChange++;
|
||||
else
|
||||
timeSinceDirChange = 0;
|
||||
|
||||
|
||||
double distLast10 = enemyLocation.distance(enemyLocations.get(Math.min(10,enemyLocations.size() - 1)));
|
||||
|
||||
double bulletPower = 2.95;
|
||||
double[] preciseMEAs = PreciseMinMaxGFs.getPreciseMEAs(
|
||||
enemyLocation,e.getHeadingRadians(),e.getVelocity(),
|
||||
myLocation,bulletPower,direction,
|
||||
new ArrayList(),absBearing);
|
||||
|
||||
double mea=FastTrig.asin(8.0/(20 - 3*bulletPower));
|
||||
double forwardWall = preciseMEAs[1]/mea;
|
||||
double reverseWall = preciseMEAs[0]/mea;
|
||||
double BFT = distance/(20 - 3*bulletPower);
|
||||
|
||||
Locator l = new Locator();
|
||||
l.vel = velocity;
|
||||
l.latVel = lateralVelocity;
|
||||
l.advVel = advancingVelocity;
|
||||
l.distance = distance;
|
||||
l.accel = accel;
|
||||
l.direction = direction;
|
||||
l.timeSinceDecel = timeSinceDecel;
|
||||
l.timeSinceDirChange = timeSinceDirChange;
|
||||
l.distLast10 = distLast10;
|
||||
l.forwardWall = forwardWall;
|
||||
l.reverseWall = reverseWall;
|
||||
l.BFT = BFT;
|
||||
|
||||
|
||||
PointChain npc = new PointChain();
|
||||
if(currentPoint != null)
|
||||
currentPoint.next = npc;
|
||||
npc.velocity = velocity;
|
||||
npc.deltaHeading = Utils.normalRelativeAngle(heading - lastHeading);
|
||||
currentPoint = npc;
|
||||
l.value = npc;
|
||||
|
||||
addQueue.add(l);
|
||||
|
||||
while(addQueue.size() > BFT){
|
||||
Locator arrived = addQueue.remove(0);
|
||||
tree.addPoint(arrived.getLocation(),arrived.value);
|
||||
}
|
||||
//tree.addPoint(l.getLocation(),npc);
|
||||
currentLoc = l;
|
||||
|
||||
lastDirection = direction;
|
||||
lastVelocity = velocity;
|
||||
lastHeading = heading;
|
||||
}
|
||||
|
||||
public EnemyMoves(AdvancedRobot b){
|
||||
bot = b;
|
||||
}
|
||||
|
||||
public Point2D.Double get(int time){
|
||||
if(time > maxTime)
|
||||
extend(time);
|
||||
return futureLocs.get(Math.max(0,time - predictTime));
|
||||
// if(rp == null)
|
||||
// throw new IllegalArgumentException("null in futureLocs somehow...");
|
||||
//System.out.println("Returning null from " + (time - predictTime) + " out of " + futureLocs.size());
|
||||
// return rp;
|
||||
}
|
||||
|
||||
public void extend(int time){
|
||||
int addSize = time - maxTime;
|
||||
int getIndex = 0;
|
||||
for(int i = 0; i < addSize; i++){
|
||||
// if(predictHead == null){
|
||||
// getIndex = getIndex + 1;
|
||||
// if(getIndex > tree.size()){
|
||||
// for(int j = i; j < addSize; j++)
|
||||
// futureLocs.add(predictLocation);
|
||||
// i = addSize;
|
||||
// }
|
||||
// else{
|
||||
// predict();
|
||||
// addSize = time - predictTime - futureLocs.size() + 1;
|
||||
// i = 0;
|
||||
// }
|
||||
// }
|
||||
if(predictHead != null){
|
||||
predictHeading += predictHead.deltaHeading;
|
||||
predictLocation = project(predictLocation,predictHeading,predictHead.velocity*dirFlip);
|
||||
predictHead = predictHead.next;
|
||||
}
|
||||
//
|
||||
// if(predictLocation == null)
|
||||
// throw new IllegalArgumentException("adding null");
|
||||
|
||||
futureLocs.add(predictLocation);
|
||||
|
||||
}
|
||||
maxTime += addSize;
|
||||
|
||||
}
|
||||
public boolean initialised(){
|
||||
return futureLocs != null;
|
||||
}
|
||||
public void predict(){
|
||||
predictLoc = currentLoc;
|
||||
predictTime = (int)bot.getTime();
|
||||
predictStartHeading = lastHeading;
|
||||
predictStartLocation = enemyLocation;
|
||||
|
||||
predict(0);
|
||||
}
|
||||
void predict(int nearIndex){
|
||||
List<KDTree.SearchResult<PointChain>> cluster = tree.nearestNeighbours(
|
||||
predictLoc.getLocation(),
|
||||
Math.min(nearIndex+1,tree.size()));
|
||||
|
||||
if(cluster.size() > 0){
|
||||
|
||||
predictHead = cluster.get(nearIndex).payload;
|
||||
dirFlip = Math.signum(predictHead.velocity) == Math.signum(predictLoc.vel)?1:-1;
|
||||
}
|
||||
futureLocs = new ArrayList<Point2D.Double>();
|
||||
predictHeading = predictStartHeading;
|
||||
predictLocation = predictStartLocation;
|
||||
maxTime = predictTime-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static class PointChain{
|
||||
PointChain next;
|
||||
double velocity, deltaHeading;
|
||||
}
|
||||
static class Locator{
|
||||
PointChain value;
|
||||
double vel,
|
||||
latVel,
|
||||
advVel,
|
||||
//offset,
|
||||
distance,
|
||||
accel,
|
||||
direction,
|
||||
timeSinceDecel,
|
||||
timeSinceDirChange,
|
||||
distLast10,
|
||||
forwardWall,
|
||||
reverseWall,
|
||||
BFT;
|
||||
double[] getLocation(){
|
||||
final double[] w = { 0.6060732907019181, 1.4406808733244607, 0.954563646088063, 0.1628041961645823, 0.6851868785430317, 1.0573331814261329, 1.249422570480633, 0.6582714590108382, 0.8855547253444055, 0.6263796249347, 1.2375289235449662, 1.0494098503354718, 0.17921500418340133, 0.20756520159004618, 0.50948425222709, 0.7157847310917926};
|
||||
return new double[]{
|
||||
Math.abs(latVel/8)*10*w[0],
|
||||
limit(0,advVel/16 + 0.5,1)*2*w[1],
|
||||
limit(0,distance/900,1)*5*w[2],
|
||||
accel/2.0*10*w[3],
|
||||
limit(0,distLast10/(8*10),1)*3*w[4],
|
||||
limit(0,forwardWall,1)*5*w[5],
|
||||
limit(0,reverseWall,1)*2*w[6],
|
||||
1/(1 + 2*timeSinceDirChange/BFT) * 3*w[7],
|
||||
1/(1 + 2*timeSinceDecel/BFT)*3*w[8]
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static Point2D.Double project(Point2D.Double sourceLocation, double angle, double length) {
|
||||
return new Point2D.Double(sourceLocation.x + FastTrig.sin(angle) * length,
|
||||
sourceLocation.y + FastTrig.cos(angle) * length);
|
||||
}
|
||||
|
||||
public static double limit(double min, double val, double max){
|
||||
return Math.max(min,Math.min(val,max));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package jk.mega;
|
||||
|
||||
public class Insulter{
|
||||
public static String getInsult(){
|
||||
String word1 = column1[(int)(column1.length*Math.random())];
|
||||
String word2 = column2[(int)(column2.length*Math.random())];
|
||||
String word3 = column3[(int)(column3.length*Math.random())];
|
||||
return ("Thou " + word1 + " " + word2 + " " + word3 + "!");
|
||||
}
|
||||
static final String[] column1 = {
|
||||
"artless",
|
||||
"bawdy",
|
||||
"beslubbering",
|
||||
"bootless",
|
||||
"churlish",
|
||||
"cockered",
|
||||
"clouted",
|
||||
"craven",
|
||||
"currish",
|
||||
"dankish",
|
||||
"dissembling",
|
||||
"droning",
|
||||
"errant",
|
||||
"fawning",
|
||||
"fobbing",
|
||||
"froward",
|
||||
"frothy",
|
||||
"gleeking",
|
||||
"goatish",
|
||||
"gorbellied",
|
||||
"impertinent",
|
||||
"infectious",
|
||||
"jarring",
|
||||
"loggerheaded",
|
||||
"lumpish",
|
||||
"mammering",
|
||||
"mangled",
|
||||
"mewling",
|
||||
"paunchy",
|
||||
"pribbling",
|
||||
"puking",
|
||||
"puny",
|
||||
"qualling",
|
||||
"rank",
|
||||
"reeky",
|
||||
"roguish",
|
||||
"ruttish",
|
||||
"saucy",
|
||||
"spleeny",
|
||||
"spongy",
|
||||
"surly",
|
||||
"tottering",
|
||||
"unmuzzled",
|
||||
"vain",
|
||||
"venomed",
|
||||
"villainous",
|
||||
"warped",
|
||||
"wayward",
|
||||
"weedy",
|
||||
"yeasty"};
|
||||
static final String[] column2 = {
|
||||
"base-court",
|
||||
"bat-fowling",
|
||||
"beef-witted",
|
||||
"beetle-headed",
|
||||
"boil-brained",
|
||||
"clapper-clawed",
|
||||
"clay-brained",
|
||||
"common-kissing",
|
||||
"crook-pated",
|
||||
"dismal-dreaming",
|
||||
"dizzy-eyed",
|
||||
"doghearted",
|
||||
"dread-bolted",
|
||||
"earth-vexing",
|
||||
"elf-skinned",
|
||||
"fat-kidneyed",
|
||||
"fen-sucked",
|
||||
"flap-mouthed",
|
||||
"fly-bitten",
|
||||
"folly-fallen",
|
||||
"fool-born",
|
||||
"full-gorged",
|
||||
"guts-griping",
|
||||
"half-faced",
|
||||
"hasty-witted",
|
||||
"hedge-born",
|
||||
"hell-hated",
|
||||
"idle-headed",
|
||||
"ill-breeding",
|
||||
"ill-nurtured",
|
||||
"knotty-pated",
|
||||
"milk-livered",
|
||||
"motley-minded",
|
||||
"onion-eyed",
|
||||
"plume-plucked",
|
||||
"pottle-deep",
|
||||
"pox-marked",
|
||||
"reeling-ripe",
|
||||
"rough-hewn",
|
||||
"rude-growing",
|
||||
"rump-fed",
|
||||
"shard-borne",
|
||||
"sheep-biting",
|
||||
"spur-galled",
|
||||
"swag-bellied",
|
||||
"tardy-gaited",
|
||||
"tickle-brained",
|
||||
"toad-spotted",
|
||||
"unchin -snouted",
|
||||
"weather-bitten"};
|
||||
static final String[] column3 = {
|
||||
"apple-john",
|
||||
"baggage",
|
||||
"barnacle",
|
||||
"bladder",
|
||||
"boar-pig",
|
||||
"bugbear",
|
||||
"bum-bailey",
|
||||
"canker-blossom",
|
||||
"clack-dish",
|
||||
"clotpole",
|
||||
"coxcomb",
|
||||
"codpiece",
|
||||
"death-token",
|
||||
"dewberry",
|
||||
"flap-dragon",
|
||||
"flax-wench",
|
||||
"flirt-gill",
|
||||
"foot-licker",
|
||||
"fustilarian",
|
||||
"giglet",
|
||||
"gudgeon",
|
||||
"haggard",
|
||||
"harpy",
|
||||
"hedge-pig",
|
||||
"horn-beast",
|
||||
"hugger-mugger",
|
||||
"joithead",
|
||||
"lewdster",
|
||||
"lout",
|
||||
"maggot-pie",
|
||||
"malt-worm",
|
||||
"mammet",
|
||||
"measle",
|
||||
"minnow",
|
||||
"miscreant",
|
||||
"moldwarp",
|
||||
"mumble-news",
|
||||
"nut-hook",
|
||||
"pigeon-egg",
|
||||
"pignut",
|
||||
"puttock",
|
||||
"pumpion",
|
||||
"ratsbane",
|
||||
"scut",
|
||||
"skainsmate",
|
||||
"strumpet",
|
||||
"varlet",
|
||||
"vassal",
|
||||
"whey-face",
|
||||
"wagtail"};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
package jk.mega.dGun;
|
||||
public class GFRange implements Comparable{
|
||||
double max = -1,min = 1,center = 0,width = 0;
|
||||
public int compareTo(Object g){
|
||||
if(center < ((GFRange)g).center)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package jk.mega.dGun;
|
||||
class Indice implements Comparable{
|
||||
double position, height;
|
||||
public int compareTo(Object o){
|
||||
// if(((Indice)o).position > position)
|
||||
// return -1;
|
||||
// return 1;
|
||||
return (int)Math.signum(position - ((Indice)o).position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package jk.mega.dGun;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import jk.mega.*;
|
||||
import java.util.ArrayList;
|
||||
import robocode.util.Utils;
|
||||
import jk.math.FastTrig;
|
||||
|
||||
public class PreciseMinMaxGFs{
|
||||
|
||||
static double MARGIN = 18;
|
||||
static double WIDTH = 800;
|
||||
static double HEIGHT = 600;
|
||||
public static double[] getPreciseMEAs(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
double rotationDirection,
|
||||
ArrayList<Point2D.Double> pointsList,
|
||||
double GF0){
|
||||
|
||||
ArrayList<Point2D.Double> endPoints = getEndPoints(
|
||||
enemyLocation,
|
||||
enemyHeading,
|
||||
enemyVelocity,
|
||||
myLocation,
|
||||
bulletPower,
|
||||
pointsList);
|
||||
// pointsList.addAll(endPoints);
|
||||
double negAngle = 1;
|
||||
double posAngle = -1;
|
||||
|
||||
for(int i = endPoints.size()-1; i >= 0; i--){
|
||||
double offset = FastTrig.normalRelativeAngle(absoluteBearing(myLocation,endPoints.get(i))
|
||||
- GF0);
|
||||
double distance = myLocation.distance(endPoints.get(i));
|
||||
double halfWidth = 20/distance;
|
||||
|
||||
if(offset - halfWidth < negAngle)
|
||||
negAngle = offset - halfWidth;
|
||||
|
||||
if(offset+halfWidth > posAngle)
|
||||
posAngle = offset+halfWidth;
|
||||
}
|
||||
if(rotationDirection == 1)
|
||||
return new double[]{-negAngle,posAngle};
|
||||
return new double[]{posAngle,-negAngle};
|
||||
}
|
||||
public static double getPreciseGF0(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
double rotationDirection){
|
||||
double vel = enemyVelocity;
|
||||
Point2D.Double loc = enemyLocation;
|
||||
while(Math.abs(vel) > 0.01){
|
||||
|
||||
vel = Math.signum(vel)*(Math.abs(vel) - Math.min(Math.abs(vel),2));
|
||||
loc = project(loc,enemyHeading,vel);
|
||||
|
||||
}
|
||||
return absoluteBearing(myLocation,loc);
|
||||
}
|
||||
static ArrayList<Point2D.Double> getEndPoints(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
ArrayList<Point2D.Double> pointsList
|
||||
){
|
||||
ArrayList<Point2D.Double> endPoints = new ArrayList<Point2D.Double>();
|
||||
|
||||
Point2D.Double[] elocs = getSmoothedEndPoints(enemyLocation,enemyHeading,enemyVelocity,myLocation,bulletPower, pointsList);
|
||||
for(int i = 0; i < elocs.length; i++)
|
||||
endPoints.add(elocs[i]);
|
||||
|
||||
elocs = getDirectEndPoints(enemyLocation,enemyHeading,enemyVelocity,myLocation,bulletPower, endPoints, pointsList);
|
||||
for(int i = 0; i < elocs.length; i++)
|
||||
endPoints.add(elocs[i]);
|
||||
|
||||
elocs = getStraightEndPoints(enemyLocation,enemyHeading,enemyVelocity,myLocation,bulletPower, pointsList);
|
||||
for(int i = 0; i < elocs.length; i++)
|
||||
endPoints.add(elocs[i]);
|
||||
|
||||
return endPoints;
|
||||
}
|
||||
|
||||
static Point2D.Double[] getSmoothedEndPoints(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
ArrayList<Point2D.Double> pointsList){
|
||||
Point2D.Double[] locs = new Point2D.Double[2];
|
||||
double bulletVelocity = 20 - 3*bulletPower;
|
||||
for(int i = -1; i < 2; i+=2){
|
||||
double angle = enemyHeading + (Math.PI/2)*(i-1);
|
||||
double vel = i*enemyVelocity;
|
||||
Point2D.Double eloc = (Point2D.Double)enemyLocation.clone();
|
||||
double bulletDistance = 0;
|
||||
double goalAngle = absoluteBearing(myLocation,eloc) + Math.PI/2;
|
||||
if(FastTrig.cos(goalAngle - angle) < 0)
|
||||
goalAngle += Math.PI;
|
||||
while(bulletDistance < eloc.distance(myLocation)){
|
||||
Point2D.Double testPoint = project(eloc,goalAngle,120);
|
||||
double testBearing = absoluteBearing(myLocation,testPoint);
|
||||
double testDistance = testPoint.distance(myLocation);
|
||||
int limit = 20;
|
||||
while((MARGIN > testPoint.x || testPoint.x > WIDTH - MARGIN ||
|
||||
MARGIN > testPoint.y || testPoint.y > HEIGHT - MARGIN)
|
||||
&& --limit > 0){
|
||||
testDistance *= 0.95;
|
||||
testPoint = project(myLocation,testBearing,testDistance);
|
||||
}
|
||||
double maxTurn = Math.PI/18 - Math.PI/240*Math.abs(vel);
|
||||
double smoothAngle = absoluteBearing(eloc,testPoint);
|
||||
double wantTurn = FastTrig.normalRelativeAngle(smoothAngle - angle);
|
||||
angle = limit(angle - maxTurn, angle + wantTurn, angle + maxTurn);
|
||||
if(vel < 0)
|
||||
vel += 2;
|
||||
else
|
||||
vel = Math.min(8,vel+1);
|
||||
|
||||
//Point2D.Double nextLoc = project(eloc,angle,vel);
|
||||
double dx = FastTrig.sin(angle)*vel;
|
||||
double dy = FastTrig.cos(angle)*vel;
|
||||
eloc.x += dx;
|
||||
eloc.y += dy;
|
||||
if(eloc.x > WIDTH - MARGIN || eloc.x < MARGIN
|
||||
|| eloc.y > HEIGHT - MARGIN || eloc.y < MARGIN){
|
||||
eloc.x -= dx;
|
||||
eloc.y -= dy;
|
||||
break;
|
||||
}
|
||||
//eloc = nextLoc;
|
||||
if(pointsList != null)
|
||||
pointsList.add((Point2D.Double)eloc.clone());
|
||||
bulletDistance += bulletVelocity;
|
||||
}
|
||||
locs[(i+1)/2] = eloc;
|
||||
}
|
||||
return locs;
|
||||
}
|
||||
static Point2D.Double[] getDirectEndPoints(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
ArrayList<Point2D.Double> prevLocs,
|
||||
ArrayList<Point2D.Double> pointsList){
|
||||
Point2D.Double[] locs = new Point2D.Double[2];
|
||||
double bulletVelocity = 20 - 3*bulletPower;
|
||||
for(int i = -1; i < 2; i+=2){
|
||||
double angle = enemyHeading + (Math.PI/2)*(i-1);
|
||||
double vel = i*enemyVelocity;
|
||||
Point2D.Double eloc = (Point2D.Double)enemyLocation.clone();
|
||||
double bulletDistance = 0;
|
||||
double goalAngle = absoluteBearing(eloc,prevLocs.get((i+1)/2));
|
||||
//if(FastTrig.cos(goalAngle - angle) < 0)
|
||||
//goalAngle += Math.PI;
|
||||
while(bulletDistance < eloc.distance(myLocation)){
|
||||
Point2D.Double testPoint = project(eloc,goalAngle,90);
|
||||
double testBearing = absoluteBearing(myLocation,testPoint);
|
||||
double testDistance = testPoint.distance(myLocation);
|
||||
int limit = 20;
|
||||
while((MARGIN > testPoint.x || testPoint.x > WIDTH - MARGIN ||
|
||||
MARGIN > testPoint.y || testPoint.y > HEIGHT - MARGIN)
|
||||
&& --limit > 0){
|
||||
testDistance *= 0.95;
|
||||
testPoint = project(myLocation,testBearing,testDistance);
|
||||
}
|
||||
double maxTurn = Math.PI/18 - Math.PI/240*Math.abs(vel);
|
||||
double smoothAngle = absoluteBearing(eloc,testPoint);
|
||||
double wantTurn = FastTrig.normalRelativeAngle(smoothAngle - angle);
|
||||
angle = limit(angle - maxTurn, angle + wantTurn, angle + maxTurn);
|
||||
if(vel < 0)
|
||||
vel += 2;
|
||||
else
|
||||
vel = Math.min(8,vel+1);
|
||||
|
||||
double dx = FastTrig.sin(angle)*vel;
|
||||
double dy = FastTrig.cos(angle)*vel;
|
||||
eloc.x += dx;
|
||||
eloc.y += dy;
|
||||
if(eloc.x > WIDTH - MARGIN || eloc.x < MARGIN
|
||||
|| eloc.y > HEIGHT - MARGIN || eloc.y < MARGIN){
|
||||
eloc.x -= dx;
|
||||
eloc.y -= dy;
|
||||
break;
|
||||
}
|
||||
//eloc = nextLoc;
|
||||
if(pointsList != null)
|
||||
pointsList.add((Point2D.Double)eloc.clone());
|
||||
bulletDistance += bulletVelocity;
|
||||
}
|
||||
locs[(i+1)/2] = eloc;
|
||||
}
|
||||
return locs;
|
||||
}
|
||||
static Point2D.Double[] getStraightEndPoints(
|
||||
Point2D.Double enemyLocation,
|
||||
double enemyHeading,
|
||||
double enemyVelocity,
|
||||
Point2D.Double myLocation,
|
||||
double bulletPower,
|
||||
ArrayList<Point2D.Double> pointsList){
|
||||
Point2D.Double[] locs = new Point2D.Double[2];
|
||||
double bulletVelocity = 20 - 3*bulletPower;
|
||||
for(int i = -1; i < 2; i+=2){
|
||||
double angle = enemyHeading + (Math.PI/2)*(i-1);
|
||||
double vel = i*enemyVelocity;
|
||||
Point2D.Double eloc = (Point2D.Double)enemyLocation.clone();
|
||||
double bulletDistance = 0;
|
||||
double goalAngle = absoluteBearing(myLocation,eloc) + Math.PI/2;
|
||||
if(FastTrig.cos(goalAngle - angle) < 0)
|
||||
goalAngle += Math.PI;
|
||||
while(bulletDistance < eloc.distance(myLocation)){
|
||||
double maxTurn = Math.PI/18 - Math.PI/240*Math.abs(vel);
|
||||
double wantTurn = FastTrig.normalRelativeAngle(goalAngle - angle);
|
||||
angle = limit(angle - maxTurn, angle + wantTurn, angle + maxTurn);
|
||||
if(vel < 0)
|
||||
vel += 2;
|
||||
else
|
||||
vel = Math.min(8,vel+1);
|
||||
|
||||
double dx = FastTrig.sin(angle)*vel;
|
||||
double dy = FastTrig.cos(angle)*vel;
|
||||
eloc.x += dx;
|
||||
eloc.y += dy;
|
||||
if(eloc.x > WIDTH - MARGIN || eloc.x < MARGIN
|
||||
|| eloc.y > HEIGHT - MARGIN || eloc.y < MARGIN){
|
||||
eloc.x -= dx;
|
||||
eloc.y -= dy;
|
||||
break;
|
||||
}
|
||||
//eloc = nextLoc;
|
||||
if(pointsList != null)
|
||||
pointsList.add((Point2D.Double)eloc.clone());
|
||||
|
||||
bulletDistance += bulletVelocity;
|
||||
}
|
||||
locs[(i+1)/2] = eloc;
|
||||
}
|
||||
return locs;
|
||||
}
|
||||
static Point2D.Double project(Point2D.Double p, double angle, double distance){
|
||||
return new Point2D.Double(p.x + distance*FastTrig.sin(angle), p.y + distance*FastTrig.cos(angle));
|
||||
}
|
||||
public static double absoluteBearing(Point2D.Double source, Point2D.Double target) {
|
||||
return FastTrig.atan2(target.x - source.x, target.y - source.y);
|
||||
}
|
||||
public static double limit(double min, double value, double max) {
|
||||
if(value > max)
|
||||
return max;
|
||||
if(value < min)
|
||||
return min;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package jk.mega.dMove;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
import robocode.*;
|
||||
|
||||
|
||||
public class BulletTracker{
|
||||
Bullet b;
|
||||
Point2D.Double startLocation;
|
||||
long fireTime;
|
||||
ArrayList<EnemyWave> crossedWaves = new ArrayList<EnemyWave>();
|
||||
boolean flattenerLogged = false;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
package jk.mega.dMove;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
import robocode.*;
|
||||
|
||||
import jk.precise.util.*;
|
||||
import jk.mega.*;
|
||||
import jk.math.FastTrig;
|
||||
|
||||
public class EnemyWave {
|
||||
Point2D.Double fireLocation;
|
||||
long fireTime;
|
||||
double bulletVelocity, directAngle, distanceTraveled;
|
||||
int direction;
|
||||
ArrayList allStats;
|
||||
ArrayList flattenerStats;
|
||||
ArrayList ABSStats;
|
||||
ArrayList flattenerTickStats;
|
||||
boolean flattenerLogged = false;
|
||||
float[] bestBins;
|
||||
float[] binCleared;
|
||||
ArrayList safePoints;
|
||||
PlaceTime safestPoint;
|
||||
|
||||
int[][] indexes;
|
||||
|
||||
boolean bulletGone = false;
|
||||
boolean imaginary = false;
|
||||
boolean futureWave = false;
|
||||
|
||||
float weight = 0;
|
||||
|
||||
Scan scan;
|
||||
|
||||
//used for second-wave surfing
|
||||
ArrayList possPoints;
|
||||
PlaceTime possSafePT;
|
||||
|
||||
public EnemyWave() { }
|
||||
|
||||
static final int BINS = 171;
|
||||
static final int MIDDLE_BIN = (BINS - 1)/2;
|
||||
|
||||
public boolean logShadow(double time, BulletTracker bt){
|
||||
Bullet b = bt.b;
|
||||
double t = 0;
|
||||
Point2D.Double currentbP = new Point2D.Double(b.getX(), b.getY());
|
||||
boolean change = false;
|
||||
if(binCleared == null){
|
||||
binCleared = new float[BINS];
|
||||
for(int k = 0; k < BINS; k++)
|
||||
binCleared[k] = 1;
|
||||
}
|
||||
while(true){
|
||||
t++;
|
||||
|
||||
Point2D.Double bP = project(currentbP,b.getHeadingRadians(),b.getVelocity()*(t+1));
|
||||
Point2D.Double lastbP = project(currentbP,b.getHeadingRadians(),b.getVelocity()*t);
|
||||
|
||||
double en = bP.distance(fireLocation);
|
||||
double len = lastbP.distance(fireLocation);
|
||||
|
||||
double actDistTrav = bulletVelocity*(time - fireTime + t);
|
||||
double lastDistTraveled = bulletVelocity*(time - fireTime + t-1);
|
||||
if( len < lastDistTraveled | len < en )
|
||||
return change;
|
||||
|
||||
if( en < actDistTrav & len > lastDistTraveled & en < len ){
|
||||
//we have intersection!
|
||||
// 4 cases:
|
||||
//1: closer to me
|
||||
//2: closer to enemy
|
||||
//3: overlaps entire wave
|
||||
//4: contained within wave
|
||||
|
||||
Point2D.Double p1, p2;
|
||||
|
||||
if(en >= lastDistTraveled)// 1 & 4
|
||||
p1 = bP;
|
||||
else{// 2 & 3
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLocation;
|
||||
wv.distanceTraveled = lastDistTraveled;
|
||||
p1 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
if(len > actDistTrav){//1 & 3
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLocation;
|
||||
wv.distanceTraveled = actDistTrav;
|
||||
p2 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
else // 2 & 4
|
||||
p2 = lastbP;
|
||||
|
||||
double i1 = getFactorIndex(p1);
|
||||
double i2 = getFactorIndex(p2);
|
||||
double lowIndex = limit(0,Math.min(i1,i2),BINS);
|
||||
double highIndex = limit(-1,Math.max(i1,i2),BINS-1);
|
||||
|
||||
if(lowIndex == BINS | highIndex == -1)
|
||||
continue;
|
||||
|
||||
|
||||
int k = (int)Math.ceil(lowIndex), m = (int)Math.floor(highIndex);
|
||||
for(; k <= m; k++)
|
||||
binCleared[k] = 0;
|
||||
if(k > 0)
|
||||
binCleared[k-1] = (float)Math.max(0,binCleared[k-1] - k + lowIndex);
|
||||
if(m < BINS-1)
|
||||
binCleared[m+1] = (float)Math.max(0,binCleared[m+1] - highIndex + m);
|
||||
|
||||
int index = bt.crossedWaves.indexOf(this);
|
||||
if(index == -1)
|
||||
bt.crossedWaves.add(this);
|
||||
|
||||
if(bestBins != null)
|
||||
change = true;
|
||||
}
|
||||
}
|
||||
|
||||
//return change;
|
||||
}
|
||||
public boolean clearShadow(double time, BulletTracker bt){
|
||||
|
||||
Bullet b = bt.b;
|
||||
double t = 0;
|
||||
Point2D.Double currentbP = new Point2D.Double(b.getX(), b.getY());
|
||||
boolean change = false;
|
||||
if(binCleared == null){
|
||||
binCleared = new float[BINS];
|
||||
for(int k = 0; k < BINS; k++)
|
||||
binCleared[k] = 1;
|
||||
}
|
||||
|
||||
while(true){
|
||||
t++;
|
||||
|
||||
Point2D.Double bP = project(currentbP,b.getHeadingRadians(),b.getVelocity()*(t+1));
|
||||
Point2D.Double lastbP = project(currentbP,b.getHeadingRadians(),b.getVelocity()*t);
|
||||
|
||||
double en = bP.distance(fireLocation);
|
||||
double len = lastbP.distance(fireLocation);
|
||||
|
||||
double actDistTrav = bulletVelocity*(time - fireTime + t);
|
||||
double lastDistTraveled = bulletVelocity*(time - fireTime + t-1);
|
||||
if( len < lastDistTraveled | len < en )
|
||||
return change;
|
||||
|
||||
if( en < actDistTrav & len > lastDistTraveled & en < len ){
|
||||
//we have intersection!
|
||||
// 4 cases:
|
||||
//1: closer to me
|
||||
//2: closer to enemy
|
||||
//3: overlaps entire wave
|
||||
//4: contained within wave
|
||||
Point2D.Double p1, p2;
|
||||
|
||||
if(en >= lastDistTraveled)
|
||||
p1 = bP;
|
||||
else{
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLocation;
|
||||
wv.distanceTraveled = lastDistTraveled;
|
||||
p1 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
if(len > actDistTrav){
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLocation;
|
||||
wv.distanceTraveled = actDistTrav;
|
||||
p2 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
else
|
||||
p2 = lastbP;
|
||||
|
||||
double i1 = getFactorIndex(p1);
|
||||
double i2 = getFactorIndex(p2);
|
||||
double lowIndex = limit(0,Math.min(i1,i2),BINS);
|
||||
double highIndex = limit(-1,Math.max(i1,i2),BINS-1);
|
||||
|
||||
if(lowIndex == BINS || highIndex == -1)
|
||||
continue;
|
||||
|
||||
|
||||
int k = (int)Math.ceil(lowIndex), m = (int)Math.floor(highIndex);
|
||||
for(; k <= m; k++)
|
||||
binCleared[k] = 1;
|
||||
if(k > 0)
|
||||
binCleared[k-1] = (float)Math.min(1,binCleared[k-1] + k - lowIndex);
|
||||
if(m < BINS-1)
|
||||
binCleared[m+1] = (float)Math.min(1,binCleared[m+1] + highIndex - m);
|
||||
if(bt != null){
|
||||
int index = bt.crossedWaves.indexOf(this);
|
||||
if(index != -1){
|
||||
bt.crossedWaves.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
if(bestBins != null)
|
||||
change = true;
|
||||
}
|
||||
}
|
||||
//return change;
|
||||
}
|
||||
|
||||
public double getFactorIndex(Point2D.Double targetLocation) {
|
||||
double absAngle = absoluteBearing(fireLocation, targetLocation);
|
||||
return getFactorIndex(absAngle);
|
||||
}
|
||||
public double getFactorIndex(double absoluteBearing) {
|
||||
double offsetAngle = (absoluteBearing - directAngle);
|
||||
double factor = FastTrig.normalRelativeAngle(offsetAngle)
|
||||
/ maxEscapeAngle() * direction;
|
||||
|
||||
return limit(0,(0.9*factor * ((BINS - 1) / 2)) + ((BINS - 1) / 2),BINS-1);
|
||||
}
|
||||
|
||||
public double maxEscapeAngle() {
|
||||
return FastTrig.asin(8.0/bulletVelocity);
|
||||
}
|
||||
|
||||
|
||||
private static double absoluteBearing(Point2D source, Point2D target) {
|
||||
return FastTrig.atan2(target.getX() - source.getX(), target.getY() - source.getY());
|
||||
}
|
||||
private static Point2D.Double project(Point2D.Double sourceLocation, double angle, double length) {
|
||||
return new Point2D.Double(sourceLocation.x + FastTrig.sin(angle) * length,
|
||||
sourceLocation.y + FastTrig.cos(angle) * length);
|
||||
}
|
||||
public static double limit(double min, double value, double max) {
|
||||
if(value > max)
|
||||
return max;
|
||||
if(value < min)
|
||||
return min;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
package jk.mega.dMove;
|
||||
import java.awt.geom.*;
|
||||
import jk.precise.util.*;
|
||||
import jk.math.FastTrig;
|
||||
|
||||
public class MovePredictor{
|
||||
|
||||
Point2D.Double fromLocation;
|
||||
Point2D.Double toLocation;
|
||||
double initialVelocity, initialHeading;
|
||||
long currentTime;
|
||||
EnemyWave wave;
|
||||
|
||||
double bearing,velocity,distanceRemaining, heading ;
|
||||
int time;
|
||||
|
||||
Point2D.Double endPoint;
|
||||
int counter;
|
||||
double sinVal , cosVal;
|
||||
boolean inline;
|
||||
|
||||
public MovePredictor(){}
|
||||
|
||||
public MovePredictor(
|
||||
Point2D.Double fromLocation,
|
||||
Point2D.Double toLocation,
|
||||
double initialVelocity,
|
||||
double initialHeading,
|
||||
long currentTime,
|
||||
EnemyWave wave){
|
||||
|
||||
recycle(fromLocation,toLocation,initialVelocity,initialHeading,currentTime,wave);
|
||||
}
|
||||
|
||||
public void recycle (
|
||||
Point2D.Double fromLocation,
|
||||
Point2D.Double toLocation,
|
||||
double initialVelocity,
|
||||
double initialHeading,
|
||||
long currentTime,
|
||||
EnemyWave wave){
|
||||
|
||||
this.fromLocation = fromLocation;
|
||||
this.toLocation = toLocation;
|
||||
this.initialVelocity = initialVelocity;
|
||||
this.initialHeading = initialHeading;
|
||||
this.currentTime = currentTime;
|
||||
this.wave = wave;
|
||||
|
||||
|
||||
bearing = absoluteBearing(fromLocation,toLocation);
|
||||
velocity = initialVelocity;
|
||||
distanceRemaining = fromLocation.distance(toLocation);;
|
||||
time = (int)(currentTime - wave.fireTime);
|
||||
heading = initialHeading;
|
||||
|
||||
endPoint = (Point2D.Double)fromLocation.clone();
|
||||
counter = 5 + (int)Math.ceil(endPoint.distance(wave.fireLocation)/(wave.bulletVelocity-8)) - time;
|
||||
sinVal = 0;
|
||||
cosVal = 0;
|
||||
inline = false;
|
||||
}
|
||||
|
||||
|
||||
public PredictionStatus predictToIntersection(){
|
||||
|
||||
while(notIntersectedEarlyExit()){
|
||||
predict();
|
||||
}
|
||||
|
||||
if(counter == 0)
|
||||
System.out.println("PREVENTED PREDICTION FREEZE!!");
|
||||
|
||||
time = (int)(endPoint.distance(wave.fireLocation)/wave.bulletVelocity) + (int)wave.fireTime;
|
||||
|
||||
return new PredictionStatus(endPoint,velocity,FastTrig.normalAbsoluteAngle(heading),time,distanceRemaining);
|
||||
}
|
||||
public PredictionStatus predictToPreciseIntersection(){
|
||||
|
||||
|
||||
while(notQuiteIntersected()){
|
||||
predict();
|
||||
}
|
||||
double[] intersectionIndices = {(double)EnemyWave.BINS,0.0};
|
||||
|
||||
PreciseWave pw = new PreciseWave();
|
||||
pw.fireLocation = wave.fireLocation;
|
||||
pw.bulletVelocity = wave.bulletVelocity;
|
||||
|
||||
while(notIntersectedEarlyExit()){
|
||||
predict();
|
||||
updatePreciseRange(pw,intersectionIndices);
|
||||
}
|
||||
PredictionStatus hitStatus =
|
||||
new PredictionStatus(endPoint,velocity,FastTrig.normalAbsoluteAngle(heading),
|
||||
time,distanceRemaining,intersectionIndices);
|
||||
|
||||
do{
|
||||
predict();
|
||||
}while(--counter != 0 && updatePreciseRange(pw,intersectionIndices) != PreciseUtils.PASSED);
|
||||
|
||||
if(counter == 0)
|
||||
System.out.println("PREVENTED PREDICTION FREEZE!!");
|
||||
time = (int)(endPoint.distance(wave.fireLocation)/wave.bulletVelocity) + (int)wave.fireTime;
|
||||
|
||||
hitStatus.time = time;
|
||||
return hitStatus;
|
||||
}
|
||||
int updatePreciseRange(PreciseWave pw, double[] intersectionIndices){
|
||||
pw.distanceTraveled = wave.bulletVelocity*time;
|
||||
int code = PreciseUtils.intersects(endPoint,pw);
|
||||
if(code == PreciseUtils.INTERSECTION){
|
||||
double[] angleRange = PreciseUtils.getIntersectionRange(endPoint,pw);
|
||||
double[] indexes = {wave.getFactorIndex(angleRange[0]),wave.getFactorIndex(angleRange[1])};
|
||||
if(indexes[1] < indexes[0]){
|
||||
double temp = indexes[0];
|
||||
indexes[0] = indexes[1];
|
||||
indexes[1] = temp;
|
||||
}
|
||||
intersectionIndices[0] = Math.min(intersectionIndices[0],indexes[0]);
|
||||
intersectionIndices[1] = Math.max(intersectionIndices[1],indexes[1]);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void predict(){
|
||||
time++;
|
||||
if(!inline & (distanceRemaining > 1 | Math.abs(velocity) > 0.1))
|
||||
{
|
||||
double maxTurn = Math.PI/18 - Math.PI/240*Math.abs(velocity);
|
||||
bearing = absoluteBearing(endPoint,toLocation);
|
||||
double offset = FastTrig.normalRelativeAngle(bearing - heading);
|
||||
if(-Math.PI/2 > offset | offset > Math.PI/2){
|
||||
offset = FastTrig.normalRelativeAngle(offset + Math.PI);
|
||||
velocity = -velocity;
|
||||
heading += Math.PI;
|
||||
}
|
||||
offset = limit(-maxTurn,offset,maxTurn);
|
||||
heading += offset;
|
||||
sinVal = FastTrig.sin(heading);
|
||||
cosVal = FastTrig.cos(heading);
|
||||
if(-0.0001 < offset & offset < 0.0001)
|
||||
inline = true;
|
||||
}
|
||||
|
||||
velocity = getNewVelocity(velocity, distanceRemaining);
|
||||
|
||||
endPoint.x += sinVal*velocity;
|
||||
endPoint.y += cosVal*velocity;
|
||||
|
||||
/*if(endPoint.x < W
|
||||
| endPoint.x > E
|
||||
| endPoint.y < S
|
||||
| endPoint.y > N){
|
||||
|
||||
velocity = 0;
|
||||
|
||||
endPoint.x -= sinVal*velocity;
|
||||
endPoint.y -= cosVal*velocity;
|
||||
|
||||
}*/
|
||||
|
||||
if(velocity > distanceRemaining)
|
||||
inline = false;
|
||||
if(inline)
|
||||
distanceRemaining = Math.abs(distanceRemaining - velocity);
|
||||
else
|
||||
distanceRemaining = endPoint.distance(toLocation);
|
||||
}
|
||||
boolean notIntersectedEarlyExit(){
|
||||
return endPoint.distanceSq(wave.fireLocation) > sqr(wave.bulletVelocity*(time+1))
|
||||
& (Math.abs(distanceRemaining) > 0.1 || Math.abs(velocity) > 0.1)
|
||||
& --counter != 0;
|
||||
}
|
||||
boolean notQuiteIntersected(){
|
||||
return endPoint.distanceSq(wave.fireLocation) > sqr(wave.bulletVelocity*(time+1) + 25.4 + 8)
|
||||
& --counter != 0;
|
||||
}
|
||||
|
||||
//3 optimized methods from the new robocode engine
|
||||
private static double getNewVelocity(double velocity, double distance) {
|
||||
if(distance < 0)
|
||||
return -getNewVelocity(-velocity,-distance);
|
||||
|
||||
final double goalVel = Math.min(getMaxVelocity(distance), 8);
|
||||
|
||||
if(velocity >= 0)
|
||||
return limit(velocity - 2,
|
||||
goalVel, velocity + 1);
|
||||
|
||||
return limit(velocity - 1,
|
||||
goalVel, velocity + maxDecel(-velocity));
|
||||
}
|
||||
|
||||
static final double getMaxVelocity(double distance) {
|
||||
final double decelTime = Math.round(
|
||||
//sum of 0... decelTime, solving for decelTime
|
||||
//using quadratic formula, then simplified a lot
|
||||
Math.sqrt(distance + 1));
|
||||
|
||||
final double decelDist = Math.max(0, (decelTime) * (decelTime-1) );
|
||||
// sum of 0..(decelTime-1)
|
||||
// * Rules.DECELERATION*0.5;
|
||||
|
||||
return Math.max(0,((decelTime - 1) * 2) + ((distance - decelDist) / decelTime));
|
||||
}
|
||||
|
||||
private static final double maxDecel(double speed) {
|
||||
return limit(1,speed*0.5 + 1, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static double limit(double min, double val, double max){
|
||||
if(val < min)
|
||||
return min;
|
||||
if (val > max)
|
||||
return max;
|
||||
return val;
|
||||
}
|
||||
private static double absoluteBearing(Point2D source, Point2D target) {
|
||||
return FastTrig.atan2(target.getX() - source.getX(), target.getY() - source.getY());
|
||||
}
|
||||
private static double sqr(double d){
|
||||
return d*d;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package jk.mega.dMove;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class PlaceTime implements Comparable{
|
||||
Point2D.Double place;
|
||||
long time;
|
||||
|
||||
PredictionStatus predictionStatus;
|
||||
|
||||
//speed optimizations - don't try this at home, kids!
|
||||
float danger;
|
||||
|
||||
|
||||
public int compareTo(Object o){
|
||||
return (int)Math.signum(danger - ((PlaceTime)o).danger);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package jk.mega.dMove;
|
||||
import java.awt.geom.*;
|
||||
|
||||
public class PredictionStatus{
|
||||
public PredictionStatus(){}
|
||||
public PredictionStatus(Point2D.Double endPoint,double velocity,double heading,long time,double distanceRemaining){
|
||||
this.endPoint = endPoint;
|
||||
this.finalVelocity = velocity;
|
||||
this.finalHeading = heading;
|
||||
this.time = time;
|
||||
this.distanceRemaining = distanceRemaining;
|
||||
}
|
||||
public PredictionStatus(Point2D.Double endPoint,double velocity,double heading,long time,double distanceRemaining,double[] indices){
|
||||
this.endPoint = endPoint;
|
||||
this.finalVelocity = velocity;
|
||||
this.finalHeading = heading;
|
||||
this.time = time;
|
||||
this.distanceRemaining = distanceRemaining;
|
||||
this.intersectionIndices = indices;
|
||||
}
|
||||
double finalHeading, finalVelocity, distanceRemaining;
|
||||
long time;
|
||||
Point2D.Double endPoint;
|
||||
double[] intersectionIndices;
|
||||
EnemyWave fwave;
|
||||
// boolean debug;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package jk.melee;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import robocode.*;
|
||||
import robocode.util.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
import jk.math.FastTrig;
|
||||
|
||||
public class MeleeRadar {
|
||||
|
||||
Hashtable<String,EnemyInfo> enemies = new Hashtable<String,EnemyInfo>();
|
||||
AdvancedRobot bot;
|
||||
Point2D.Double myLocation;
|
||||
public MeleeRadar(AdvancedRobot _bot){
|
||||
bot = _bot;
|
||||
|
||||
enemies.clear();
|
||||
|
||||
}
|
||||
public void onTick(){
|
||||
if(bot.getRadarTurnRemaining() == 0)
|
||||
bot.setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
|
||||
|
||||
myLocation = new Point2D.Double(bot.getX(), bot.getY());
|
||||
}
|
||||
|
||||
public void onScannedRobot(ScannedRobotEvent e){
|
||||
String eName = e.getName();
|
||||
|
||||
EnemyInfo eInfo;
|
||||
if((eInfo = enemies.get(eName)) == null){
|
||||
enemies.put(eName,eInfo = new EnemyInfo());
|
||||
eInfo.name = eName;
|
||||
}
|
||||
|
||||
eInfo.lastScanTime = (int)bot.getTime();
|
||||
double otherAngle;// = getHeadingRadians() + e.getBearingRadians();
|
||||
eInfo.location = project(myLocation,otherAngle = bot.getHeadingRadians() + e.getBearingRadians(), e.getDistance());
|
||||
|
||||
|
||||
|
||||
if(bot.getOthers() <= enemies.size()){
|
||||
Enumeration<EnemyInfo> all = enemies.elements();
|
||||
int oldestScan = eInfo.lastScanTime;
|
||||
while(all.hasMoreElements()){
|
||||
EnemyInfo tmp = all.nextElement();
|
||||
if(tmp.lastScanTime < oldestScan){
|
||||
otherAngle = absoluteAngle(myLocation,tmp.location);
|
||||
oldestScan = tmp.lastScanTime;
|
||||
}
|
||||
}
|
||||
if(bot.getOthers() == 1 && oldestScan == eInfo.lastScanTime){
|
||||
double angle = Utils.normalRelativeAngle(otherAngle - bot.getRadarHeadingRadians());
|
||||
bot.setTurnRadarRightRadians(Math.signum(angle)*limit(0,Math.abs(angle) + (Math.PI/4 - Math.PI/8 - Math.PI/18),Math.PI/4));
|
||||
|
||||
}
|
||||
else
|
||||
bot.setTurnRadarRightRadians(Utils.normalRelativeAngle(otherAngle - bot.getRadarHeadingRadians())*Double.POSITIVE_INFINITY);
|
||||
}
|
||||
else
|
||||
bot.setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
|
||||
|
||||
}
|
||||
|
||||
static Point2D.Double project(Point2D.Double location, double angle, double distance){
|
||||
return new Point2D.Double(location.x + distance*FastTrig.sin(angle), location.y + distance*FastTrig.cos(angle));
|
||||
}
|
||||
static double absoluteAngle(Point2D source, Point2D target) {
|
||||
return FastTrig.atan2(target.getX() - source.getX(), target.getY() - source.getY());
|
||||
}
|
||||
|
||||
|
||||
public void onRobotDeath(RobotDeathEvent e){
|
||||
|
||||
enemies.remove(e.getName());
|
||||
}
|
||||
|
||||
public static double limit(double min, double value, double max) {
|
||||
if(value > max)
|
||||
return max;
|
||||
if(value < min)
|
||||
return min;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
class EnemyInfo{
|
||||
String name;
|
||||
int lastScanTime;
|
||||
Point2D.Double location = new Point2D.Double();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
package jk.precise;
|
||||
import robocode.*;
|
||||
import robocode.util.*;
|
||||
import java.awt.geom.*;
|
||||
import jk.precise.util.*;
|
||||
import java.util.*;
|
||||
|
||||
import jk.math.FastTrig;
|
||||
|
||||
public class EnergyDomeWorker
|
||||
{
|
||||
final static int OPTIONS = 12;
|
||||
static int[] optionScores = new int[OPTIONS];
|
||||
static int[] offsetCounts = new int[OPTIONS];
|
||||
static double[] offsets = new double[OPTIONS];
|
||||
static double[] dirOffsets = new double[OPTIONS];
|
||||
|
||||
double lastEnemyEnergy = 100;
|
||||
Point2D.Double lastEnemyLocation;
|
||||
ArrayList<Point2D.Double> myLocations = new ArrayList<Point2D.Double>();
|
||||
ArrayList<Point2D.Double> enemyLocations = new ArrayList<Point2D.Double>();
|
||||
ArrayList<Double> enemyHeadings = new ArrayList<Double>();
|
||||
ArrayList<Double> enemyVelocities = new ArrayList<Double>();
|
||||
double lastBearing;
|
||||
double firePower;
|
||||
double moveAmount;
|
||||
long nextFireTime;
|
||||
ArrayList<DetectWave> enemyWaves = new ArrayList<DetectWave>();
|
||||
double direction=1;
|
||||
static double unmatchedEnemyDamage;
|
||||
static double enemyDamage;
|
||||
static double myDamage;
|
||||
|
||||
|
||||
boolean move;
|
||||
boolean aim;
|
||||
boolean turn;
|
||||
boolean fire;
|
||||
double moveVal;
|
||||
double aimAngle;
|
||||
double turnAngle;
|
||||
|
||||
boolean idealPosition;
|
||||
Point2D.Double goalPoint;
|
||||
static final double WALL_THRESHOLD = 200;
|
||||
Rectangle2D.Double safeField;
|
||||
|
||||
AdvancedRobot bot;
|
||||
Point2D.Double myLocation;
|
||||
|
||||
int bullets;
|
||||
double avgBulletPower;
|
||||
//double enemyEnergy = 100;
|
||||
|
||||
public EnergyDomeWorker(AdvancedRobot bot){
|
||||
|
||||
this.bot = bot;
|
||||
|
||||
nextFireTime = bot.getTime() + (long)Math.ceil(bot.getGunHeat()/bot.getGunCoolingRate());
|
||||
//setAdjustRadarForGunTurn(true);
|
||||
//setAdjustRadarForRobotTurn(true); -- redundant
|
||||
//setAdjustGunForRobotTurn(true);
|
||||
if(bot.getRoundNum() > 0)
|
||||
System.out.println("Enemy Gun VG scores: \n" + Arrays.toString(optionScores));
|
||||
// while(true){
|
||||
// turnRadarRight(Double.POSITIVE_INFINITY);
|
||||
// }
|
||||
myLocation = new Point2D.Double(bot.getX(), bot.getY());
|
||||
|
||||
safeField = new Rectangle2D.Double(WALL_THRESHOLD,WALL_THRESHOLD,
|
||||
bot.getBattleFieldWidth() - 2*WALL_THRESHOLD,bot.getBattleFieldHeight() - 2*WALL_THRESHOLD);
|
||||
|
||||
// int code = safeField.outcode(myLocation);
|
||||
goalPoint = (Point2D.Double)myLocation.clone();
|
||||
if(safeField.contains(myLocation) || bot.getRoundNum() == 0)
|
||||
idealPosition = true;
|
||||
else{
|
||||
goalPoint.x = limit(WALL_THRESHOLD,goalPoint.x,bot.getBattleFieldWidth()-WALL_THRESHOLD);
|
||||
goalPoint.y = limit(WALL_THRESHOLD,goalPoint.y,bot.getBattleFieldHeight()-WALL_THRESHOLD);
|
||||
goTo(goalPoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onScannedRobot(ScannedRobotEvent e) {
|
||||
|
||||
double latVel = bot.getVelocity()*Math.sin(e.getBearingRadians());
|
||||
if(latVel < 0)
|
||||
direction = -1;
|
||||
if(latVel > 0)
|
||||
direction = 1;
|
||||
|
||||
myLocation = new Point2D.Double(bot.getX(), bot.getY());
|
||||
double absBearing=e.getBearingRadians() + (bot.getHeadingRadians());
|
||||
double eDistance = e.getDistance();
|
||||
double deltaE = (lastEnemyEnergy - (lastEnemyEnergy = e.getEnergy()));
|
||||
Point2D.Double enemyLocation = project(myLocation, absBearing, eDistance);
|
||||
myLocations.add(0,myLocation);
|
||||
enemyLocations.add(0,enemyLocation);
|
||||
enemyHeadings.add(0,e.getHeadingRadians());
|
||||
enemyVelocities.add(0,e.getVelocity());
|
||||
|
||||
if(!idealPosition){
|
||||
double safeStop = Math.abs(bot.getVelocity())/2 + 3;
|
||||
|
||||
if(bot.getRoundNum() == 0)
|
||||
safeStop += 300;//build some history
|
||||
|
||||
if( (nextFireTime - bot.getTime()) > safeStop){
|
||||
goalPoint = (Point2D.Double)myLocation.clone();
|
||||
goalPoint.x = limit(WALL_THRESHOLD,goalPoint.x,bot.getBattleFieldWidth()-WALL_THRESHOLD);
|
||||
goalPoint.y = limit(WALL_THRESHOLD,goalPoint.y,bot.getBattleFieldHeight()-WALL_THRESHOLD);
|
||||
goTo(goalPoint);
|
||||
}
|
||||
else{
|
||||
//goTo(myLocation);
|
||||
bot.setAhead(0);
|
||||
//idealPosition = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(bot.getTime() >= nextFireTime && lastEnemyLocation != null && (Math.min(lastEnemyEnergy,0.0999) < deltaE && deltaE < 3.001)){
|
||||
idealPosition = true;
|
||||
bullets++;
|
||||
if(bullets == 1)
|
||||
avgBulletPower = deltaE;
|
||||
else
|
||||
avgBulletPower = 0.1*deltaE + 0.9*avgBulletPower;
|
||||
//System.out.println("Bullet seen!");
|
||||
nextFireTime = bot.getTime() + (long)Math.ceil(Rules.getGunHeat(deltaE)/bot.getGunCoolingRate());
|
||||
double enemyBulletVelocity = Rules.getBulletSpeed(deltaE);
|
||||
|
||||
double[] options = new double[OPTIONS];
|
||||
options[0] = absoluteBearing(enemyLocations.get(2),myLocations.get(2));
|
||||
options[1] = absoluteBearing(enemyLocations.get(2),myLocations.get(2))
|
||||
+ enemyHeadings.get(1) - enemyHeadings.get(2);
|
||||
options[2] = absoluteBearing(enemyLocations.get(1),myLocations.get(2));
|
||||
Point2D.Double predictedNext = project(enemyLocations.get(2),enemyHeadings.get(2),enemyVelocities.get(2));
|
||||
options[3] = absoluteBearing(predictedNext,myLocations.get(2));
|
||||
//System.out.println("Predicted difference: " + predictedNext.distance(enemyLocations.get(1)));
|
||||
for(int i = 0; i < OPTIONS/3; i++){
|
||||
options[i + OPTIONS/3] = options[i] + offsets[i];
|
||||
options[i + 2*OPTIONS/3] = options[i] + direction*dirOffsets[i];
|
||||
}
|
||||
|
||||
int maxIndex = 0;
|
||||
for(int i = 0; i < OPTIONS; i++)
|
||||
if(optionScores[i] > optionScores[maxIndex])
|
||||
maxIndex = i;
|
||||
// System.out.println("Max index: " + maxIndex);
|
||||
double bulletBearing = options[maxIndex];
|
||||
double[] moveOptions = {-0.4,0.0,0.4};
|
||||
double[] moveWeights;
|
||||
if(bullets%2 == 0)
|
||||
moveWeights = new double[]{0.5,0.2,1};
|
||||
else
|
||||
moveWeights = new double[]{1,0.2,0.5};
|
||||
if(Math.abs(enemyVelocities.get(1)*Math.sin(enemyHeadings.get(1) - bulletBearing)) > 0.1 && maxIndex%(OPTIONS/3) < 2)
|
||||
moveOptions = new double[]{0d};
|
||||
double maxDiff = 0;
|
||||
for(int j = 0; j < moveOptions.length; j++){
|
||||
Point2D.Double fireLoc = project(myLocation,bot.getHeadingRadians(),moveOptions[j]);
|
||||
double fireBearing = absoluteBearing(fireLoc,lastEnemyLocation);
|
||||
double diff = Math.abs(Utils.normalRelativeAngle(fireBearing + Math.PI - bulletBearing));
|
||||
if(diff*moveWeights[j] > maxDiff){
|
||||
moveAmount = moveOptions[j];
|
||||
maxDiff = diff*moveWeights[j];
|
||||
}
|
||||
}
|
||||
//options[4] = absoluteBearing(enemyLocations.get(1),project(myLocations.get(2),getHeadingRadians(),moveAmount*0.5));
|
||||
|
||||
Point2D.Double fireLoc = project(myLocation,bot.getHeadingRadians(),moveAmount);
|
||||
|
||||
double maxWidth = 0;
|
||||
double bestAngle = absoluteBearing(fireLoc,enemyLocations.get(1));
|
||||
double bestPower = 0.1;
|
||||
long hitTime = 0;
|
||||
double maxPower = Math.min(deltaE-0.01,deltaE*(bot.getEnergy()-10)/e.getEnergy());
|
||||
// enemyEnergy = e.getEnergy();
|
||||
|
||||
for(int i = 7; i < 20; i++){
|
||||
double bulletPower = 0.1 + Math.max(0,(maxPower-0.1)*0.05*i);
|
||||
// if(deltaE > 0.1)
|
||||
// bulletPower += 0.01;
|
||||
double myBulletVelocity = Rules.getBulletSpeed(bulletPower);
|
||||
Point2D.Double bLoc = lastEnemyLocation;
|
||||
double mDist = 0;
|
||||
double eFireTime = -1;
|
||||
double mFireTime = 1;
|
||||
double t = 0;
|
||||
while(true){
|
||||
t+= 1;
|
||||
bLoc = project(lastEnemyLocation,bulletBearing,(t-eFireTime)*enemyBulletVelocity);
|
||||
double bDistSq = bLoc.distanceSq(fireLoc);
|
||||
mDist = (t - mFireTime)*myBulletVelocity;
|
||||
if(mDist*mDist >= bDistSq || t > 100)
|
||||
break;
|
||||
}
|
||||
|
||||
Point2D.Double bP = bLoc;
|
||||
Point2D.Double lastbP = project(bP,bulletBearing,-enemyBulletVelocity);
|
||||
|
||||
double en = bP.distance(fireLoc);
|
||||
double len = lastbP.distance(fireLoc);
|
||||
|
||||
double actDistTrav = mDist;
|
||||
double lastDistTraveled = actDistTrav - myBulletVelocity;
|
||||
|
||||
if(!( en < actDistTrav && len > lastDistTraveled && en < len )){
|
||||
System.out.println("Prediction error!");
|
||||
continue;
|
||||
}
|
||||
Point2D.Double p1, p2;
|
||||
if(en >= lastDistTraveled)
|
||||
p1 = bP;
|
||||
else{
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLoc;
|
||||
wv.distanceTraveled = lastDistTraveled;
|
||||
p1 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
if(len > actDistTrav){
|
||||
PreciseWave wv = new PreciseWave();
|
||||
wv.fireLocation = fireLoc;
|
||||
wv.distanceTraveled = actDistTrav;
|
||||
p2 = PreciseUtils.intersection(lastbP,bP,wv);
|
||||
}
|
||||
else
|
||||
p2 = lastbP;
|
||||
|
||||
|
||||
double d1 = absoluteBearing(fireLoc,p1);
|
||||
double d2 = absoluteBearing(fireLoc,p2);
|
||||
|
||||
//double pDist = p1.distance(p2);
|
||||
|
||||
Point2D.Double midPoint = new Point2D.Double(0.5*(p1.x+p2.x) , 0.5*(p1.y+p2.y));
|
||||
|
||||
Rectangle2D.Double me = new Rectangle2D.Double(myLocation.x - 18.1, myLocation.y - 18.1, 36.2, 36.2);
|
||||
|
||||
double diff = Utils.normalRelativeAngle(d1-d2);
|
||||
double fireAngle = d1 - 0.5*diff;
|
||||
double width = Math.abs(diff);
|
||||
if(width > maxWidth && !me.contains(p2)){
|
||||
maxWidth = width;
|
||||
bestAngle = fireAngle;
|
||||
bestPower = bulletPower;
|
||||
hitTime = (long)t;
|
||||
}
|
||||
}
|
||||
|
||||
aim = true;
|
||||
aimAngle = bestAngle;
|
||||
|
||||
firePower = bestPower;
|
||||
move = true;
|
||||
moveVal = moveAmount;
|
||||
|
||||
DetectWave dw = new DetectWave();
|
||||
dw.fireLocation = enemyLocations.get(1);
|
||||
dw.fireTime = bot.getTime() - 2;
|
||||
dw.bulletBearings = options;
|
||||
dw.bearingAttempts = new boolean[OPTIONS];
|
||||
dw.bearingAttempts[maxIndex] = true;
|
||||
dw.bulletVelocity = enemyBulletVelocity;
|
||||
dw.interceptTime = hitTime;
|
||||
dw.direction = direction;
|
||||
enemyWaves.add(dw);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(!move && bot.getDistanceRemaining() == 0 && !aim && bot.getGunTurnRemaining() == 0 && !fire && firePower > 0){
|
||||
|
||||
fire = true;
|
||||
move = true;
|
||||
moveVal = -moveAmount;
|
||||
|
||||
}
|
||||
updateWaves();
|
||||
|
||||
if(firePower == 0 && !aim){
|
||||
aim = true;
|
||||
aimAngle = absBearing;
|
||||
|
||||
if(e.getEnergy() < 0.1 && e.getVelocity() == 0 &&enemyVelocities.size() > 1 && bot.getTime() > nextFireTime + 3 &&
|
||||
enemyVelocities.get(1) == 0 && enemyWaves.size() == 0 && bot.getEnergy() > 1 + e.getEnergy()
|
||||
){
|
||||
fire = true;
|
||||
firePower = 0.1;
|
||||
}
|
||||
else
|
||||
if( bot.getDistanceRemaining() == 0 && !move && !turn){
|
||||
turn = true;
|
||||
turnAngle = absBearing + Math.PI/2;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(lastEnemyLocation != null)
|
||||
lastBearing = absoluteBearing(lastEnemyLocation,myLocation);
|
||||
lastEnemyLocation = enemyLocation;
|
||||
|
||||
if(nextFireTime < bot.getTime() - 100 && lastEnemyEnergy >= bot.getEnergy()-1){
|
||||
enemyDamage ++;
|
||||
unmatchedEnemyDamage ++;
|
||||
}
|
||||
}
|
||||
|
||||
public void goTo(Point2D.Double destination){
|
||||
|
||||
double distance = myLocation.distance(destination);
|
||||
double angle;
|
||||
if(-1 < distance && distance < 1 ){
|
||||
angle = 0;
|
||||
distance = 0;
|
||||
}
|
||||
else
|
||||
angle = FastTrig.normalRelativeAngle(absoluteBearing(myLocation, destination) - bot.getHeadingRadians());
|
||||
|
||||
if (Math.abs(angle) > Math.PI/2) {
|
||||
distance = -distance;
|
||||
if (angle > 0) {
|
||||
angle -= Math.PI;
|
||||
}
|
||||
else {
|
||||
angle += Math.PI;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bot.setTurnRightRadians(angle);
|
||||
bot.setAhead(distance);
|
||||
}
|
||||
public void applyActions(){
|
||||
if(fire){
|
||||
bot.setFire(firePower);
|
||||
firePower = 0;
|
||||
fire = false;
|
||||
}
|
||||
|
||||
if(aim){
|
||||
bot.setTurnGunRightRadians(Utils.normalRelativeAngle(aimAngle - bot.getGunHeadingRadians()));
|
||||
aim = false;
|
||||
}
|
||||
|
||||
if(move){
|
||||
bot.setAhead(moveVal);
|
||||
move = false;
|
||||
}
|
||||
|
||||
if(turn){
|
||||
bot.setTurnRightRadians(Math.tan(turnAngle - bot.getHeadingRadians()));
|
||||
turn = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void updateWaves(){
|
||||
Iterator<DetectWave> it = enemyWaves.iterator();
|
||||
long time = bot.getTime();
|
||||
while(it.hasNext()){
|
||||
DetectWave dw = it.next();
|
||||
dw.distanceTraveled = dw.bulletVelocity*(time - dw.fireTime);
|
||||
if(dw.distanceTraveled - 18 > dw.fireLocation.distance(myLocations.get(0)))
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
boolean logBullet(Bullet b){
|
||||
double heading = b.getHeadingRadians();
|
||||
Iterator<DetectWave> it = enemyWaves.iterator();
|
||||
long time = bot.getTime();
|
||||
while(it.hasNext()){
|
||||
DetectWave dw = it.next();
|
||||
dw.distanceTraveled = dw.bulletVelocity*(time - dw.fireTime);
|
||||
Point2D.Double bloc = new Point2D.Double(b.getX(),b.getY());
|
||||
if(Math.abs(dw.distanceTraveled - dw.fireLocation.distance(bloc) - dw.bulletVelocity) < 1.1*dw.bulletVelocity){
|
||||
boolean matched = false;
|
||||
|
||||
for(int i = 0; i < OPTIONS; i++){
|
||||
double diff = (Utils.normalRelativeAngle(heading - dw.bulletBearings[i]));
|
||||
if(Math.abs(diff) < 0.00001){
|
||||
optionScores[i]++;
|
||||
matched = true;
|
||||
}
|
||||
if( i < OPTIONS/3){
|
||||
offsets[i] = (offsets[i]*offsetCounts[i] + diff)/(offsetCounts[i]+1);
|
||||
dirOffsets[i] = (dirOffsets[i]*offsetCounts[i] + dw.direction*diff)/(offsetCounts[i]+1);
|
||||
offsetCounts[i]++;
|
||||
}
|
||||
}
|
||||
it.remove();
|
||||
return matched;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("No bullet detected");
|
||||
return false;
|
||||
}
|
||||
public void onHitByBullet(HitByBulletEvent e){
|
||||
|
||||
lastEnemyEnergy += 20 - (e.getVelocity());
|
||||
boolean matched = logBullet(e.getBullet());
|
||||
double damage = Rules.getBulletDamage(e.getBullet().getPower());
|
||||
enemyDamage += damage;
|
||||
if(!matched ){
|
||||
unmatchedEnemyDamage += damage;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean aboveScore(double goal){
|
||||
double Q = goal*0.01;
|
||||
double x = (2100 + myDamage)*(1-Q)/Q;
|
||||
|
||||
int maxIndex = 0;
|
||||
for(int i = 0; i < OPTIONS; i++)
|
||||
if(optionScores[i] > optionScores[maxIndex])
|
||||
maxIndex = i;
|
||||
|
||||
if((bot.getRoundNum() > 0 && optionScores[maxIndex] < bullets*0.6)
|
||||
||
|
||||
(bullets > 10 && lastEnemyEnergy/avgBulletPower > bot.getEnergy()/0.11)
|
||||
||
|
||||
(enemyLocations.size() > 0 && nextFireTime < bot.getTime() + 5 && enemyLocations.get(0).distance(myLocations.get(0)) < 80)
|
||||
)
|
||||
x -= 100;
|
||||
|
||||
return (enemyDamage <= x);
|
||||
}
|
||||
public void onBulletHitBullet(BulletHitBulletEvent e){
|
||||
logBullet(e.getHitBullet());
|
||||
}
|
||||
public void onBulletHit(BulletHitEvent e){
|
||||
lastEnemyEnergy -= Rules.getBulletDamage(e.getBullet().getPower());
|
||||
myDamage += Rules.getBulletDamage(e.getBullet().getPower());
|
||||
}
|
||||
static Point2D.Double project(Point2D.Double location, double angle, double distance){
|
||||
return new Point2D.Double(location.x + distance*Math.sin(angle), location.y + distance*Math.cos(angle));
|
||||
}
|
||||
private double absoluteBearing(Point2D source, Point2D target) {
|
||||
return Math.atan2(target.getX() - source.getX(), target.getY() - source.getY());
|
||||
}
|
||||
public static double limit(double min, double value, double max) {
|
||||
if(value > max)
|
||||
return max;
|
||||
if(value < min)
|
||||
return min;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
class DetectWave extends PreciseWave{
|
||||
|
||||
long fireTime;
|
||||
double direction;
|
||||
|
||||
double[] bulletBearings;
|
||||
boolean[] bearingAttempts;
|
||||
|
||||
long interceptTime;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package jk.precise.util;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
import jk.math.FastTrig;
|
||||
public class PreciseUtils{
|
||||
public static final int INTERSECTION = 3, PASSED = 1, NOT_REACHED = 2;
|
||||
|
||||
|
||||
//high speed test to determine if the full method should be run this tick
|
||||
public static int intersects(Point2D.Double botLocation, PreciseWave wave){
|
||||
double[] distSq = new double[]{
|
||||
wave.fireLocation.distanceSq(botLocation.x - 18, botLocation.y + 18),
|
||||
wave.fireLocation.distanceSq(botLocation.x + 18, botLocation.y + 18),
|
||||
wave.fireLocation.distanceSq(botLocation.x + 18, botLocation.y - 18),
|
||||
wave.fireLocation.distanceSq(botLocation.x - 18, botLocation.y - 18)};
|
||||
|
||||
|
||||
int score = 0;
|
||||
double compDistSq = sqr(wave.distanceTraveled);
|
||||
if ( compDistSq < distSq[0] & compDistSq < distSq[1] & compDistSq < distSq[2] & compDistSq < distSq[3])
|
||||
return NOT_REACHED;
|
||||
|
||||
compDistSq = sqr(wave.distanceTraveled - wave.bulletVelocity);
|
||||
if( compDistSq > distSq[0] & compDistSq > distSq[1] & compDistSq > distSq[2] & compDistSq > distSq[3])
|
||||
return PASSED;
|
||||
|
||||
return INTERSECTION;
|
||||
}
|
||||
public static double[] getIntersectionRange(Point2D.Double botLocation, PreciseWave wave){
|
||||
double[] yBounds = new double[]{botLocation.y - 18, botLocation.y + 18};
|
||||
double[] xBounds = new double[]{botLocation.x - 18, botLocation.x + 18};
|
||||
|
||||
double[] radii = new double[]{wave.distanceTraveled, wave.distanceTraveled - wave.bulletVelocity};
|
||||
|
||||
ArrayList<Point2D.Double> intersects = new ArrayList<Point2D.Double>();
|
||||
for(int i = 0; i < 2; i++)
|
||||
for(int j = 0; j < 2; j++){
|
||||
Point2D.Double[] testPoints = vertIntersect(wave.fireLocation.x, wave.fireLocation.y, radii[i], xBounds[j]);
|
||||
for(int k = 0; k < testPoints.length; k++)
|
||||
if(inBounds(testPoints[k].y, yBounds))
|
||||
intersects.add(testPoints[k]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
for(int j = 0; j < 2; j++){
|
||||
Point2D.Double[] testPoints = horizIntersect(wave.fireLocation.x, wave.fireLocation.y, radii[i], yBounds[j]);
|
||||
for(int k = 0; k < testPoints.length; k++)
|
||||
if(inBounds(testPoints[k].x, xBounds))
|
||||
intersects.add(testPoints[k]);
|
||||
}
|
||||
for(int i = 0; i < 2; i++)
|
||||
for(int j = 0; j < 2; j++){
|
||||
Point2D.Double testCorner = new Point2D.Double(xBounds[i], yBounds[j]);
|
||||
double distSq = testCorner.distanceSq(wave.fireLocation);
|
||||
if(distSq <= sqr(radii[0]) && distSq > sqr(radii[1]))
|
||||
intersects.add(testCorner);
|
||||
}
|
||||
double antiClockAngle = 1;
|
||||
double clockAngle = -1;
|
||||
Point2D.Double antiClock = null,clock = null;
|
||||
double absBearing = angle(wave.fireLocation, botLocation);
|
||||
|
||||
for(int i = 0, k = intersects.size(); i<k; i++){
|
||||
Point2D.Double p = intersects.get(i);
|
||||
double angDiff = fastRelativeAngle(angle(wave.fireLocation,p) - absBearing);
|
||||
if(angDiff > clockAngle){
|
||||
clockAngle = angDiff;
|
||||
clock = p;
|
||||
}
|
||||
if(angDiff < antiClockAngle){
|
||||
antiClockAngle = angDiff;
|
||||
antiClock = p;
|
||||
}
|
||||
}
|
||||
// return new Point2D.Double[]{antiClock,clock};
|
||||
return new double[]{fastAbsoluteAngle(antiClockAngle + absBearing), fastAbsoluteAngle(clockAngle + absBearing)};
|
||||
}
|
||||
public static Point2D.Double intersection(Point2D.Double l1, Point2D.Double l2, PreciseWave w){
|
||||
double xd = l2.x - l1.x;
|
||||
double yd = l2.y - l1.y;
|
||||
double a = sqr(xd) + sqr(yd);
|
||||
double b = 2*(xd*(l1.x - w.fireLocation.x) + yd*(l1.y - w.fireLocation.y));
|
||||
double c = sqr(l1.x - w.fireLocation.x) + sqr(l1.y - w.fireLocation.y) - sqr(w.distanceTraveled);
|
||||
double det = b*b - 4*a*c;
|
||||
if(det < 0)
|
||||
throw new IllegalArgumentException();
|
||||
det = Math.sqrt(det);
|
||||
double t = (-b + det)/(2*a);
|
||||
if(0 <= t && t <= 1)
|
||||
return new Point2D.Double(l1.x + xd*t, l1.y + yd*t);
|
||||
t = (-b - det)/(2*a);
|
||||
if(0 <= t && t <= 1)
|
||||
return new Point2D.Double(l1.x + xd*t, l1.y + yd*t);
|
||||
|
||||
throw new IllegalArgumentException("t is out of range [0;1]: " + t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static boolean inBounds(double q ,double[] bounds){
|
||||
return bounds[0] <= q && q <= bounds[1] ;
|
||||
}
|
||||
|
||||
//assumes between -PI*2 and PI*2
|
||||
public static double fastRelativeAngle(double angle) {
|
||||
return FastTrig.normalRelativeAngle(angle);
|
||||
}
|
||||
|
||||
//assumes between -PI*2 and PI*4
|
||||
public static double fastAbsoluteAngle(double angle){
|
||||
return FastTrig.normalAbsoluteAngle(angle);
|
||||
}
|
||||
|
||||
static Point2D.Double[] vertIntersect(double centerX, double centerY, double r, double intersectX){
|
||||
double deltaX = centerX - intersectX;
|
||||
double sqrtVal = r*r - deltaX*deltaX;
|
||||
if(sqrtVal < 0)
|
||||
return new Point2D.Double[]{};
|
||||
|
||||
// if(sqrtVal == 0)
|
||||
// return new Point2D.Double[]{
|
||||
// new Point2D.Double(intersectX, centerY)};
|
||||
|
||||
sqrtVal = Math.sqrt(sqrtVal);
|
||||
return new Point2D.Double[]{
|
||||
new Point2D.Double(intersectX, centerY + sqrtVal),
|
||||
new Point2D.Double(intersectX, centerY - sqrtVal)};
|
||||
}
|
||||
static Point2D.Double[] horizIntersect(double centerX, double centerY, double r, double intersectY){
|
||||
double deltaY = centerY - intersectY;
|
||||
double sqrtVal = r*r - deltaY*deltaY;
|
||||
if(sqrtVal < 0)
|
||||
return new Point2D.Double[]{};
|
||||
|
||||
// if(sqrtVal == 0)
|
||||
// return new Point2D.Double[]{
|
||||
// new Point2D.Double(centerX, intersectY)};
|
||||
|
||||
sqrtVal = Math.sqrt(sqrtVal);
|
||||
return new Point2D.Double[]{
|
||||
new Point2D.Double(centerX + sqrtVal, intersectY),
|
||||
new Point2D.Double(centerX - sqrtVal, intersectY)};
|
||||
}
|
||||
|
||||
public static final double sqr(double d){
|
||||
return d*d;}
|
||||
|
||||
public static double angle(Point2D.Double source, Point2D.Double target) {
|
||||
return FastTrig.atan2(target.x - source.x, target.y - source.y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package jk.precise.util;
|
||||
import java.awt.geom.*;
|
||||
public class PreciseWave{
|
||||
public double distanceTraveled;
|
||||
public double bulletVelocity;
|
||||
public Point2D.Double fireLocation;
|
||||
}
|
||||
@@ -0,0 +1,618 @@
|
||||
package jk.tree;
|
||||
/*
|
||||
** KDTree.java by Julian Kent
|
||||
**
|
||||
** Licenced under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
|
||||
**
|
||||
** Licence summary:
|
||||
** Under this licence you are free to:
|
||||
** Share : copy and redistribute the material in any medium or format
|
||||
** Adapt : remix, transform, and build upon the material
|
||||
** The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||
**
|
||||
** Under the following terms:
|
||||
** Attribution:
|
||||
** You must give appropriate credit, provide a link to the license, and indicate
|
||||
** if changes were made. You may do so in any reasonable manner, but not in any
|
||||
** way that suggests the licensor endorses you or your use.
|
||||
** NonCommercial:
|
||||
** You may not use the material for commercial purposes.
|
||||
** ShareAlike:
|
||||
** If you remix, transform, or build upon the material, you must distribute your
|
||||
** contributions under the same license as the original.
|
||||
** No additional restrictions:
|
||||
** You may not apply legal terms or technological measures that legally restrict
|
||||
** others from doing anything the license permits.
|
||||
**
|
||||
** See full licencing details here: http://creativecommons.org/licenses/by-nc-sa/3.0/
|
||||
**
|
||||
** For additional licencing rights please contact jkflying@gmail.com
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class KDTree<T> {
|
||||
|
||||
// use a big bucketSize so that we have less node bounds (for more cache
|
||||
// hits) and better splits
|
||||
private static final int _bucketSize = 50;
|
||||
|
||||
private final int _dimensions;
|
||||
private int _nodes;
|
||||
private final Node root;
|
||||
private final ArrayList<Node> nodeList = new ArrayList<Node>();
|
||||
|
||||
// prevent GC from having to collect _bucketSize*dimensions*8 bytes each
|
||||
// time a leaf splits
|
||||
private double[] mem_recycle;
|
||||
|
||||
// the starting values for bounding boxes, for easy access
|
||||
private final double[] bounds_template;
|
||||
|
||||
// one big self-expanding array to keep all the node bounding boxes so that
|
||||
// they stay in cache
|
||||
// node bounds available at:
|
||||
// low: 2 * _dimensions * node.index + 2 * dim
|
||||
// high: 2 * _dimensions * node.index + 2 * dim + 1
|
||||
private final ContiguousDoubleArrayList nodeMinMaxBounds;
|
||||
|
||||
private KDTree(int dimensions) {
|
||||
_dimensions = dimensions;
|
||||
|
||||
// initialise this big so that it ends up in 'old' memory
|
||||
nodeMinMaxBounds = new ContiguousDoubleArrayList(512 * 1024 / 8 + 2 * _dimensions);
|
||||
mem_recycle = new double[_bucketSize * dimensions];
|
||||
|
||||
bounds_template = new double[2 * _dimensions];
|
||||
Arrays.fill(bounds_template, Double.NEGATIVE_INFINITY);
|
||||
for (int i = 0, max = 2 * _dimensions; i < max; i += 2)
|
||||
bounds_template[i] = Double.POSITIVE_INFINITY;
|
||||
|
||||
// and.... start!
|
||||
root = new Node();
|
||||
}
|
||||
|
||||
public int nodes() {
|
||||
return _nodes;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return root.entries;
|
||||
}
|
||||
|
||||
public int addPoint(double[] location, T payload) {
|
||||
|
||||
Node addNode = root;
|
||||
// Do a Depth First Search to find the Node where 'location' should be
|
||||
// stored
|
||||
while (addNode.pointLocations == null) {
|
||||
addNode.expandBounds(location);
|
||||
if (location[addNode.splitDim] < addNode.splitVal)
|
||||
addNode = nodeList.get(addNode.lessIndex);
|
||||
else
|
||||
addNode = nodeList.get(addNode.moreIndex);
|
||||
}
|
||||
addNode.expandBounds(location);
|
||||
|
||||
int nodeSize = addNode.add(location, payload);
|
||||
|
||||
if (nodeSize % _bucketSize == 0)
|
||||
// try splitting again once every time the node passes a _bucketSize
|
||||
// multiple
|
||||
// in case it is full of points of the same location and won't split
|
||||
addNode.split();
|
||||
|
||||
return root.entries;
|
||||
}
|
||||
|
||||
public ArrayList<SearchResult<T>> nearestNeighbours(double[] searchLocation, int K) {
|
||||
|
||||
K = Math.min(K, size());
|
||||
|
||||
ArrayList<SearchResult<T>> returnResults = new ArrayList<SearchResult<T>>(K);
|
||||
|
||||
if (K > 0) {
|
||||
IntStack stack = new IntStack();
|
||||
PrioQueue<T> results = new PrioQueue<T>(K, true);
|
||||
|
||||
stack.push(root.index);
|
||||
|
||||
int added = 0;
|
||||
|
||||
while (stack.size() > 0) {
|
||||
int nodeIndex = stack.pop();
|
||||
if (added < K || results.peekPrio() > pointRectDist(nodeIndex, searchLocation)) {
|
||||
Node node = nodeList.get(nodeIndex);
|
||||
if (node.pointLocations == null)
|
||||
node.search(searchLocation, stack);
|
||||
else
|
||||
added += node.search(searchLocation, results);
|
||||
}
|
||||
}
|
||||
|
||||
double[] priorities = results.priorities;
|
||||
Object[] elements = results.elements;
|
||||
for (int i = 0; i < K; i++) { // forward (closest first)
|
||||
SearchResult<T> s = new SearchResult<T>(priorities[i], (T) elements[i]);
|
||||
returnResults.add(s);
|
||||
}
|
||||
}
|
||||
return returnResults;
|
||||
}
|
||||
|
||||
public ArrayList<T> ballSearch(double[] searchLocation, double radius) {
|
||||
IntStack stack = new IntStack();
|
||||
ArrayList<T> results = new ArrayList<T>();
|
||||
|
||||
stack.push(root.index);
|
||||
|
||||
while (stack.size() > 0) {
|
||||
int nodeIndex = stack.pop();
|
||||
if (radius > pointRectDist(nodeIndex, searchLocation)) {
|
||||
Node node = nodeList.get(nodeIndex);
|
||||
if (node.pointLocations == null)
|
||||
stack.push(node.moreIndex).push(node.lessIndex);
|
||||
else
|
||||
node.searchBall(searchLocation, radius, results);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public ArrayList<T> rectSearch(double[] mins, double[] maxs) {
|
||||
IntStack stack = new IntStack();
|
||||
ArrayList<T> results = new ArrayList<T>();
|
||||
|
||||
stack.push(root.index);
|
||||
|
||||
while (stack.size() > 0) {
|
||||
int nodeIndex = stack.pop();
|
||||
if (overlaps(mins, maxs, nodeIndex)) {
|
||||
Node node = nodeList.get(nodeIndex);
|
||||
if (node.pointLocations == null)
|
||||
stack.push(node.moreIndex).push(node.lessIndex);
|
||||
else
|
||||
node.searchRect(mins, maxs, results);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
||||
}
|
||||
|
||||
abstract double pointRectDist(int offset, final double[] location);
|
||||
|
||||
abstract double pointDist(double[] arr, double[] location, int index);
|
||||
|
||||
boolean contains(double[] arr, double[] mins, double[] maxs, int index) {
|
||||
|
||||
int offset = (index + 1) * mins.length;
|
||||
|
||||
for (int i = mins.length; i-- > 0;) {
|
||||
double d = arr[--offset];
|
||||
if (mins[i] > d | d > maxs[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean overlaps(double[] mins, double[] maxs, int offset) {
|
||||
offset *= (2 * maxs.length);
|
||||
final double[] array = nodeMinMaxBounds.array;
|
||||
for (int i = 0; i < maxs.length; i++, offset += 2) {
|
||||
double bmin = array[offset], bmax = array[offset + 1];
|
||||
if (mins[i] > bmax | maxs[i] < bmin)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Euclidean<T> extends KDTree<T> {
|
||||
public Euclidean(int dims) {
|
||||
super(dims);
|
||||
}
|
||||
|
||||
double pointRectDist(int offset, final double[] location) {
|
||||
offset *= (2 * super._dimensions);
|
||||
double distance = 0;
|
||||
final double[] array = super.nodeMinMaxBounds.array;
|
||||
for (int i = 0; i < location.length; i++, offset += 2) {
|
||||
|
||||
double diff = 0;
|
||||
double bv = array[offset];
|
||||
double lv = location[i];
|
||||
if (bv > lv)
|
||||
diff = bv - lv;
|
||||
else {
|
||||
bv = array[offset + 1];
|
||||
if (lv > bv)
|
||||
diff = lv - bv;
|
||||
}
|
||||
distance += sqr(diff);
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
double pointDist(double[] arr, double[] location, int index) {
|
||||
double distance = 0;
|
||||
int offset = (index + 1) * super._dimensions;
|
||||
|
||||
for (int i = super._dimensions; i-- > 0;) {
|
||||
distance += sqr(arr[--offset] - location[i]);
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Manhattan<T> extends KDTree<T> {
|
||||
public Manhattan(int dims) {
|
||||
super(dims);
|
||||
}
|
||||
|
||||
double pointRectDist(int offset, final double[] location) {
|
||||
offset *= (2 * super._dimensions);
|
||||
double distance = 0;
|
||||
final double[] array = super.nodeMinMaxBounds.array;
|
||||
for (int i = 0; i < location.length; i++, offset += 2) {
|
||||
|
||||
double diff = 0;
|
||||
double bv = array[offset];
|
||||
double lv = location[i];
|
||||
if (bv > lv)
|
||||
diff = bv - lv;
|
||||
else {
|
||||
bv = array[offset + 1];
|
||||
if (lv > bv)
|
||||
diff = lv - bv;
|
||||
}
|
||||
distance += (diff);
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
double pointDist(double[] arr, double[] location, int index) {
|
||||
double distance = 0;
|
||||
int offset = (index + 1) * super._dimensions;
|
||||
|
||||
for (int i = super._dimensions; i-- > 0;) {
|
||||
distance += Math.abs(arr[--offset] - location[i]);
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WeightedManhattan<T> extends KDTree<T> {
|
||||
private double[] weights;
|
||||
|
||||
public WeightedManhattan(int dims) {
|
||||
super(dims);
|
||||
}
|
||||
|
||||
public void setWeights(double[] newWeights) {
|
||||
weights = newWeights;
|
||||
}
|
||||
|
||||
double pointRectDist(int offset, final double[] location) {
|
||||
offset *= (2 * super._dimensions);
|
||||
double distance = 0;
|
||||
final double[] array = super.nodeMinMaxBounds.array;
|
||||
for (int i = 0; i < location.length; i++, offset += 2) {
|
||||
|
||||
double diff = 0;
|
||||
double bv = array[offset];
|
||||
double lv = location[i];
|
||||
if (bv > lv)
|
||||
diff = bv - lv;
|
||||
else {
|
||||
bv = array[offset + 1];
|
||||
if (lv > bv)
|
||||
diff = lv - bv;
|
||||
}
|
||||
distance += (diff) * weights[i];
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
double pointDist(double[] arr, double[] location, int index) {
|
||||
double distance = 0;
|
||||
int offset = (index + 1) * super._dimensions;
|
||||
|
||||
for (int i = super._dimensions; i-- > 0;) {
|
||||
distance += Math.abs(arr[--offset] - location[i]) * weights[i];
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchResult<S> {
|
||||
public double distance;
|
||||
public S payload;
|
||||
|
||||
SearchResult(double dist, S load) {
|
||||
distance = dist;
|
||||
payload = load;
|
||||
}
|
||||
}
|
||||
|
||||
private class Node {
|
||||
|
||||
// for accessing bounding box data
|
||||
// - if trees weren't so unbalanced might be better to use an implicit
|
||||
// heap?
|
||||
int index;
|
||||
|
||||
// keep track of size of subtree
|
||||
int entries;
|
||||
|
||||
// leaf
|
||||
ContiguousDoubleArrayList pointLocations;
|
||||
ArrayList<T> pointPayloads = new ArrayList<T>(_bucketSize);
|
||||
|
||||
// stem
|
||||
// Node less, more;
|
||||
int lessIndex, moreIndex;
|
||||
int splitDim;
|
||||
double splitVal;
|
||||
|
||||
Node() {
|
||||
this(new double[_bucketSize * _dimensions]);
|
||||
}
|
||||
|
||||
Node(double[] pointMemory) {
|
||||
pointLocations = new ContiguousDoubleArrayList(pointMemory);
|
||||
index = _nodes++;
|
||||
nodeList.add(this);
|
||||
nodeMinMaxBounds.add(bounds_template);
|
||||
}
|
||||
|
||||
void search(double[] searchLocation, IntStack stack) {
|
||||
if (searchLocation[splitDim] < splitVal)
|
||||
stack.push(moreIndex).push(lessIndex); // less will be popped
|
||||
// first
|
||||
else
|
||||
stack.push(lessIndex).push(moreIndex); // more will be popped
|
||||
// first
|
||||
}
|
||||
|
||||
// returns number of points added to results
|
||||
int search(double[] searchLocation, PrioQueue<T> results) {
|
||||
int updated = 0;
|
||||
for (int j = entries; j-- > 0;) {
|
||||
double distance = pointDist(pointLocations.array, searchLocation, j);
|
||||
if (results.peekPrio() > distance) {
|
||||
updated++;
|
||||
results.addNoGrow(pointPayloads.get(j), distance);
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
void searchBall(double[] searchLocation, double radius, ArrayList<T> results) {
|
||||
|
||||
for (int j = entries; j-- > 0;) {
|
||||
double distance = pointDist(pointLocations.array, searchLocation, j);
|
||||
if (radius >= distance) {
|
||||
results.add(pointPayloads.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void searchRect(double[] mins, double[] maxs, ArrayList<T> results) {
|
||||
|
||||
for (int j = entries; j-- > 0;)
|
||||
if (contains(pointLocations.array, mins, maxs, j))
|
||||
results.add(pointPayloads.get(j));
|
||||
|
||||
}
|
||||
|
||||
void expandBounds(double[] location) {
|
||||
entries++;
|
||||
int mio = index * 2 * _dimensions;
|
||||
for (int i = 0; i < _dimensions; i++) {
|
||||
nodeMinMaxBounds.array[mio] = Math.min(nodeMinMaxBounds.array[mio], location[i]);
|
||||
mio++;
|
||||
nodeMinMaxBounds.array[mio] = Math.max(nodeMinMaxBounds.array[mio], location[i]);
|
||||
mio++;
|
||||
}
|
||||
}
|
||||
|
||||
int add(double[] location, T load) {
|
||||
pointLocations.add(location);
|
||||
pointPayloads.add(load);
|
||||
return entries;
|
||||
}
|
||||
|
||||
void split() {
|
||||
int offset = index * 2 * _dimensions;
|
||||
|
||||
double diff = 0;
|
||||
for (int i = 0; i < _dimensions; i++) {
|
||||
double min = nodeMinMaxBounds.array[offset];
|
||||
double max = nodeMinMaxBounds.array[offset + 1];
|
||||
if (max - min > diff) {
|
||||
double mean = 0;
|
||||
for (int j = 0; j < entries; j++)
|
||||
mean += pointLocations.array[i + _dimensions * j];
|
||||
|
||||
mean = mean / entries;
|
||||
double varianceSum = 0;
|
||||
|
||||
for (int j = 0; j < entries; j++)
|
||||
varianceSum += sqr(mean - pointLocations.array[i + _dimensions * j]);
|
||||
|
||||
if (varianceSum > diff * entries) {
|
||||
diff = varianceSum / entries;
|
||||
splitVal = mean;
|
||||
|
||||
splitDim = i;
|
||||
}
|
||||
}
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
// kill all the nasties
|
||||
if (splitVal == Double.POSITIVE_INFINITY)
|
||||
splitVal = Double.MAX_VALUE;
|
||||
else if (splitVal == Double.NEGATIVE_INFINITY)
|
||||
splitVal = Double.MIN_VALUE;
|
||||
else if (splitVal == nodeMinMaxBounds.array[index * 2 * _dimensions + 2 * splitDim + 1])
|
||||
splitVal = nodeMinMaxBounds.array[index * 2 * _dimensions + 2 * splitDim];
|
||||
|
||||
Node less = new Node(mem_recycle); // recycle that memory!
|
||||
Node more = new Node();
|
||||
lessIndex = less.index;
|
||||
moreIndex = more.index;
|
||||
|
||||
// reduce garbage by factor of _bucketSize by recycling this array
|
||||
double[] pointLocation = new double[_dimensions];
|
||||
for (int i = 0; i < entries; i++) {
|
||||
System.arraycopy(pointLocations.array, i * _dimensions, pointLocation, 0, _dimensions);
|
||||
T load = pointPayloads.get(i);
|
||||
|
||||
if (pointLocation[splitDim] < splitVal) {
|
||||
less.expandBounds(pointLocation);
|
||||
less.add(pointLocation, load);
|
||||
}
|
||||
else {
|
||||
more.expandBounds(pointLocation);
|
||||
more.add(pointLocation, load);
|
||||
}
|
||||
}
|
||||
if (less.entries * more.entries == 0) {
|
||||
// one of them was 0, so the split was worthless. throw it away.
|
||||
_nodes -= 2; // recall that bounds memory
|
||||
nodeList.remove(moreIndex);
|
||||
nodeList.remove(lessIndex);
|
||||
}
|
||||
else {
|
||||
|
||||
// we won't be needing that now, so keep it for the next split
|
||||
// to reduce garbage
|
||||
mem_recycle = pointLocations.array;
|
||||
|
||||
pointLocations = null;
|
||||
|
||||
pointPayloads.clear();
|
||||
pointPayloads = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// NB! This Priority Queue keeps things with the LOWEST priority.
|
||||
// If you want highest priority items kept, negate your values
|
||||
private static class PrioQueue<S> {
|
||||
|
||||
Object[] elements;
|
||||
double[] priorities;
|
||||
private double minPrio;
|
||||
private int size;
|
||||
|
||||
PrioQueue(int size, boolean prefill) {
|
||||
elements = new Object[size];
|
||||
priorities = new double[size];
|
||||
Arrays.fill(priorities, Double.POSITIVE_INFINITY);
|
||||
if (prefill) {
|
||||
minPrio = Double.POSITIVE_INFINITY;
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
// uses O(log(n)) comparisons and one big shift of size O(N)
|
||||
// and is MUCH simpler than a heap --> faster on small sets, faster JIT
|
||||
|
||||
void addNoGrow(S value, double priority) {
|
||||
int index = searchFor(priority);
|
||||
int nextIndex = index + 1;
|
||||
int length = size - nextIndex;
|
||||
System.arraycopy(elements, index, elements, nextIndex, length);
|
||||
System.arraycopy(priorities, index, priorities, nextIndex, length);
|
||||
elements[index] = value;
|
||||
priorities[index] = priority;
|
||||
|
||||
minPrio = priorities[size - 1];
|
||||
}
|
||||
|
||||
int searchFor(double priority) {
|
||||
int i = size - 1;
|
||||
int j = 0;
|
||||
while (i >= j) {
|
||||
int index = (i + j) >>> 1;
|
||||
if (priorities[index] < priority)
|
||||
j = index + 1;
|
||||
else
|
||||
i = index - 1;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
double peekPrio() {
|
||||
return minPrio;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContiguousDoubleArrayList {
|
||||
double[] array;
|
||||
int size;
|
||||
|
||||
ContiguousDoubleArrayList(int size) {
|
||||
this(new double[size]);
|
||||
}
|
||||
|
||||
ContiguousDoubleArrayList(double[] data) {
|
||||
array = data;
|
||||
}
|
||||
|
||||
ContiguousDoubleArrayList add(double[] da) {
|
||||
if (size + da.length > array.length)
|
||||
array = Arrays.copyOf(array, (array.length + da.length) * 2);
|
||||
|
||||
System.arraycopy(da, 0, array, size, da.length);
|
||||
size += da.length;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IntStack {
|
||||
int[] array;
|
||||
int size;
|
||||
|
||||
IntStack() {
|
||||
this(64);
|
||||
}
|
||||
|
||||
IntStack(int size) {
|
||||
this(new int[size]);
|
||||
}
|
||||
|
||||
IntStack(int[] data) {
|
||||
array = data;
|
||||
}
|
||||
|
||||
IntStack push(int i) {
|
||||
if (size >= array.length)
|
||||
array = Arrays.copyOf(array, (array.length + 1) * 2);
|
||||
|
||||
array[size++] = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
int pop() {
|
||||
return array[--size];
|
||||
}
|
||||
|
||||
int size() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
static final double sqr(double d) {
|
||||
return d * d;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user