Beispiel #1
0
        static void Main()
        {
            var game = new Game();

            game.Init();

            string[] inputs;
            string direction = "";
            // game loop
            while (true)
            {
                // ReSharper disable once PossibleNullReferenceException
                inputs = Console.ReadLine().Split(' ');
                int noOfPlayers = int.Parse(inputs[0]); // total number of players (2 to 4).
                game.MyId = int.Parse(inputs[1]); // your player number (0 to 3).

                for (int i = 0; i < noOfPlayers; i++)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    inputs = Console.ReadLine().Split(' ');
                    int startX = int.Parse(inputs[0]); // starting X coordinate of lightcycle (or -1)
                    int startY = int.Parse(inputs[1]); // starting Y coordinate of lightcycle (or -1)
                    int tronX = int.Parse(inputs[2]); // starting X coordinate of lightcycle (can be the same as X0 if you play before this player)
                    int tronY = int.Parse(inputs[3]); // starting Y coordinate of lightcycle (can be the same as Y0 if you play before this player)
                    if (startX != -1)
                    {
                        Map.MapArray[startX, startY].OwnerId = i;
                        Map.MapArray[tronX, tronY].OwnerId = i;
                        if (i == game.MyId)
                        {
                            game.MyPosition.X = tronX;
                            game.MyPosition.Y = tronY;
                        }
                        else
                        {
                            if (!game.Targets.Any())
                            {
                                game.Targets.Add(new Enemy { Position = new Coords { X = tronX, Y = tronY }, PlayerId = i });
                            }
                            else
                            {
                                var target = game.Targets.FirstOrDefault(w => w.PlayerId == i);
                                if (target != null)
                                {
                                    target.LastPosition = target.Position;
                                    target.Position.X = tronX;
                                    target.Position.Y = tronY;
                                }
                            }
                        }
                    }
                    else
                    {
                        ClearDeadBody(i);
                    }

                }
                Console.WriteLine(GetWhereToGo(direction, game));

            }
            // ReSharper disable once FunctionNeverReturns
        }
Beispiel #2
0
        public static string GetWhereToGo(string direction, Game game)
        {
            foreach (var target in game.Targets)
            {
                target.Distance = game.GetDistance(game.MyPosition, target.Position);
            }

            var primTarget = game.Targets.OrderBy(o => o.Distance).FirstOrDefault(d => d.Distance < 4);

            if (primTarget != null)
            {
                direction = GetOrientation(game.MyPosition, primTarget);
            }

            var compass = new CanGo();

            if (compass.UpTwo(game.MyPosition) && direction == Move.Up)
            {
                direction = Move.Up;
            }
            else if (compass.RightTwo(game.MyPosition) && direction == Move.Right)
            {
                direction = Move.Right;
            }
            else if (compass.DownTwo(game.MyPosition) && direction == Move.Down)
            {
                direction = Move.Down;
            }
            else if (compass.LeftTwo(game.MyPosition) && direction == Move.Left)
            {
                direction = Move.Left;
            }
            else
            {
                if (compass.UpTwo(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.RightTwo(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.DownTwo(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.LeftTwo(game.MyPosition))
                {
                    direction = Move.Left;
                }
                else if (compass.Up(game.MyPosition))
                {
                    direction = Move.Up;
                }
                else if (compass.Right(game.MyPosition))
                {
                    direction = Move.Right;
                }
                else if (compass.Down(game.MyPosition))
                {
                    direction = Move.Down;
                }
                else if (compass.Left(game.MyPosition))
                {
                    direction = Move.Left;
                }

            }
            return direction;
        }