BlackWidow

From Robowiki
Revision as of 18:18, 5 March 2009 by Robar (talk | contribs)
Jump to navigation Jump to search

Background Information

BlackWidow
Author(s) User:Robar
Targeting SymbolicPatternMatching
Movement Stop And Go + Random Movement
Released March, 2009
Current Version 1.0
Code License RWLPCL
Download


Bot Name
BlackWidow
Author
User:Robar
Extends
AdvancedRobot
What's special about it?
It features one of my new developments, the Adapting Oscillator Movement.
Great, I want to try it. Where can I download it?
http://robocoderepository.com/BotDetail.jsp?id=3542
How competitive is it?
Very. It's top 10, probably top 5.

Strategy

How does it move?
Stop And Go + Random Movement
How does it fire?
SymbolicPatternMatching.
How does it dodge bullets?
Stop And Go, if fails, it switches to Random Movement, which changes direction randomly when enemy fires.
How does the melee strategy differ from One-on-one strategy?
It's only a one-on-one bot.
What does it save between rounds and matches?
Static variables, as always.

Additional Information

Where did you get the name?
Small, but very dangerous - this's the perfect name for a spider-geek. :P
Can I use your code?
RWLPCL I commented the PM code in much detail in order to make beginners understand the code easier.
What's next for your robot?
I must have left out setAdjustGunForRobotTurn to get under 250 bytes. I should squeeze the code more to put it back, because it scores badly against stopNgo. (75-80% instead of 90-95)
Does it have any White Whales?
NanoAndrew, NanoLaulektric, NanoSatan, Acero, Splinter, NanoDeath, WeekendObsession etc...
What other robot(s) is it based on?
It has FunkyChicken's gun with codesize-optimalizations.

Version history

1.0
Symbolic Pattern Matcher gun, 36px Stop And Go, enemy fire-sensitive random movement, 2.5 firepower.

The code 1.0

package robar.nano;

import java.awt.Color;
import robocode.*;
import robocode.util.*;

public class BlackWidow extends AdvancedRobot{

	//Made by HUNRobar
	//You can contact me at testwiki.roborumble.org, or via e-mail to robar06@gmail.com
    //Global
    
    static StringBuffer enemyLog = new StringBuffer("000000000000000000000000000000"); //The list where enemy lateral velocites are stored

    //Constants
    static final double FIREPOWER = 2.5; //The firepower of the bot
    static final double BULLETVEL = 20-3*FIREPOWER; //The velocity of the bullet fired at FIREPOWER
    static final int PATTERN_DEPTH = 30; //The lenght of the pattern we try to find each turn in enemyLog
    static final double MOVEAMOUNT = 36; //The amount of pixels the bot will move in stop and go

    //Variables
    static double prevEnergy; //It stores the energy of the enemy
    static double direction = MOVEAMOUNT; //It's the direction and the movement packed together
    static int deathCount; //The number of deaths of our robot

    public void run(){
        //setAdjustGunForRobotTurn(true); //This sets the gun independent from the body. Extracted it due to codesize

    	//Black Widow-like colors: ;)
    	//setAllColors(Color.black);
    	//Infinite radar-lock
        setTurnRadarRight(Double.POSITIVE_INFINITY);
    }

    public void onScannedRobot(ScannedRobotEvent e){

            //Local variables

            double absB; //absolute bearing
            int index; //index of the match of the pm gun
            int matchLenght = PATTERN_DEPTH; //the number of data a pattern contains


            /*The pattern matcher gun
             *
             *It's a bit codesize-optimized version of Assertive's gun which is descend from FunkyChicken
             *I comment the gun in detail in order to make new robocoders more understandable. I'd have been
             *very glad if there had been such comments when I was learning symbolic pm. ;)
            */

            //Adding a new entry in the beginning of our pattern-list
            enemyLog.insert(0, (char)((int)(Math.sin(e.getHeadingRadians() - (absB=e.getBearingRadians()+getHeadingRadians()))*e.getVelocity())));

            //Reducing pattern lenght until there is a match in the list. The pattern is the first 'matchlenght' entries in the list.
            while ((index = enemyLog.toString().indexOf(enemyLog.substring(0, matchLenght--), 1)) < 0);

            //Now matchLenght will be the index of the pattern we estimate the enemy will do in the next turns.
            //The lenght of the etimated pattern equals the time our bullet reaching the enemy.
            matchLenght = index - (int)(e.getDistance()/BULLETVEL);


            //Converting lateral velocities of the estimated pattern to angular velocities, then adding them to absolute bearing
            do{
                absB += Math.asin(((byte)enemyLog.codePointAt(index--))/e.getDistance());
            }while(index >= Math.max(0, matchLenght));

            //Turning gun
            setTurnGunRightRadians(Utils.normalRelativeAngle(absB-getGunHeadingRadians()));

            //Fire in the hall!
            setFire(FIREPOWER);

            
            //Movement: Stop and Go, if it fails, simple random movement

            if(prevEnergy > (prevEnergy = e.getEnergy()) ){

                if(deathCount > 2)  direction = (Math.random()*10000-5000);
                setAhead(direction);
                
            }

            setTurnRightRadians(Math.cos(e.getBearingRadians()));

            setTurnRadarLeft(getRadarTurnRemaining());
    }
    public void onHitWall(HitWallEvent e){
        direction=-direction;
    }

    public void onDeath(DeathEvent e){
        deathCount++;
    }
}