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


C# Combatant.OrderByDescending方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        Random r = new Random();

        string[] inputs;
        int opponentCount = int.Parse(Console.ReadLine()); // Opponent count

        // game loop
        while (true)
        {
            int gameRound = int.Parse(Console.ReadLine());
            inputs = Console.ReadLine().Split(' ');
            var player = new Combatant { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]), BackInTimeLeft = int.Parse(inputs[2]) };

            var opponents = new Combatant[opponentCount];
            for (int i = 0; i < opponentCount; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                opponents[i] = new Combatant { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]), BackInTimeLeft = int.Parse(inputs[2]) };
            }

            var map = new string[MAP_HEIGHT+2];
            map[0] = string.Join("", Enumerable.Repeat(CELL_WALL, MAP_WIDTH+2).ToArray());
            for (int i = 0; i < MAP_HEIGHT; i++)
            {
                map[i+1] = CELL_WALL +  Console.ReadLine() + CELL_WALL; // One line of the map ('.' = free, '0' = you, otherwise the id of the opponent)
            }
            map[MAP_HEIGHT+1] = string.Join("", Enumerable.Repeat(CELL_WALL, MAP_WIDTH+2).ToArray());

            //printMap(map);
            var mapChars = map.SelectMany(row=>row.Select(col=>col)).ToArray();
            for (int i = 0; i < opponentCount; i++)
            {
                opponents[i].Score = mapChars.Where(x => x.ToString() == (i + 1).ToString()).Count();
                Console.Error.WriteLine("Opponent " + 1 + " has score " + opponents[i].Score);
            }

            //Prefer any neutral cell
            Console.Error.WriteLine("I'm at " + player);
            var directions = directionsTo(map, player, CELL_NEUTRAL).ToArray();
            Console.Error.WriteLine("Neutral cells at: " + string.Join(", ", (directions.Select(d => d.ToString()).ToArray())));
            //if (!directions.Any())
            //{
            //	Console.Error.WriteLine("No neutrals found");
            //	//No neutral, so prefer an opponents cell, so we cross paths
            //	var visited = directionsTo(map, player, CELL_PLAYER);
            //	var walls = directionsTo(map, player, CELL_WALL[0]);
            //	directions = new Direction[] { Direction.TOP, Direction.RIGHT, Direction.BOTTOM, Direction.LEFT }.Except(walls).Except(visited).ToArray();
            //}
            if (directions.Any())
            {
                //Go in one of the available directions
                var nextDirection = (Direction)directions[r.Next(directions.Count())];
                var newLocation = player + nextDirection;
                Console.Error.WriteLine("Walking " + nextDirection.ToString() + " to " + newLocation);
                Console.WriteLine(newLocation.ToString());
            }
            else
            {
                //I'm trapped. Get out!
                Console.Error.WriteLine("Heading for leader");
                var point = opponents.OrderByDescending(x => x.Score).First();
                if (Math.Abs(point.X - player.X) > Math.Abs(point.Y - player.Y))
                    Console.WriteLine(point);
                else
                {
                    Console.WriteLine(new Point(player.X, point.Y));
                }
            }

            //Console.WriteLine("17 10"); // action: "x y" to move or "BACK rounds" to go back in time
        }
    }
开发者ID:aquamoth,项目名称:CodeinGame,代码行数:73,代码来源:Program.cs


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