Difference between revisions of "User talk:Awesomeness"

From Robowiki
Jump to navigation Jump to search
(→‎THANK YOU: reversed y azis make life easier)
(American flag)
 
(24 intermediate revisions by 5 users not shown)
Line 2: Line 2:
 
| title = Archived talks
 
| title = Archived talks
 
| page1 = Archived Talk 20090502
 
| page1 = Archived Talk 20090502
 +
| page2 = Archived Talk 20090504
 
}}
 
}}
  
Okay, I need to make a list of bullets.  I have made a bullet class and everything, but I need a special list that will let me access all of the bullets in a while/for loop and be able to add and remove them at any time and never mess up.  If I did this in a normal array I could do a for loop and access using an increasing number, but I wouldn't know when to stop. In a while loop, if I used while(bulletsArray[x] != null) and then increment x, after I remove my first bullet that say, hit a wall, it will stop there.  I need help!
+
Help! I can't edit any pages because of some stupid database error! --[[User:Awesomeness|Awesomeness]] 21:57, 6 May 2009 (UTC)
  
:Thanks,
+
:Hey, it works now...  --[[User:Awesomeness|Awesomeness]] 22:00, 6 May 2009 (UTC)
::[[User:Awesomeness|Awesomeness]] 14:02, 2 May 2009 (UTC)
 
  
I think this will do:
+
Okay, I'm almost done with the prototype of my bot. It's really big, so I'll put it [[PwnBot/Current_Code|here]]. I'm sure it has lots of problems with the antigrav movement, (just look at the console, which shows the x force and y force that the points generate) and I'm sure it doesn't work at all... However, do take a look at the debug graphics, I think they're cool. =)
<pre>
+
--[[User:Awesomeness|Awesomeness]] 20:52, 4 May 2009 (UTC)
ArrayList<Bullet> bullets = new ArrayList<Bullet>();
 
for (int i = 0; i < bullets.size(); i++) {
 
    Bullet bullet = bullets.get(i);
 
    if (bullet.needRemove()) {
 
        // I think this will work
 
        // bullets.remove(i--);
 
        // but usually I do
 
        bullets.remove(bullet);
 
        i--;
 
    }
 
}
 
</pre>
 
Here I assume that you use ArrayList to store you bullets and your bullet's classname is Bullet. If you use a plain array to keep the bullets, consider change to ArrayList. It is more flexible. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 14:09, 2 May 2009 (UTC)
 
  
:Oh my goshYou're rightArrayList is way more flexible! I looked at the documentation; you don't even have to increment or decrement anything!  The function remove() shifts the other elements to the left already!  Thanks!  [[User:Awesomeness|Awesomeness]] 14:14, 2 May 2009 (UTC)
+
:OH NOSomething I did with the antigrav code messed up the bullet sim codeGood thing I backed up the non-broken version before I added antigrav.  Should I show that one instead? I can't figure out how to add antigrav, I guess I'm simply just not good enough.  Oh well... =(   --[[User:Awesomeness|Awesomeness]] 20:58, 4 May 2009 (UTC)
  
:: Be sure don't use for-each style (<code>for(Bullet bullet : bullets)</code> or you will get ConcurentModificationException when you remove element (this is per java spec, but I still use the for-each style and didn't get this exception actually). And when you scroll through the array like one I mentioned, be sure you do i--, or you will just skip one element. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 14:19, 2 May 2009 (UTC)
+
:: Don't say that - you wouldn't believe how buggy the first version of [[Dookious]] was. =) And I had been programming for years, and had four semesters of Computer Science study under my belt. Seriously, keep at it, dude... --[[User:Voidious|Voidious]] 21:04, 4 May 2009 (UTC)
  
:: Oh, you're right.  [[User:Awesomeness|Awesomeness]] 14:27, 2 May 2009 (UTC)
+
::: I'm going to put the before-I-messed-it-up code on instead--[[User:Awesomeness|Awesomeness]] 22:11, 4 May 2009 (UTC)
  
: One suggestion. Don't use <code>bullets.remove(bullet);</code>, use <code>bullets.remove(i);</code> instead because removing by index is far faster than removing by content. Well, with the size the list is in robocode it probably doesn't matter a ton, but removal of list by content, when you already have the index on hand, seems terribly wasteful to me. --[[User:Rednaxela|Rednaxela]] 14:45, 2 May 2009 (UTC)
+
What do you think of my targeting idea on my userpage? --[[User:Awesomeness|Awesomeness]] 00:44, 7 May 2009 (UTC)
  
: I changed that myself already. =D lol  [[User:Awesomeness|Awesomeness]] 14:56, 2 May 2009 (UTC)
+
: I think I've seen something like this before but I don't remember which so don't care. Now, I understand how I recorded thing to tree, but how it find the match? &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 01:19, 7 May 2009 (UTC)
  
I've grown very fond of iterators for Lists, this would be my implementation:
+
:: It would look through every branch in the tree, and it will look for matches.  It simply takes the current speed, acceleration, turn rate, etc. and finds the closest match, or matches. If there are multiple branches that match, it would take the branch that occurs most. I suppose if they're even in occurence it might pick them randomly. Then again, it might balance out, choosing based on the closeness of the match and the number of occurences combined. There's lot's of ways to do it. --[[User:Awesomeness|Awesomeness]] 01:50, 7 May 2009 (UTC)
<pre>
 
ArrayList<Bullet> bullets = new ArrayList<Bullet>();
 
Iterator<Bullet> i = bullets.iterator();
 
while (i.hasNext()) {
 
    Bullet bullet = i.next();
 
    if (bullet.needRemove()) {
 
        i.remove();
 
    }
 
}
 
</pre> --[[User:Skilgannon|Skilgannon]] 15:00, 2 May 2009 (UTC)
 
: Ahhh... I never knew that iterator has remove method so I always using ArrayLisy.get(i) to prevent ConcurentModificationException. Thanks you very much. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 15:06, 2 May 2009 (UTC)
 
  
: Actually, I'm very fond of them myself, and what gives you the best [[wikipedia:Big O notation|asymptotic speed]] is using LinkedList with Iterator.remove(), because with that method is never needs to recopy parts of the list to shift them over. Note, 'best asymptotic speed', means that it's the fastest for very very large numbers of list elements, and that if the list is small ArrayList/iterator is faster. To find out what "small" is defined as, one would need to benchmark it, and it is somewhat dependant on the particular computer. Also ArrayList/index is ''slightly'' faster than ArrayList/iterator version in all cases because the ArrayList/iterator version incurs overhead for function calls but in effect does the same thing. --[[User:Rednaxela|Rednaxela]] 19:16, 2 May 2009 (UTC)
+
::: OK, I think I remember which now. [[LambdaBot]]'s state searching. =P &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 01:55, 7 May 2009 (UTC)
----
 
  
How do you find the x and y of a robot you've scanned? I see no <code>ScannedRobotEvent.getX()</code> or <code>getY()</code> method.  [[User:Awesomeness|Awesomeness]] 15:19, 2 May 2009 (UTC)
+
:::: It seems none of my ideas are ever new.  Man!  Everyone's thought of everything! Either way, I suppose mine might still be new because i'ts a targeting implementation, not movement--[[User:Awesomeness|Awesomeness]] 01:58, 7 May 2009 (UTC)
  
Trig Trig Trig...
+
:::::  If I'd thought of it just a bit earlier, it'd finally be my first original idea... --[[User:Awesomeness|Awesomeness]] 02:02, 7 May 2009 (UTC)
<pre>
 
double absBearing = e.getBearingRadians() + getHeadingRadians();
 
double x = getX() + Math.sin(absBearing) * e.getDistance();
 
double y = getY() + Math.cos(absBearing) * e.getDistance();
 
</pre>
 
That's all. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 15:21, 2 May 2009 (UTC)
 
  
Here's a method I use in my utils class (I first saw it in a [[PEZ]] bot):
+
:::::: Hey, usually we all share many of common ideas, but who can conclude every single step with detailed information will be the inventor =D ABC might be the inventor of Wave Surfing, but many bots have done similar to Wave Surfing, but ABC can conclude what to done before another people. Pual might be inventor of GuessFactor Targeting but David have done thing similar to in the same time. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 02:09, 7 May 2009 (UTC)
<pre>
 
    public static Point2D.Double project(Point2D.Double sourceLocation,  
 
        double angle, double length) {
 
        return new Point2D.Double(sourceLocation.x + Math.sin(angle) * length,
 
            sourceLocation.y + Math.cos(angle) * length);
 
    }
 
    // You'd pass it something like:  
 
    // myLocation = new Point2D.Double(getX(), getY());  
 
    // enemyLocation = MyUtils.project(myLocation, absBearing, e.getDistance());
 
</pre>
 
--[[User:Voidious|Voidious]] 16:15, 2 May 2009 (UTC)
 
  
 +
::::::: Yeah, I suppose you're right.  I'm going to try to make the gun eventually.  It'll be pretty hard.  --[[User:Awesomeness|Awesomeness]] 02:13, 7 May 2009 (UTC)
  
Lastly, I need a way to "dodge" these simulated bullets and to figure out what angle the oppenent bot would be shooting from if it used linear targeting against meI don't know how to do either of these. [[User:Awesomeness|Awesomeness]] 16:31, 2 May 2009 (UTC)
+
::::: Just creating a new bot is inventing.  There are always new takes on old ideas, ways to tweak something that's been done and make it betterWhat flag do you want in the rumble? --[[User:Darkcanuck|Darkcanuck]] 02:23, 7 May 2009 (UTC)
  
To dodge, use [[Anti-Gravity Movement]], to assume linear firing, use this code:
+
:::::: American, please.  --[[User:Awesomeness|Awesomeness]] 17:13, 10 May 2009 (UTC)
<pre>
 
angle = Utils.normalRelativeAngle(absBearing + Math.PI + Math.asin((Math.sin(e.getBearingRadians()) * getVelocity())/(20 - 3 * BULLET_POWER)));
 
</pre>
 
replace BULLET_POWER to which you get from energy drop. This prediction use non-iterative no-wall-stopping linear targeting. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 16:35, 2 May 2009 (UTC)
 
  
:Thanks!  This fits exactly what I was planning to do!  [[User:Awesomeness|Awesomeness]] 16:44, 2 May 2009 (UTC)
+
Wow, thanks for clearing it! &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 08:21, 10 May 2009 (UTC)
:However anti-gravity confuses me greatly...  [[User:Awesomeness|Awesomeness]] 17:11, 2 May 2009 (UTC)
 
 
 
 
 
UGH!  I worked so hard on this and look what it does!  Enable the debug graphics to see where it thinks the bullets are...  Theres no point in working on antigrav movement until I fix this.
 
Program:
 
<pre>package awesomeness;
 
import robocode.*;
 
import robocode.util.*;
 
import java.util.Random;
 
import java.util.ArrayList;
 
import java.awt.*;
 
 
 
/**
 
* PwnBot - a robot by (your name here)
 
*/
 
public class PwnBot extends AdvancedRobot {
 
 
static StringBuffer pattern = new StringBuffer("" + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)-8 + (char)-7 + (char)-6 + (char)-5 + (char)-4 + (char)-3 + (char)-2 + (char)-1 + (char)1 + (char)2 + (char)3 + (char)4 + (char)5 + (char)6 + (char)7 + (char)8);
 
 
static double previousEnergy = 100d;
 
static double changeInEnergy;
 
//static double totalBulletDist;
 
//double[] bulletDists;
 
 
 
static int movementDirection = 50;
 
static long lastTime; //The last time known, used to track bullets
 
 
static Random generator = new Random(); //This makes random numbers
 
ArrayList<VirtualBullet> bullets = new ArrayList<VirtualBullet>();
 
static VirtualBullet newBullet, bullet;
 
 
public void run() {
 
lastTime = 0;
 
setAdjustGunForRobotTurn(true);
 
turnRadarRightRadians(Double.POSITIVE_INFINITY);
 
}
 
 
 
/**
 
* onScannedRobot: What to do when you see another robot
 
*/
 
public void onScannedRobot(ScannedRobotEvent e) {
 
 
//The absolute bearing, this is used a lot
 
double absoluteBearing = getHeadingRadians() + e.getBearingRadians(); ;
 
 
///////////////////////////////////////////////////////
 
////////////////////Movement Code//////////////////////
 
 
/////////////////////Bullet Code///////////////////////
 
 
//If there's a change in energy, it probably fired
 
 
 
if ((changeInEnergy = previousEnergy - (previousEnergy = e.getEnergy())) > 0d && changeInEnergy<=3.01) {
 
 
newBullet = new VirtualBullet(getX() + Math.sin(absoluteBearing) * e.getDistance(), getY() + Math.cos(absoluteBearing) * e.getDistance(), 20 - 3 * changeInEnergy, Utils.normalRelativeAngle(absoluteBearing +  Math.PI + Math.asin((Math.sin(e.getBearingRadians()) * getVelocity())/(20 - 3 * changeInEnergy))));
 
newBullet.tick(1);
 
bullets.add(newBullet);
 
 
 
}
 
 
 
for (int i = 0; i < bullets.size(); i++) {
 
bullet = bullets.get(i);
 
bullet.tick(getTime() - lastTime);
 
bullets.set(i, bullet);
 
 
if (bullets.get(i).checkHitWall()) {
 
// I think this will work
 
// bullets.remove(i--);
 
// but usually I do
 
bullets.remove(i);
 
i--;
 
}
 
 
//bulletDists[i] = bullets.get(i).getDistance(getX(), getY());
 
//totalBulletDist += bullets.get(i).getDistance(getX(), getY());
 
 
}
 
 
///////////////////End Bullet Code/////////////////////
 
 
 
//Stay at almost right angles
 
//setTurnRightRadians(Math.cos(absoluteBearing+(-0.003*movementDirection)));
 
 
//setAhead(movementDirection);
 
 
 
 
////////////////////Movement Code//////////////////////
 
///////////////////////////////////////////////////////
 
 
///////////////////////////////////////////////////////
 
///////////////////////Gun Code////////////////////////
 
 
double absbearing;
 
absbearing = (e.getBearingRadians()-Math.PI/2)+1.57079633;
 
//rounding to be more accurate in projection!
 
pattern.insert(0, (char)(Math.round(Math.sin(e.getHeadingRadians() - (absbearing = absbearing + getHeadingRadians()))*e.getVelocity())));
 
 
int index=0, searchlength = 30;
 
//lol, if I ever make a haiku pattern-matcher, this will be in it:
 
while ((index = pattern.toString().indexOf(pattern.substring(0, searchlength--), 1)) < 0);
 
 
//searchlength will now become the index of the StringBuffer that I will project back to (back because my pattern
 
//is stored backward).
 
double power;
 
double dist;
 
searchlength =  index - (int)((dist = e.getDistance())/(20-(power = Math.min(3, Math.min(getEnergy(), e.getEnergy())/4))*3));
 
 
//just add the offset to the bearing instead of making a new variable!
 
//The fact that this actually reconstructs future movement (like a normal pattern-matcher does) probably makes this
 
//just about the most accurate current nano pattern-matcher (except possibly Kakuru's, since it uses doubles instead of
 
//characters).  The nice thing about it is that it correctly projects patterns even if I'm at a different distance than
 
//when I collected the pattern.
 
do
 
{
 
absbearing += Math.asin(((byte)pattern.charAt(index--))/dist);
 
}
 
while (index >= Math.max(0, searchlength));
 
 
setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(absbearing - getGunHeadingRadians()));
 
setFire(power);
 
 
 
///////////////////////Gun Code////////////////////////
 
///////////////////////////////////////////////////////
 
 
 
 
///////////////////////////////////////////////////////
 
/////////////////////Radar Code////////////////////////
 
 
setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
 
 
 
/////////////////////Radar Code////////////////////////
 
///////////////////////////////////////////////////////
 
 
 
lastTime = getTime();
 
 
}
 
 
 
public void onHitWall(HitWallEvent e) {
 
i();
 
}
 
 
public void i() {
 
movementDirection = -movementDirection;
 
}
 
 
 
// Paint a transparent square on top of the last scanned robot
 
public void onPaint(Graphics2D g) {
 
// Set the paint color to a red half transparent color
 
g.setColor(new Color(0xff, 0x00, 0x00, 0x80));
 
 
 
for (int i = 0; i < bullets.size(); i++) {
 
bullet = bullets.get(i);
 
 
 
g.drawLine( (int) bullet.getX(), (int) bullet.getY(), (int)getX(), (int)getY());
 
 
// Draw a filled square on top of the scanned robot that covers it
 
g.fillRect( (int) bullet.getX() - 5, (int) bullet.getY() - 5, 10, 10);
 
 
 
}
 
}
 
 
 
public class VirtualBullet {  //A class to simulate bullets.
 
 
double x, y, speed, angle;
 
 
 
VirtualBullet(double startX, double startY, double velocity, double trajectory) {
 
x = startX;
 
y = startY;
 
speed = velocity;
 
angle = trajectory;
 
}
 
 
public void tick(long ticks) {  //Moves the bullet the amount it would
 
while(ticks > 0) {
 
x += Math.sin(angle)*speed;
 
y += Math.cos(angle)*speed;
 
ticks --;
 
}
 
}
 
 
public double getX() {
 
return x;
 
}
 
 
public double getY() {
 
return y;
 
}
 
 
public double getDistance(double botX, double botY) {
 
return Math.sqrt(Math.pow(botX-x, 2)+Math.pow(botY-y, 2));
 
}
 
 
 
public boolean checkHitWall() {
 
if (x < 0 || y < 0 || x > getBattleFieldWidth() || y > getBattleFieldHeight()) {
 
return true;
 
}
 
return false;
 
}
 
 
}
 
 
}
 
 
</pre>
 
 
 
=( [[User:Awesomeness|Awesomeness]] 17:28, 2 May 2009 (UTC)
 
 
 
First, '''Robobocode trig is not same as your Math class trig'''. It should be:
 
<pre>
 
 
 
 
public void tick(long ticks) {  //Moves the bullet the amount it would
 
while(ticks > 0) {
 
x += Math.sin(angle)*speed;
 
y += Math.cos(angle)*speed;
 
ticks --;
 
}
 
}
 
</pre>
 
And when you detect energy drop, '''bullet already move one tick!''', mean that you must advace bullet one tick when you add it. And, the absBearing you use in position calculation is not yet an absoluteBearing since it just e.getBearingRadians() because I use codesize trick. But if you are creating megabot, try remove all the codesize trick and make the code more readable. (or less ugly) Few suggestion:
 
* Check for energy change in onBulletHit, onHitByBullet too because the robot loss/gain energy when hitbybullet/bullethit.
 
* use more acculate radar lock, or you can't detect bullet acculately.
 
&raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 02:27, 3 May 2009 (UTC)
 
 
 
:I have partially fixed it.  It still fails miserably.  I added a bit more debug graphics, which attempts to make a line from the bullet to PwnBot, but it doesn't work either.  This confuses me...  One end of the line should be touching my bot.
 
:: What you fixed? I fix to this code and it work correct as far as I can tell. I '''cannot''' be 100% accurate. I think just 80% is ''very'' good. This is my modified code:
 
<pre>
 
package awesomeness;
 
import robocode.*;
 
import robocode.util.*;
 
import java.util.Random;
 
import java.util.ArrayList;
 
import java.awt.*;
 
 
 
/**
 
* PwnBot - a robot by (your name here)
 
*/
 
public class PwnBot extends AdvancedRobot {
 
 
static StringBuffer pattern = new StringBuffer("" + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)0 + (char)-8 + (char)-7 + (char)-6 + (char)-5 + (char)-4 + (char)-3 + (char)-2 + (char)-1 + (char)1 + (char)2 + (char)3 + (char)4 + (char)5 + (char)6 + (char)7 + (char)8);
 
 
static double previousEnergy = 100d;
 
static double changeInEnergy;
 
//static double totalBulletDist;
 
//double[] bulletDists;
 
 
 
static int movementDirection = 50;
 
static long lastTime; //The last time known, used to track bullets
 
 
static Random generator = new Random(); //This makes random numbers
 
ArrayList<VirtualBullet> bullets = new ArrayList<VirtualBullet>();
 
static VirtualBullet newBullet, bullet;
 
 
public void run() {
 
lastTime = 0;
 
setAdjustGunForRobotTurn(true);
 
setAdjustRadarForGunTurn(true);
 
setAdjustRadarForRobotTurn(true);
 
while(true)
 
turnRadarRightRadians(Double.POSITIVE_INFINITY);
 
}
 
 
 
/**
 
* onScannedRobot: What to do when you see another robot
 
*/
 
public void onScannedRobot(ScannedRobotEvent e) {
 
 
//The absolute bearing, this is used a lot
 
double absoluteBearing = e.getBearingRadians() + getHeadingRadians();
 
 
///////////////////////////////////////////////////////
 
////////////////////Movement Code//////////////////////
 
 
/////////////////////Bullet Code///////////////////////
 
 
//If there's a change in energy, it probably fired
 
 
 
if ((changeInEnergy = previousEnergy - (previousEnergy = e.getEnergy())) > 0d && changeInEnergy<=3) {
 
 
newBullet = new VirtualBullet(getX() + Math.sin(absoluteBearing) * e.getDistance(), getY() + Math.cos(absoluteBearing) * e.getDistance(), 20 - 3 * changeInEnergy, Utils.normalRelativeAngle(absoluteBearing +  Math.PI + Math.asin((Math.sin(e.getBearingRadians()) * getVelocity())/(20 - 3 * changeInEnergy))));
 
bullets.add(newBullet);
 
 
 
}
 
 
 
for (int i = 0; i < bullets.size(); i++) {
 
bullet = bullets.get(i);
 
bullet.tick(getTime() - lastTime);
 
bullets.set(i, bullet);
 
 
if (bullets.get(i).checkHitWall()) {
 
// I think this will work
 
// bullets.remove(i--);
 
// but usually I do
 
bullets.remove(i);
 
i--;
 
}
 
 
//bulletDists[i] = bullets.get(i).getDistance(getX(), getY());
 
//totalBulletDist += bullets.get(i).getDistance(getX(), getY());
 
 
}
 
 
///////////////////End Bullet Code/////////////////////
 
 
 
//Stay at almost right angles
 
setTurnRightRadians(Utils.normalRelativeAngle(absoluteBearing + Math.PI/2 - getHeadingRadians()));
 
 
setAhead(movementDirection);
 
 
if (Math.random() > 0.92) i();
 
 
 
 
////////////////////Movement Code//////////////////////
 
///////////////////////////////////////////////////////
 
 
///////////////////////////////////////////////////////
 
///////////////////////Gun Code////////////////////////
 
 
double absbearing;
 
absbearing = absoluteBearing;
 
//rounding to be more accurate in projection!
 
pattern.insert(0, (char)(Math.round(Math.sin(e.getHeadingRadians() - (absbearing))*e.getVelocity())));
 
 
int index=0, searchlength = 30;
 
//lol, if I ever make a haiku pattern-matcher, this will be in it:
 
while ((index = pattern.toString().indexOf(pattern.substring(0, searchlength--), 1)) < 0);
 
 
//searchlength will now become the index of the StringBuffer that I will project back to (back because my pattern
 
//is stored backward).
 
double power;
 
double dist;
 
searchlength =  index - (int)((dist = e.getDistance())/(20-(power = Math.min(3, Math.min(getEnergy(), e.getEnergy())/4))*3));
 
 
//just add the offset to the bearing instead of making a new variable!
 
//The fact that this actually reconstructs future movement (like a normal pattern-matcher does) probably makes this
 
//just about the most accurate current nano pattern-matcher (except possibly Kakuru's, since it uses doubles instead of
 
//characters).  The nice thing about it is that it correctly projects patterns even if I'm at a different distance than
 
//when I collected the pattern.
 
do
 
{
 
absbearing += Math.asin(((byte)pattern.charAt(index--))/dist);
 
}
 
while (index >= Math.max(0, searchlength));
 
 
setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(absbearing - getGunHeadingRadians()));
 
setFire(power);
 
 
 
///////////////////////Gun Code////////////////////////
 
///////////////////////////////////////////////////////
 
 
 
 
///////////////////////////////////////////////////////
 
/////////////////////Radar Code////////////////////////
 
 
 
setTurnRadarRightRadians(2 * Utils.normalRelativeAngle(absoluteBearing - getRadarHeadingRadians()));
 
 
 
/////////////////////Radar Code////////////////////////
 
///////////////////////////////////////////////////////
 
 
 
lastTime = getTime();
 
 
}
 
 
 
public void onHitWall(HitWallEvent e) {
 
i();
 
}
 
 
public void i() {
 
movementDirection = -movementDirection;
 
}
 
 
 
// Paint a transparent square on top of the last scanned robot
 
public void onPaint(Graphics2D g) {
 
// Set the paint color to a red half transparent color
 
g.setColor(new Color(0xff, 0x00, 0x00, 0x80));
 
 
 
for (int i = 0; i < bullets.size(); i++) {
 
bullet = bullets.get(i);
 
 
// Draw a filled square on top of the scanned robot that covers it
 
g.fillRect( (int) bullet.getX() - 5, (int) bullet.getY() - 5, 10, 10);
 
 
 
}
 
}
 
 
 
public void onHitByBullet(HitByBulletEvent e) { previousEnergy += 3 * e.getBullet().getPower(); }
 
public void onBulletHit(BulletHitEvent e) { previousEnergy -= 4 * e.getBullet().getPower() + Math.max(0,2 * (e.getBullet().getPower() - 1)); }
 
public void onHitRobot(HitRobotEvent e) { previousEnergy -= 0.6; }
 
 
 
public class VirtualBullet {  //A class to simulate bullets.
 
 
double x, y, speed, angle;
 
 
 
VirtualBullet(double startX, double startY, double velocity, double trajectory) {
 
x = startX;
 
y = startY;
 
speed = velocity;
 
angle = trajectory;
 
}
 
 
public void tick(long ticks) {  //Moves the bullet the amount it would
 
while(ticks > 0) {
 
x += Math.sin(angle)*speed;
 
y += Math.cos(angle)*speed;
 
ticks --;
 
}
 
}
 
 
public double getX() {
 
return x;
 
}
 
 
public double getY() {
 
return y;
 
}
 
 
public double getDistance(double botX, double botY) {
 
return Math.sqrt(Math.pow(botX-x, 2)+Math.pow(botY-y, 2));
 
}
 
 
 
public boolean checkHitWall() {
 
if (x < 0 || y < 0 || x > getBattleFieldWidth() || y > getBattleFieldHeight()) {
 
return true;
 
}
 
return false;
 
}
 
 
}
 
 
}
 
</pre>
 
:: I bet it 90% accurate, but you may see it doesn't accurate because enemy cannot turn the gun to it aim position in time before it fire. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 06:08, 3 May 2009 (UTC)
 
 
 
== THANK YOU ==
 
 
 
Thank you guys!  All of you!  Especially you, [[User:Nat|Nat]]!  I've made the official working code, all I have to do now is make them anti-gravity points!  You fixed almost everything, all I had to do was inverse the Y axis for some reason.  I don't know enough trig to fix whatever formula's going wrong.  But thank you!  YAY!
 
 
 
--[[User:Awesomeness|Awesomeness]] 17:09, 3 May 2009 (UTC)
 
 
 
:I just was browsing on the wiki...  =( My bullet dodging idea isn't original or new...  It's just this thing called "ShrapnelDodging"...  Aww...  --[[User:Awesomeness|Awesomeness]] 17:23, 3 May 2009 (UTC)
 
 
 
:: Robocode's been out quite a while, so it's very difficult to find 100% original ideas. It's just the way it is, try not to let it get you down! =) Glad to hear you got your stuff working. --[[User:Voidious|Voidious]] 17:27, 3 May 2009 (UTC)
 
 
 
:::You're right.  Besides, maybe I'll even change something.  Until I'm in highschool, I'll never have a full understanding of trigonometry, so I'll probably need help with that.  I might use this virtual bullet engine in my other bots.  It's not huge, but it'll never fit into a nano bot and probably not into a micro.  Currently, without any movement and including the graphical debugging, it's 691 bytes, and I'm sure it can be compressed.
 
--[[User:Awesomeness|Awesomeness]] 17:47, 3 May 2009 (UTC)
 
 
 
:::Actually, taking out the weak PM gun, the graphical debugging, and the weird movement I put in before I planned out the bullet sims and stuff I have now, (leaving only the basis of the bullet tracking itself) I get 409 bytes.  Is that good, or is that way more than what other people have made?
 
::::Oh, I just checked the [[Robocode/Game_Physics|game physics]], and I found out that the Y axis is well... reversed.  That's weird.  I don't like that.  Oh well.  [[User:Awesomeness|Awesomeness]] 19:59, 3 May 2009 (UTC)
 
::::: But that make a life more easier! &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 23:45, 3 May 2009 (UTC)
 

Latest revision as of 19:13, 10 May 2009

Archived talks:
Archived Talk 20090502 - Archived Talk 20090504

Help! I can't edit any pages because of some stupid database error! --Awesomeness 21:57, 6 May 2009 (UTC)

Hey, it works now... --Awesomeness 22:00, 6 May 2009 (UTC)

Okay, I'm almost done with the prototype of my bot. It's really big, so I'll put it here. I'm sure it has lots of problems with the antigrav movement, (just look at the console, which shows the x force and y force that the points generate) and I'm sure it doesn't work at all... However, do take a look at the debug graphics, I think they're cool. =) --Awesomeness 20:52, 4 May 2009 (UTC)

OH NO! Something I did with the antigrav code messed up the bullet sim code! Good thing I backed up the non-broken version before I added antigrav. Should I show that one instead? I can't figure out how to add antigrav, I guess I'm simply just not good enough. Oh well... =( --Awesomeness 20:58, 4 May 2009 (UTC)
Don't say that - you wouldn't believe how buggy the first version of Dookious was. =) And I had been programming for years, and had four semesters of Computer Science study under my belt. Seriously, keep at it, dude... --Voidious 21:04, 4 May 2009 (UTC)
I'm going to put the before-I-messed-it-up code on instead. --Awesomeness 22:11, 4 May 2009 (UTC)

What do you think of my targeting idea on my userpage? --Awesomeness 00:44, 7 May 2009 (UTC)

I think I've seen something like this before but I don't remember which so don't care. Now, I understand how I recorded thing to tree, but how it find the match? » Nat | Talk » 01:19, 7 May 2009 (UTC)
It would look through every branch in the tree, and it will look for matches. It simply takes the current speed, acceleration, turn rate, etc. and finds the closest match, or matches. If there are multiple branches that match, it would take the branch that occurs most. I suppose if they're even in occurence it might pick them randomly. Then again, it might balance out, choosing based on the closeness of the match and the number of occurences combined. There's lot's of ways to do it. --Awesomeness 01:50, 7 May 2009 (UTC)
OK, I think I remember which now. LambdaBot's state searching. =P » Nat | Talk » 01:55, 7 May 2009 (UTC)
It seems none of my ideas are ever new. Man! Everyone's thought of everything! Either way, I suppose mine might still be new because i'ts a targeting implementation, not movement. --Awesomeness 01:58, 7 May 2009 (UTC)
If I'd thought of it just a bit earlier, it'd finally be my first original idea... --Awesomeness 02:02, 7 May 2009 (UTC)
Hey, usually we all share many of common ideas, but who can conclude every single step with detailed information will be the inventor =D ABC might be the inventor of Wave Surfing, but many bots have done similar to Wave Surfing, but ABC can conclude what to done before another people. Pual might be inventor of GuessFactor Targeting but David have done thing similar to in the same time. » Nat | Talk » 02:09, 7 May 2009 (UTC)
Yeah, I suppose you're right. I'm going to try to make the gun eventually. It'll be pretty hard. --Awesomeness 02:13, 7 May 2009 (UTC)
Just creating a new bot is inventing. There are always new takes on old ideas, ways to tweak something that's been done and make it better. What flag do you want in the rumble? --Darkcanuck 02:23, 7 May 2009 (UTC)
American, please. --Awesomeness 17:13, 10 May 2009 (UTC)

Wow, thanks for clearing it! » Nat | Talk » 08:21, 10 May 2009 (UTC)