简体   繁体   English

斐波那契螺旋-Robocode

[英]Fibonacci Spiral - Robocode

Does anyone know how I could make a spiral motion following the Fibonacci pattern around a point in Robocode? 有谁知道我如何按照斐波那契模式绕Robocode的一个点做​​螺旋运动? I have methods like setTurnRight (double), setAhead (double), getX () and getY (). 我有setTurnRight(double),setAhead(double),getX()和getY()之类的方法。

I tried to make a simple spiral, without the required standard, that way, but it did not work ... It was more like a circle. 我试图用这种方式制作一个简单的螺旋,没有所需的标准,但是却没有效果……它更像一个圆。

this.setAhead(this.direction * Double.POSITIVE_INFINITY);
if (this.direction == 1) {
    this.setTurnRight(Utils.normalRelativeAngleDegrees(this.enemy.getBearing() + 60));
} else {
    this.setTurnRight(Utils.normalRelativeAngleDegrees(this.enemy.getBearing() + 120));
}

physics of the game: http://robowiki.net/wiki/Robocode/Game_Physics 游戏物理学: http//robowiki.net/wiki/Robocode/Game_Physics

Robocode Logarithmic Spiral Robocode对数螺旋

Here is a working run method to make a bot follow a logarithmic spiral and I believe it is a close approximation of the golden spiral (which is the spiral that can be approximated with the Fibonacci numbers). 这是一种使机器人遵循对数螺旋的有效运行方法,我相信它是黄金螺旋(可以用斐波纳契数近似的螺旋)的近似值。

    public void run() {
      double v = 5;
      double c = Math.PI*2;
      double a = .1;
      double b = .0053468;

      setMaxVelocity(v);
      setAhead(100*999);
      setTurnRight(360*999);
      while(true)
      {
          double t = getTime();
          double f = a*Math.pow(Math.E,b*t);
          double w = v/(c*f);       

          setMaxTurnRate(w);
          execute();
          System.out.println(t+"\t"+w);
      }
    }

Explanation 说明

To move in a circle (trivial spiral), you keep constant speed (how fast the bot is moving) and constant revolution speed (how fast the bot is turning). 要绕圈运动(平缓的螺旋运动),请保持恒定的速度 (机器人移动的速度 )和恒定的旋转速度 (机器人旋转的速度 )。 There are several ways to go from this trivial spiral movement to something more interesting. 从这种微不足道的螺旋运动到更有趣的事情,有几种方法。 The simplest way to move in a spiral is to keep constant speed and vary the revolution speed. 螺旋运动的最简单方法是保持恒定速度并改变转速。 This answer from the game development exchange gives a good walk through on how to get an approximate equation for revolution speed. 从游戏开发交流答案通过提供有关如何获得转速近似方程好走。

  • w = v / (2*pi*t) or w = v / (2*pi*f(t)) where: w = v / (2*pi*t)w = v / (2*pi*f(t))其中:
    • w = revolution speed w =转速
    • v = speed v =速度
    • pi = 3.14... pi = 3.14 ...
    • t = time or f(t) = function of the radius over time t =时间或f(t) =半径随时间的函数

This equation gives a way to move along a spiral and we can choose any spiral we want by specifying a f(t) . 该方程式提供了一种沿着螺旋运动的方式,我们可以通过指定f(t)来选择所需的任何螺旋。 To get the correct radius function for the golden spiral, check out this wiki page about the golden spiral. 要获取黄金螺旋正确的半径功能,看看这个 wiki页面对黄金螺旋。 It gives this equation: 它给出了以下等式:

  • r = a*e^(b*theta) or in other words f(t) = a*e^(b*t) where: r = a*e^(b*theta)或换句话说f(t) = a*e^(b*t)其中:
    • f(t) = our radius function f(t) =我们的半径函数
    • a = arbitrary constant for scaling the spiral a =缩放螺旋的任意常数
    • e = Euler's constant e =欧拉常数
    • b = .0053468 (or .3063489 if using radians) b = .0053468(如果使用弧度,则为.3063489)
    • t = time t =时间

Conclusion 结论

All that is left is to incorporate this code into your bot and choose your own values for a and v . 剩下的就是将这段代码合并到您的机器人中,并为av选择您自己的值。 v will determine the speed of the bot, so a larger v is a good idea (max is 10) and since the max for w is 8, you should scale a accordingly so that w stays between 0 and 8 for as long as possible (which is why I've included the println). v将决定机器人的速度,因此,较大的v是个好主意(最大为10),并且由于w的最大值为8,因此应相应地缩放a ,以便w尽可能长时间地保持在0到8之间(这就是为什么我包含println的原因。

[NOTE: I couldn't think of an easy way to superimpose the golden spiral on the bot's path to check it's accuracy. [注意:我想不出一种简单的方法来在机器人的路径上叠加金色螺旋,以检查其准确性。 So while it is clearly a logarithmic spiral, I am unsure to what degree it approximates the desired golden spiral ] 因此,尽管它显然是对数螺旋,但我不确定它在多大程度上接近所需的黄金螺旋]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM