当前位置: 首页>>代码示例>>C#>>正文


C# Entity.GetLength方法代码示例

本文整理汇总了C#中Entity.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.GetLength方法的具体用法?C# Entity.GetLength怎么用?C# Entity.GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entity的用法示例。


在下文中一共展示了Entity.GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Ant

        public Ant(Dictionary<string, double> template, Random rng, Entity[,] grid, bool guaranteedMutation)
        {
            Statistics.totalNumberOfAnts++;
            if (Statistics.totalNumberOfAnts > Statistics.largestPopulation)
            {
                Statistics.largestPopulation = Statistics.totalNumberOfAnts;
            }

            attributes = new Dictionary<string, double>();

            foreach (KeyValuePair<string, double> kvp in template)
            {
                //  chance of totally random mutation for a given characteristic
                if (rng.NextDouble() <= EXTREME_MUTATION_CHANCE || guaranteedMutation)
                {
                    // old code
                    //attributes[kvp.Key] = (2 * template[kvp.Key]) * (rng.NextDouble() - RANGE_OFFSET) * (template["mutationFactor"]);
                    double range = Statistics.attributeRange[kvp.Key].Y - Statistics.attributeRange[kvp.Key].X;
                    attributes[kvp.Key] = range * rng.NextDouble() + Statistics.attributeRange[kvp.Key].X;
                }
                else
                {
                    attributes[kvp.Key] = template[kvp.Key] + (rng.NextDouble() - RANGE_OFFSET) * template["mutationFactor"] * (Statistics.attributeRange[kvp.Key].Y - Statistics.attributeRange[kvp.Key].X);

                    if (attributes[kvp.Key] > Statistics.attributeRange[kvp.Key].Y)
                    {
                        attributes[kvp.Key] = Statistics.attributeRange[kvp.Key].Y;
                    }
                    else if (attributes[kvp.Key] < Statistics.attributeRange[kvp.Key].X)
                    {
                        attributes[kvp.Key] = Statistics.attributeRange[kvp.Key].X;
                    }
                }

                Statistics.currentSum[kvp.Key] += attributes[kvp.Key];
            }

            isObstacle = true;
            health = DEFAULT_STARTING_HEALTH;

            lastSeen = new int[grid.GetLength(0), grid.GetLength(1)];
            diffusionGrid = new double[grid.GetLength(0), grid.GetLength(1)];
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:43,代码来源:Ant.cs

示例2: Neighbors

        //  todo: FIX, broken
        public List<Entity> Neighbors(Entity[,] grid)
        {
            List<Entity> l = new List<Entity>();

            for (int i = -1; i < 2; i += 2)
            {
                for (int j = -1; j < 2; j += 2)
                {
                    int x = (int) position.X + i;
                    int y = (int) position.Y + j;

                    if (x < 0 || x >= grid.GetLength(0) || y < 0 || y >= grid.GetLength(1))
                    {
                        continue;
                    }
                    l.Add(grid[x, y]);
                }
            }
            return l;
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:21,代码来源:Entity.cs

示例3: ProcessVision

        void ProcessVision(Entity[,] grid, double curTime)
        {
            for (int i = 0; i < grid.GetLength(0); i++)
            {
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    int dist = Math.Abs((int) position.X - i) + Math.Abs((int) position.Y - j);

                    if (dist > attributes["eyesightRange"])
                    {
                        continue;  // don't account for things you cannot see
                    }

                    Entity e = grid[i, j];
                    if (e != null)
                    {
                        if (e is Ant)
                        {
                            ants.Add((Ant)e);
                        }
                        else if (e is Food)
                        {
                            foods.Add((Food)e);
                        }
                    }

                    lastSeen[i, j] = (int)curTime;
                }
            }
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:30,代码来源:Ant.cs

示例4: Update

        public void Update(Entity[,] grid, GameTime gameTime, Random rng)
        {
            //  update health every second
            if (gameTime.TotalGameTime.TotalSeconds - timeOfLastUpdate > 1)
            {
                timeOfLastUpdate = gameTime.TotalGameTime.TotalSeconds;
                health -= STANDING_COST;
            }

            int curTime = (int) gameTime.TotalGameTime.TotalSeconds;
            Vector2 newPosition = position;
            foreach (char c in Entity.Directions)
            {
                newPosition = directionTranslate(c);

                //  give birth to ant sometimes
                if (newPosition.Y >= 0 && newPosition.Y < grid.GetLength(1) &&
                        newPosition.X >= 0 && newPosition.X < grid.GetLength(0) &&
                        grid[(int)newPosition.X, (int)newPosition.Y] is Ant)
                {
                    Ant other = (Ant) grid[(int)newPosition.X, (int)newPosition.Y];

                    if (curTime - timeOfLastChild >= attributes["childbirthCooldown"]
                        && curTime - other.timeOfLastChild >= other.attributes["childbirthCooldown"]
                        && curTime - other.timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME
                        && curTime - timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME)
                    {
                        if (rng.NextDouble() <= attributes["childbirthPercentage"] / 100)
                        {
                            Ant child = new Ant(this, other, rng, grid);
                            child.sprite = other.sprite;

                            timeOfLastChild = curTime;
                            other.timeOfLastChild = curTime;

                            //  health of parents go into raising the child
                            child.health = other.attributes["childbirthCost"] + attributes["childbirthCost"];

                            other.health -= 1.5*other.attributes["childbirthCost"];
                            health -= 1.5*attributes["childbirthCost"];
                        }
                    }
                }
            }

            // punish ants for having high eyesight, strength, etc
            health -= attributes["eyesightRange"] * .0001;

            //  death
            if (health <= 0 || moves >= attributes["oldestPossibleAge"])
            {
                //  kill this ant if it has low health
                Die(grid);
            }
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:55,代码来源:Ant.cs

示例5: CreateMovement

        // NOTE: curTime is in milliseconds
        public override char CreateMovement(Entity[,] grid, double curTime)
        {
            if (curTime - timeOfLastMove < attributes["walkSpeed"])
                return '0'; //  don't move if the time isn't right

            timeOfLastMove = curTime; // update movetime

            ProcessVision(grid, curTime / 1000.0);
            CalculateDiffusion(grid, curTime / 1000.0);

            char dir = '0';
            double max = 0;
            Vector2 newPosition = position;

            foreach (char c in Entity.Directions)
            {
                newPosition = directionTranslate(c);

                //  absorbs a food piece just by being next to it
                if (newPosition.Y >= 0 && newPosition.Y < grid.GetLength(1) &&
                        newPosition.X >= 0 && newPosition.X < grid.GetLength(0) &&
                        grid[(int)newPosition.X, (int)newPosition.Y] is Food)
                {
                    health += ((Food)grid[(int)newPosition.X, (int)newPosition.Y]).Calories();

                    Statistics.foodFades.Add(new FoodFade(newPosition, grid[(int)newPosition.X, (int)newPosition.Y].Sprite()));

                    grid[(int)newPosition.X, (int)newPosition.Y] = null;

                    Statistics.foodEffects.Add(new FoodEffect(this, newPosition));

                    foodsEaten++;
                    Statistics.totalFoods--;

                    if (foodsEaten > Statistics.largestNumberOfFoodsEaten)
                    {
                        Statistics.largestNumberOfFoodsEaten = foodsEaten;
                    }
                }

                //  don't walk onto a position that has an ant
                if (newPosition.Y >= 0 && newPosition.Y < grid.GetLength(1) &&
                    newPosition.X >= 0 && newPosition.X < grid.GetLength(0) &&
                    grid[(int)newPosition.X, (int)newPosition.Y] == null)
                {
                    //  only calculate diffusion for valid locations
                    if (diffusionGrid[(int)newPosition.X, (int)newPosition.Y] > max)
                    {
                        max = diffusionGrid[(int)newPosition.X, (int)newPosition.Y];
                        dir = c;
                    }
                }
            }

            if (dir != '0')
            {
                health -= MOVEMENT_COST;
                moves++;
                Statistics.numberOfMovements++;
                if (moves > Statistics.longestAgeLived)
                {
                    Statistics.longestAgeLived = moves;
                }

                Statistics.timeOfLastMovement = (int)(curTime/1000.0);
                Statistics.systemHasMoved = true;
            }

            lastMove = dir;

            return dir;
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:73,代码来源:Ant.cs

示例6: CalculateDiffusion

        public double[,] CalculateDiffusion(Entity[,] grid, double curTime)
        {
            for (int i = 0; i < grid.GetLength(0); i++)
            {
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    Vector2 currentPos = new Vector2(i, j);

                    if (curTime - lastSeen[i, j]
                        >= attributes["timeToReexplore"])
                    {
                        diffusionGrid[i, j] = attributes["desireToExplore"];
                    }
                    else
                    {
                        diffusionGrid[i, j] = 0;
                    }

                    foreach (Food food in foods)
                    {
                        diffusionGrid[i, j]
                            += Score(attributes["desireForFood"]*food.Calories(), food.Position(), currentPos);
                    }
                    foreach (Ant ant in ants)
                    {
                        diffusionGrid[i, j]
                            += Score(attributes["desireToFollowAnts"], ant.Position(), currentPos);

                        if (ant.health >= attributes["healthThreshold"])
                        {
                            if (curTime - timeOfLastChild >= attributes["childbirthCooldown"]
                            && curTime - timeOfLastChild >= MINIMUM_CHILDBIRTH_TIME)
                            {
                                diffusionGrid[i, j]
                                    += Score((attributes["desireToMate"] +
                                    (ant.health - attributes["healthThreshold"])) / (children.Count + 1)
                                    , ant.Position(), currentPos);
                            }
                        }
                    }

                    Vector2 sameDirMove = directionTranslate(lastMove);
                    if (i == sameDirMove.X && j == sameDirMove.Y && lastMove != '0')
                    {
                        //  prevents equal-sum scenarios
                        diffusionGrid[i, j] += attributes["desireToContinueInSameDirection"];
                    }

                    Vector2 backwardsDirMove = directionTranslate(BackwardsDirection(lastMove));
                    if (i == backwardsDirMove.X && j == backwardsDirMove.Y && lastMove != '0')
                    {
                        //  prevents oscillation
                        diffusionGrid[i, j] += attributes["desireToGoBackwards"];
                    }

                }
            }

            return diffusionGrid;
        }
开发者ID:jdtang13,项目名称:InfinityEvolve,代码行数:60,代码来源:Ant.cs


注:本文中的Entity.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。