Beispiel #1
0
        public float GetDirectionWeight(Ant criticalAnt, List <FormationInfo> allFormationInfos, int directionX, int directionY)
        {
            FormationInfo criticalFormationInfo = allFormationInfos.Find(x => x.ant == criticalAnt);

            double[,] currentDistributionWeight = new double[11, 11];
            foreach (FormationInfo info in allFormationInfos)
            {
                currentDistributionWeight[5 + info.blockX, 5 + info.blockY] += 1.0 / allFormationInfos.Count;
            }
            int newBlockX = Math.Min(Math.Max(5 + criticalFormationInfo.blockX + directionX, 0), 10);
            int newBlockY = Math.Min(Math.Max(5 + criticalFormationInfo.blockY + directionY, 0), 10);

            currentDistributionWeight[5 + criticalFormationInfo.blockX, 5 + criticalFormationInfo.blockY] -= 1.0 / allFormationInfos.Count;
            currentDistributionWeight[newBlockX, newBlockY] += 1.0 / allFormationInfos.Count;
            return(1 - (Variance(distributionWeight, currentDistributionWeight)));
        }
Beispiel #2
0
        public float GetProperRotation(Ant criticalAnt, List <FormationInfo> allFormationInfos, out double deviation)
        {
            FormationInfo criticalFormationInfo = allFormationInfos.Find(x => x.ant == criticalAnt);

            double[,] currentDistributionWeight = new double[11, 11];
            cuw = new double[11, 11];
            foreach (FormationInfo info in allFormationInfos)
            {
                currentDistributionWeight[5 + info.blockX, 5 + info.blockY] += 1.0 / allFormationInfos.Count;
                cuw[5 + info.blockX, 5 + info.blockY] += 1.0 / allFormationInfos.Count;
            }
            deviation = Math.Sqrt(Variance(distributionWeight, currentDistributionWeight));
            dev       = deviation;
            List <BlockInfo> blockInfos = new List <BlockInfo>();

            for (int x = -5; x <= 5; x++)
            {
                for (int y = -5; y <= 5; y++)
                {
                    int newBlockX = Math.Min(Math.Max(criticalFormationInfo.blockX + x, -5), 5);
                    int newBlockY = Math.Min(Math.Max(criticalFormationInfo.blockY + y, -5), 5);
                    currentDistributionWeight[5 + newBlockX, 5 + newBlockY] -= 1.0 / allFormationInfos.Count;
                    blockInfos.Add(new BlockInfo {
                        x = newBlockX, y = newBlockY, weight = Variance(currentDistributionWeight, distributionWeight)
                    });
                    currentDistributionWeight[5 + newBlockX, 5 + newBlockY] += 1.0 / allFormationInfos.Count;
                }
            }
            float     minWeight = blockInfos.Min().weight;
            var       blocks    = blockInfos.FindAll(x => x.weight == minWeight);
            BlockInfo bestBlock = blocks.OrderBy(x => Guid.NewGuid().GetHashCode()).FirstOrDefault();

            if (bestBlock.x == 0 && bestBlock.y == 0)
            {
                return(-1f);
            }
            else
            {
                Random r = new Random(Guid.NewGuid().GetHashCode());
                return((MathTool.Direction2DToRotation2D(bestBlock.x + r.NextDouble() / 2 - 0.25, bestBlock.y + r.NextDouble() / 2 - 0.25) + 360f) % 360f);
            }
        }