Movement Pattern Learning

From Robowiki
Jump to navigation Jump to search
Patterned Movement
A movement that keeps using the same patterns.
Pattern Matching or other learning methods beats it easily but it is still effective in nano bots.

Movement Pattern Learning

Movement that learns the correct pattern to use.
In nano bots hitting walls is a big problem but still effective against learning guns.
Learning
We think that enemy has a pattern matching gun so it keeps the movement stats of enemy like current velocity, lateral velocity.
We shouldn't do the same thing again at the same situation if we've been hit before.
Building
Create a "int[n]"
Note: Increasing n slows down learning.
Make a counter that will increase it's value every tick.
We will use this counter for choosing the pattern index.
Index Formula: counterValue / m.
Note: "m" should be >= 4 because of the bot width.
Calculation: 2 + 4 + 6 + 8 = 20 > 18
To learn: when we are hit we take the current pattern index and increase it so the next time we use that pattern we will make a different move :and enemy won't be able to hit our bot.

Code

    public static int patternNum = 30; 
    public static int tickPerPattern = 15; //We will use a pattern for 15 ticks
    public static int movePerPattern = 36;
    public static int[] m = new int[patternNum];
    public static int counter = 0;
Initialisation
    public void run() {
        setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
    }
Turning the radar to find a robot.
    public void onScannedRobot(robocode.ScannedRobotEvent e) {
        setTurnRightRadians((e.getBearingRadians()) + 1.5707963267948966D); //Staying perpendicular to the enemy to have a large escape angle
        int currentPattern = m[counter / tickPerPattern]; 
        int direction = currentPattern % 3 - 1; //Finding the direction to go
        setAhead(direction * movePerPattern);//Move!
        counter++;
        counter %= (tickPerPattern * patternNum);//We don't want an ArrayIndexOutOfBoundsException
        setTurnRadarLeftRadians(getRadarTurnRemaining());//Locking the radar
    }
Movement
    public void onHitByBullet(robocode.HitByBulletEvent e) {
        m[(counter / tickPerPattern)] += 1; //Changing the direction for not being hit the next time
    }
Learning the correct pattern

Improvements

Adding wall smoothing like in RaikoNano.
Having more decisions to make.
Current: -8, 0, 8
After: -8, -4, 0, 4, 8