Пример #1
0
        public AICommand BuildCommand(Unit unit)
        {
            var direction = AICommand.SerializeDirection(MapDirections.RandomDirection());

            return(new AICommand {
                Command = AICommand.Move, Unit = unit.Id, Dir = direction
            });
        }
        public AICommand BuildCommand(Unit unit)
        {
            if (!unit.HasPath)
            {
                PathFinder pF = new PathFinder(Map);

                if (unit.CarryingResource)
                {
                    unit.Path = pF.FindPath(unit.Location, (0, 0));

                    return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
                }
                else if (Map.IsResourceAdjacentTo(unit.Location))
                {
                    var direction = MapDirections.CardinalDirection(unit.Location, Map.ResourceLocationsNearest(unit.Location).First());

                    return(AICommand.BuildGatherCommand(unit, direction));
                }
                else if (!unit.AdjacentToResource(Map))
                {
                    if (Map.ResourceLocationsNearest(unit.Location).Count > 0)
                    {
                        Console.WriteLine(Map.ResourceLocationsNearest(unit.Location).First());
                        var location = Map.ResourceLocationsNearest(unit.Location).First();

                        unit.Path = pF.FindPath(unit.Location, location, 1);
                        Console.WriteLine("unit path is " + unit.Path);

                        return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
            }

            return(null);
        }
Пример #3
0
        public AICommand BuildCommand(Unit unit)
        {
            var direction    = AICommand.SerializeDirection(MapDirections.RandomDirection());
            var returnAction = new AICommand {
                Command = direction, Unit = unit.Id, Dir = direction
            };

            if (unit.IsScout)
            {
                returnAction = ScoutStrategy.GetStrategy(Map, unit);
            }

            if (unit.IsWorker)
            {
                returnAction = WorkerStrategy.GetStrategy(Map, unit);
            }

            if (unit.IsTank)
            {
                returnAction = TankStrategy.GetStrategy(Map, unit);
            }

            if (unit.IsBase)
            {
                returnAction = BaseStrategy.GetStrategy(Map, unit);
            }

            if (returnAction != null)
            {
                if (returnAction.Dir == "None")
                {
                    return(null);
                }
            }


            return(returnAction);
        }
        public AICommand BuildCommand(Unit unit)
        {
            if (isFirstMove)
            {
                isFirstMove = false;
                return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
            }
            else if (!unit.HasPath)
            {
                int Xincrementer = 2;
                int Yincrementer = 2;
                // var tileLocation = unit.Location;
                // tileLocation.X = tileLocation.X * incrementer;
                // tileLocation.Y = tileLocation.Y * incrementer;

                PathFinder pF = new PathFinder(Map);

                unit.Path = pF.FindPath(unit.Location, (unit.Location.X * Xincrementer, unit.Location.Y * Yincrementer));

                while (Yincrementer < 3 && !unit.HasPath)
                {
                    // tileLocation.X = tileLocation.X + 1;
                    // tileLocation.Y = tileLocation.Y + 1;
                    Yincrementer = Yincrementer + 1;
                    Xincrementer = Xincrementer + 1;

                    unit.Path = pF.FindPath(unit.Location, (unit.Location.X, unit.Location.Y * Yincrementer));
                }

                while (Xincrementer < 3 && !unit.HasPath)
                {
                    // tileLocation.X = tileLocation.X + 1;
                    // tileLocation.Y = tileLocation.Y + 1;
                    Yincrementer = Yincrementer + 1;
                    Xincrementer = Xincrementer + 1;

                    unit.Path = pF.FindPath(unit.Location, (unit.Location.X * Xincrementer, unit.Location.Y));
                }

                while (Xincrementer < 3 && Yincrementer < 5 && !unit.HasPath)
                {
                    // tileLocation.X = tileLocation.X + 1;
                    // tileLocation.Y = tileLocation.Y + 1;
                    Yincrementer = Yincrementer + 1;
                    Xincrementer = Xincrementer + 1;

                    unit.Path = pF.FindPath(unit.Location, (unit.Location.X * Xincrementer, unit.Location.Y * Yincrementer));
                }

                return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
            }
            else
            {
                return(AICommand.BuildMoveCommand(unit, unit.NextMove()));
            }


            // if (!unit.HasPath) {
            //     PathFinder pF = new PathFinder(Map);
            //     unit.Path = pF.FindPath(unit.Location, (1000, 1000));


            //     return AICommand.BuildMoveCommand(unit, unit.NextMove());
            // } else {
            //     return AICommand.BuildMoveCommand(unit, unit.NextMove());

            // }
        }