今日は、Boid をシミュレートする AI プログラムの作成と投稿に忙殺されました。現在、私は動き回る単一の「ボイド」を取得することに取り組んでいます。「ボイド」は、その「前方ベクトル」を象徴する線を引いた円(省略記号)です。
class SwarmCir
{
    public float _pointX;
    public float _pointY;
    public float _height;
    public float _width;
    Pen _pen = new Pen(Color.Black);
    PointF _ForwardPoint = new PointF(0, 0);
    float rotAng = 0.0f;
    public SwarmCir()
    {
        _pointX = 1.0f;
        _pointY = 1.0f;
        _height = 5.0f;
        _width = 5.0f;
        _ForwardPoint.X = 7.0f;
        _ForwardPoint.Y = 7.0f;
    }
    public SwarmCir(Point XY)
    {
        _pointX = XY.X;
        _pointY = XY.Y;
        _height = 5.0f;
        _width = 5.0f;
    }
    public SwarmCir( Point XY, float Height, float Width )
    {
        _pointX = XY.X;
        _pointY = XY.Y;
        _height = Height;
        _width = Width;
    }
    public void SetPen(Pen p)
    {
        _pen = p;
    }
    public void Draw(Graphics g)
    {
        g.DrawEllipse(_pen, _pointX, _pointY, _width, _height);
        g.DrawLine(_pen, new PointF(_pointX, _pointY), _ForwardPoint);
    }
    public void Rotate(PaintEventArgs e)
    {
        e.Graphics.TranslateTransform(_pointX, _pointY);
        e.Graphics.RotateTransform(rotAng);
        e.Graphics.TranslateTransform(-_pointX, -_pointY);
    }
    public PointF ForwardVec()
    {
        PointF temp = new PointF();
        temp.X = _pointX - _ForwardPoint.X;
        temp.Y = _pointY - _ForwardPoint.Y;
        return Normalize(temp);
    }
    public PointF Normalize(PointF p)
    {
        PointF temp = new PointF();
        if (p.X > p.Y)
        {
            temp.X = 1;
            temp.Y = p.Y / p.X;
        }
        else if (p.Y > p.X)
        {
            temp.Y = 1;
            temp.X = p.X / p.Y;
        }
        else
        {
            return new PointF(1, 1);
        }
        return temp;
    }
    public void MoveForward()
    {
        _pointX += ForwardVec().X;
        _pointY += ForwardVec().Y;
    }
    public void MoveBackwards()
    {
        _pointX -= ForwardVec().X;
        _pointY -= ForwardVec().Y;
    }
    public void TurnLeft()
    {
        rotAng += 10.0f;
    }
    public void TurnRight()
    {
        rotAng -= 10.0f;
    }
}
現在、このクラスを実装するプログラムを実行しているときに、デフォルトの SwarmCir() をインスタンス化し、下部にある移動関数を呼び出すだけで、非常に奇妙な結果が得られます。基本的に、「W」で円を「前方ベクトル」に沿って移動させたいのです。明らかに「S」の場合は逆です。それから回す時はちゃんと形と線が曲がって欲しいです。さらに情報が必要な場合はお問い合わせください。完全な AI ワークベンチに向けて取り組んでいます。