jamro / jsbattle

JavaScript Programming Game (inspired by RoboCode)
http://jsbattle.jmrlab.com
MIT License
105 stars 47 forks source link

Level 4: Dummy Duel - fails to detect enemy #23

Closed RichardBronosky closed 5 years ago

RichardBronosky commented 5 years ago

The battle instructions say:

Time for the first duel! The opponent is not difficult - it will stand still and wait for you. You just need to find and destroy it.

I have tested it with the script from https://jsbattle.jmrlab.com/docs/manual/algorithms_aiming.html#put-everything-together

importScripts('lib/tank.js')

tank.init(function(settings, info) {
});

tank.loop(function(state, control) {
    if(!state.radar.enemy) {
    control.RADAR_TURN = 1
  } else {
    control.RADAR_TURN = 0
    control.SHOOT = 1

    let targetAngle = Math.deg.atan2(state.radar.enemy.y - state.y, state.radar.enemy.x - state.x)
    let radarAngle = Math.deg.normalize(targetAngle - state.angle)
    let radarAngleDiff = Math.deg.normalize(radarAngle - state.radar.angle)
    control.RADAR_TURN = 0.3 * radarAngleDiff

    let bodyAngleDiff = Math.deg.normalize(targetAngle - state.angle)
    control.TURN = 0.5 * bodyAngleDiff

    let targetDistance = Math.distance(state.x, state.y, state.radar.enemy.x, state.radar.enemy.y)
    let distanceDiff = targetDistance - 150
    control.THROTTLE = distanceDiff/100

    let gunAngle = Math.deg.normalize(targetAngle - state.angle)
    let gunAngleDiff = Math.deg.normalize(gunAngle - state.gun.angle)

    control.GUN_TURN = 0.3 * gunAngleDiff
  }
});
acklenx commented 5 years ago

This was not the first battle. It was the fourth... and you have to find the other bot. It's probably worth a bigger hint in the description that the radar has a limited range of 300 - so you will likely have to move to get in radar range of the other bot.

jamro commented 5 years ago

Good point, I will update the description