コード例 #1
0
    void Awake()
    {
        // connect to the outer data
        labyrinth = GameObject.FindGameObjectWithTag("Labyrinth").GetComponent<LabyrinthController>();
        walls = labyrinth.GetMap();
        minimap = GameObject.FindGameObjectWithTag("Minimap").GetComponent<MinimapController>();

        // connect to subsystems
        laser = GetComponent<DroidLaser>();

        // create first particles, for 3*3 for each unit
        var length = labyrinth.length;
        var width = labyrinth.width;
        var particlesOnUnit = 1;
        var particlesShift = CreateParticlesShift(particlesOnUnit);
        var ls = new List<Particle>();
        for (var i = 0; i < length; i++)
        {
            for (var j = 0; j < width; j++)
            {
                if (walls[i, j] == 0)
                {
                    // nine particles for every unit
                    for (var k = 0; k < particlesOnUnit*particlesOnUnit; k++)
                    {
                        var particle = new Particle
                        {
                            probablity = 1,
                            position = new Vector3(i, 1f, j) + particlesShift[k]
                        };
                        ls.Add(particle);
                    }
                }
            }
        }

        // create particles map
        particlesMap = new ParticlesMap(ls);
        particlesMap.Normalize();
        StartCoroutine(minimap.ShowParticles(particlesMap.Particles));
    }
コード例 #2
0
    private void WeightParticles()
    {
        var data = laser.Scan();
        var pBest = new Particle();
        foreach (var p in particlesMap.Particles)
        {
            var convolution = LaserHelper.ScanPoint(p.position)*data;
            //p.direction = (int)convolution.topPosition;

            p.probablity = CalculateProbabilityOnProductResult(convolution);
            if (p.probablity > pBest.probablity)
            {
                pBest = p;
            }
        }
    }