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); }
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); }