User talk:Gertjan96

From Robowiki
Jump to navigation Jump to search

Contents

Thread titleRepliesLast modified
Simple robot - improvements, help wanted?307:14, 19 June 2014
Simple robot - looking for improvements121:59, 17 June 2014

Simple robot - improvements, help wanted?

Edited by 2 users.
Last edit: 07:14, 19 June 2014

Hello,

I have to hand my teacher the robotcode code for my robot next wednesday. It doesn't have to be a very difficult robot, so I have made this robot today. Against the sample robots, it wins against the most of them, but not all of them.

Is there anyone who can help me to improve this code? Here is the code:

package MyRobots;
import robocode.*;
import java.awt.Color;

public class Fireintheass extends AdvancedRobot
{
	double distance = 10;
	
	public void run() {
		setColors(Color.pink, Color.pink, Color.pink, Color.white, Color.pink);
		
		setAdjustRadarForGunTurn(true);
	
		setTurnRadarRight(360);
	
		while(true) {
			ahead(distance + 100);
			back(distance);
		}
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		turnRight(e.getBearing());
		
		distance = e.getDistance();
		
		if (e.getVelocity() == 0)
		{
			fire(3);
		}
	
		setTurnRadarRight(360);
	}	
}
Gertjan96 (talk)20:08, 15 June 2014

Anyone? :(

Gertjan96 (talk)21:32, 15 June 2014

Need help

Gertjan96 (talk)21:40, 15 June 2014

You Should Use The Syntax Highlight Tag </syntaxhighlight>

Tmservo (talk)21:22, 16 June 2014
 
 
 

Simple robot - looking for improvements

Hello,

I made a simple but (I hope) effective robot. I don't have much experience, so I would love to get any tips on how to further improve this code. It has to be ready in 3,5 hours. Lots of thanks.

package MyRobots;
import robocode.*;
import java.awt.Color;

public class Fireintheass extends AdvancedRobot
{
	double distance = 10;
	
	public void run() {
		setColors(Color.pink, Color.pink, Color.pink, Color.white, Color.pink);
		
		setAdjustRadarForGunTurn(true);
	
		setTurnRadarRight(360);
	
		while(true) {
			ahead(distance + 100);
			back(distance);
		}
	}

	public void onScannedRobot(ScannedRobotEvent e) {
		turnRight(e.getBearing());
		
		distance = e.getDistance();
		
		if (e.getVelocity() == 0)
		{
			fire(3);
		}
	
	setTurnRadarRight(360);
	}
	
}
Gertjan96 (talk)20:30, 17 June 2014

A few things I suggest changing:

  1. Make the forward and back based on a single variable, which you change the value of once every so often (say once every 20 ticks). You can then also change direction for things like hitting a wall, which will help you keep moving.
  2. Try using a lower bullet power if they are far away. Also, if they are really close, you can fire even if they aren't moving because they won't move enough in time.
  3. Try using a proper radar lock instead of just spinning - check out One_on_One_Radar#The_Infinity_Lock.
  4. I don't see anything which is actually turning the gun towards the enemy. Take a look at Linear_Targeting#Example_of_Noniterative_Linear_Targeting for some code which should give you a major edge against any of the sample bots.

It's a pity you don't have a few weeks to work on this, because then you could set your sights above just beating the sample bots =)

Skilgannon (talk)21:46, 17 June 2014