User talk:Realmoonstruck

From Robowiki
Jump to navigation Jump to search

Welcome!

Hello, Realmoonstruck, and welcome to RoboWiki! This place contains a wealth information about Robocode, from basic to more advanced. I hope you enjoy creating robots and being a robocoder!

If you are posting a comment on this wiki, please sign your messages using four tildes (--~~~~); this will automatically insert your username and the date stamp. If you are not familiar with MediaWiki, these links might help you out:

If you need help, check out the frequently asked questions or ask it on this page. Again, welcome!

—— RoboWiki Administrators

Competitive JuniorRobot

I have been trying to make competitive Junior Robots. This the best 1 vs 1 bot I could make till now...

package ne0n;

import robocode.*;

public class JuniorLinear extends JuniorRobot {
	int moveAmount;

	public void run() {
		setColors(black, white, red, orange, purple);
		moveAmount = Math.max(fieldWidth, fieldHeight);
		turnTo(0);

		while (true) {
			bearGunTo(90);
			ahead(moveAmount);
		}

	}

	public void onHitWall() {
		bearGunTo(90);
		turnRight(90);
	}

	public void onHitByBullet() {
		turnGunTo(hitByBulletAngle);
	}

	public void onHitRobot() {
		if (scannedBearing > -90 && scannedBearing < 90)
			back(100);
		else
			ahead(100);

	}

	public void onScannedRobot() {

		double firepower = 3d-2d*((double)scannedDistance/(double)moveAmount);
		double bulletVelocity = 20-3*firepower;
		double offset = Math.toDegrees(Math.asin(scannedVelocity*Math.sin(Math.toRadians(scannedHeading-scannedAngle))/bulletVelocity));
		turnGunTo((int)(scannedAngle + offset));
		fire(firepower);

	}

}

Tis moves in the same was as the Sample Walls. As the name suggests this uses simple trigonometric linear targeting. This has been able to beat all the Sample bots on 1 vs 1. But in melee Walls and SpinBot are beating me each time. I tried to implement some better movement and targeting strategies but couldn't get anything to work till now.

Any help will be appreciated... —Preceding unsigned comment added by Realmoonstruck (talkcontribs)

I am not entirely sure on how JuniorRobots work, but if I might suggest you stick to just radians or just degrees. Looking at your code it looks to be something like a simple linear targeting implementation. Radar handling may help somewhat. — Chase-san 14:21, 14 July 2010 (UTC)
Junior doesn't support radians, but Java Trig use radians. So when use Junior Robot we must convert back and forth. --Nat Pavasant 14:26, 14 July 2010 (UTC)

In sample bots melee it is better to fire head-on since many of sample robots are moving back-and-forth with make it impossible to hit with linear or circular. So in melee Walls and SpinBot will beat you. Maybe you may want to see oldwiki:Girl Robot. It should be quite easy to port over to Junior Robot, with melee features stripped... :( --Nat Pavasant 14:26, 14 July 2010 (UTC)

Thanks, i'll take a look at the girl. As for head-on targeting, I have tried it with no significant change in melee performance but slightly worse than this bot in 1vs1. If radar lock wont work, advanced targeting wont work then all that is left is movement, and this is the best movement strategy that i could work out on Junior. Nobody interested to work on a Junior? —Preceding unsigned comment added by Realmoonstruck (talkcontribs)
One note, is you really don't need a radar lock for advanced targeting. After all, my melee bot Glacier has one of the strongest melee guns in the rumble (maybe even the strongest), however it doesn't lock radar ever, because it never cares about having multiple consecutive ticks. I'm pretty sure I could port it to a Robot or JuniorRobot.
About why people don't use Robot or JuniorRobot much, probably mostly has to do with people not being that interested in the limitation of the robot being only able to move one part at a time. That said, people have experimented with it some in the past in the old "ExtendsRobotCompetition". --Rednaxela 23:08, 14 July 2010 (UTC)
Thanks, that was really helpful. But I have a question, is the radar not being independent the only shortcoming of the Junior? I ask because i have ported the Walls to a junior but still Walls beat me each time in the melee. I cant find any logical explanation for this.
package ne0n;
import robocode.*;
import java.awt.geom.*;
public class JuniorWalls extends JuniorRobot {

	boolean peek;
	int moveAmount;
	public void run() {
		moveAmount = Math.max(fieldWidth, fieldHeight);
		peek = false;
		
		//turn towards the nearest wall
		double bottomDist = Line2D.ptSegDist(0, 0, fieldWidth, 0, robotX, robotY);
		double rightDist = Line2D.ptSegDist(fieldWidth, 0, fieldWidth, fieldHeight, robotX, robotY);
		double topDist = Line2D.ptSegDist(fieldWidth, fieldHeight, 0, fieldHeight, robotX, robotY);
		double leftDist = Line2D.ptSegDist(0, fieldHeight, 0, 0, robotX, robotY);
		double minDist = Math.min(Math.min(bottomDist, rightDist), Math.min(topDist, leftDist));
		if (topDist == minDist)
			turnTo(0);
		else if (rightDist == minDist)
			turnTo(90);
		else if (bottomDist == minDist)
			turnTo(180);
		else
			turnTo(270);
			
		ahead(moveAmount);
		peek = true;
		bearGunTo(90);
		turnRight(90);

		while (true) {
			// Look before we turn when ahead() completes.
			peek = true;
			// Move up the wall
			ahead(moveAmount);
			// Don't look now
			peek = false;
			// Turn to the next wall
			turnRight(90);
		}
	}
	public void onHitRobot() {
		// If he's in front of us, set back up a bit.
		if (scannedBearing > -90 && scannedBearing < 90) {
			back(100);
		} // else he's in back of us, so set ahead a bit.
		else {
			ahead(100);
		}
	}
	public void onScannedRobot() {
		fire(2);
		//can't call scan() so moving my gun
		if (peek) {
			turnGunRight(1);
			turnGunLeft(1);
		}
	}
}

Realmoonstruck 07:49, 15 July 2010 (UTC)

similarly what is the difference between these two codes?

package ne0n;
import robocode.*;
public class JuniorTest extends JuniorRobot
{
	public void run() {
        turnGunRight((int)Double.POSITIVE_INFINITY); 
    }
    public void onScannedRobot(){
        fire(3);
    }
}

and

package ne0n;
import robocode.*;
public class RobotTest extends Robot
{
	public void run() {
        turnGunRight(Double.POSITIVE_INFINITY); 
    }
    public void onScannedRobot(ScannedRobotEvent e) {
        fire(3);
    }
}

The Junior doesn't fire a single shot.Realmoonstruck 17:05, 15 July 2010 (UTC)

Its the ScannedRobotEvent e. — Chase-san 10:46, 15 July 2010 (UTC)
The ScannedRobotEvent parameter is supposed to be that way for JuniorRobot Chase. Anyway, I did some testing and it seems that in JuniorRobot, the fire command won't take effect until AFTER the turnGunRight completes, also, run() is run repeatedly in JuniorRobot without the need for an internal loop, so what you need to do is make the turnGunRight call more like:
turnGunRight((int)robocode.Rules.GUN_TURN_RATE);
It also seems that it fires after the fire command automatically if gunheat was high, so to get the same effect, also need to make it like
if (gunReady) fire(3);
Also, that same "if (gunReady)" fix causes JuniorWalls to beat Walls, not sure why actually. --Rednaxela 13:15, 15 July 2010 (UTC)
I think better name for AdvancedRobot, Robot and JuniorRobot is EasyRobot, HardRobot, NightmareRobot, respectively. I actually try to port Girl once, but one-thing-per-time system is really annoying (in Robot we can do things at the same time if we do in different events) --Nat Pavasant 15:07, 15 July 2010 (UTC)
I'm not sure if thats totally true. Of course from RobotTest and JuniorTest it's evident that Junior cant fire while turning the gun but if you test the code below you'll see that Junior can fire while moving ahead or back. In that case it is doing two things at once isn't it? I have no idea what it was supposed to do, but the two cases seem like a contradiction in behavior to me. Maybe its a bug.

WallJunior

package ne0n;
import robocode.*;
public class WallJunior extends JuniorRobot
{
	public void run() {
		turnTo(180);
		turnGunRight(90);
		ahead(fieldHeight);
        	turnRight(90);
		while (true) {
			ahead(fieldWidth);
			back(fieldWidth);
		}
	}
	public void onScannedRobot(){
        	if (gunReady) fire(3);
	}
}

WallRobot

package ne0n;
import robocode.*;
public class WallRobot extends Robot
{
	public void run() {
		turnLeft(getHeading() % 360);
		turnGunRight(90);
		ahead(getBattleFieldHeight());
		turnRight(90);
		while (true) {
			ahead(getBattleFieldWidth());
			back(getBattleFieldWidth());
		}
	}
	public void onScannedRobot(ScannedRobotEvent e) {
		fire(3);
	}
}
By "beat Walls" do you mean in melee? In my testing JuniorWalls beat Walls at around 60:40 in 100 round 1 vs 1s (no idea how). if (gunReady) didn't make any difference. But it fails in melee (again no idea why) with or without the if (gunReady) fix.

Strange as it may seem, the Junior version of a Robot (if it can be ported exactly as it is) always tends to be better at 1vs1 and worse at melee. if you take WallJunior vs WallRobot for example, Junior won a 500 round battle with 74% score. The melee result of 100 rounds was
Rank, Robot Name, Total Score, 1sts, 2nds, 3rds
1st,sample.Walls,103837 (11%),61,2,1
2nd,sample.SpinBot,88186 (10%),9,28,19
3rd,ne0n.WallRobot*,71210 (8%),10,11,8
4th,sample.Tracker,67204 (7%),4,14,9
5th,ne0n.WallJunior*,64672 (7%),8,11,4
6th,sample.RamFire,61172 (7%),3,2,7
7th,sample.Crazy,57940 (6%),1,8,11
8th,sample.Fire,52027 (6%),1,3,11
9th,sample.Corners,49654 (5%),0,2,5
10th,sample.VelociRobot,49341 (5%),1,5,3
11th,sample.TrackFire,48981 (5%),0,1,4
12th,sample.MyFirstRobot,47679 (5%),1,4,6
13th,sample.PaintingRobot,47287 (5%),2,4,8
14th,sample.MyFirstJuniorRobot,43789 (5%),0,4,4
15th,sample.Target,24159 (3%),0,0,0
16th,sample.SittingDuck,21900 (2%),0,0,1
17th,sample.Interactive,20550 (2%),0,0,0
As you see the Robot 3rd Junior 5th. Can anyone explain this behavior?

I know you all have better things to do than waste time on a Junior but would anyone like to take it up as a challenge to beat the Sample bots at melee?

Realmoonstruck 19:02, 15 July 2010 (UTC)

There are no threads on this page yet.