public void RegionPositionTest() { // standart constructor var regionPos = new RegionPosition(0, 0); Assert.IsNotNull(regionPos); // Constructor RegionPosition out of a Position var position = new Position(0, 0); regionPos = new RegionPosition(position); Assert.IsNotNull(regionPos); // Constructor RegionPosition out of a PositionI var positionI = new PositionI(0, 0); regionPos = new RegionPosition(positionI); Assert.IsNotNull(regionPos); // Tests the + Operator var regionPos2 = new RegionPosition(1, 1); regionPos += regionPos2; Assert.AreEqual(regionPos2, regionPos); // Tests the == Operator Assert.True(regionPos == regionPos2); // Tests the Equals funktion Assert.True(regionPos.Equals(regionPos2)); }
/// <summary> /// Initializes a new instance of the <see cref="Core.Controllers.AStar.Node"/> class. /// It set the positionI of the Node, set the node state to open and calculate the travel cost to the destination tile. /// </summary> /// <param name="location">Current PositionI of the Node.</param> /// <param name="endLocation">PositionI of the destination tile.</param> public Node(PositionI location, PositionI endLocation) { Location = location; State = NodeState.Open; H = GetTraversalCost(Location, endLocation); G = 0; }
/// <summary> /// Initializes a new instance of the <see cref="Core.Controllers.AStar_Indicator.Indicator"/> class. /// </summary> /// <param name="startPosition">Start position.</param> /// <param name="moves">Moves of the entity.</param> /// <param name="accountID">Account ID.</param> public Indicator(PositionI startPosition, int moves, int accountID) { m_startPoint = startPosition; m_moves = moves; m_accountID = accountID; m_indicatorPoints = new HashSet <PositionI>(); }
/// <summary> /// Initializes a new instance of the <see cref="Core.Controllers.Actions.CreateUnit"/> class. /// </summary> /// <param name="model">action model.</param> public CreateUnit(Core.Models.ModelEntity model) : base(model) { var action = (Core.Models.Action)Model; var param = action.Parameters; if (param[CREATE_POSITION].GetType() != typeof(PositionI)) { param[CREATE_POSITION] = new PositionI((Newtonsoft.Json.Linq.JContainer)param[CREATE_POSITION]); } }
/// <summary> /// Check all possible spawn locations around a building. /// Check surrounding area around the building for units, if there is a free location this will be returned. /// </summary> /// <returns>The free field.</returns> /// <param name="position">IPosition of the current selected building..</param> /// <param name="regionManagerC">Region manager c.</param> private PositionI GetFreeField(PositionI position, RegionManagerController regionManagerC) { foreach (var surpos in LogicRules.GetSurroundedFields(position)) { var td = regionManagerC.GetRegion(surpos.RegionPosition).GetTerrain(surpos.CellPosition); var ed = regionManagerC.GetRegion(surpos.RegionPosition).GetEntity(surpos.CellPosition); if (td.Walkable && ed == null) { return(surpos); } } return(null); }
public void PositionITest() { // standart Constructor var position = new PositionI(0, 0); Assert.IsNotNull(position); // Constructor Position out of a ReagionPosition var regionPos = new RegionPosition(0, 0); var cellPos = new CellPosition(0, 0); position = new PositionI(regionPos, cellPos); Assert.IsNotNull(position); position = new PositionI(new Position(0, 0)); Assert.IsNotNull(position); // tests the + Operator position = new PositionI(1, 1); var position2 = new PositionI(0, 0); position2 += position; Assert.AreEqual(position, position2); // tests the - Operator position -= position2; Assert.AreNotEqual(position2, position); Assert.AreEqual(new PositionI(0, 0), position); // tests the == Operator Assert.True(new PositionI(0, 0) == position); // tests the Equals function Assert.True(position.Equals(new PositionI(0, 0))); // test Distance with PositionI var dist = position.Distance(position2); Assert.IsNotNull(dist); // test Distance with PositionI var dist2 = position2.Distance(new Position(0, 0)); Assert.IsNotNull(dist2); Assert.AreEqual(dist, dist2); }
public void CellPositionTest() { // standart constructor var cellPos = new CellPosition(0, 0); Assert.IsNotNull(cellPos); // Constructor CellPosition out of Position var position = new Position(0, 0); cellPos = new CellPosition(position); Assert.IsNotNull(cellPos); // Constructor CellPosition out of PositionI var positionI = new PositionI(0, 0); cellPos = new CellPosition(positionI); Assert.IsNotNull(cellPos); // Tests the == operator var cellPos2 = new CellPosition(0, 0); Assert.True(cellPos == cellPos2); // Tests the Equas function Assert.True(cellPos.Equals(cellPos2)); // Tests the != operator cellPos2 = new CellPosition(1, 1); Assert.True(cellPos != cellPos2); // Tests if its Posible to create a cell position bigger than 31 and smaller then 0 cellPos = new CellPosition(32, 32); Assert.AreNotEqual(32, cellPos.CellX); Assert.AreNotEqual(32, cellPos.CellY); cellPos = new CellPosition(-1, -1); Assert.AreNotEqual(-1, cellPos.CellX); Assert.AreNotEqual(-1, cellPos.CellY); }
/// <summary> /// Gets the surrounded positions. /// </summary> /// <returns>The surrounded positions.</returns> /// <param name="startPoint">Start point.</param> /// <param name="accountID">Account ID.</param> /// <param name="moves">Moves of the entity.</param> private HashSet <PositionI> GetSurroundedPositions(PositionI startPoint, int accountID, int moves) { var fieldSet = new HashSet <PositionI>(); var fieldSetHelper = new HashSet <PositionI>(); fieldSet.Add(startPoint); fieldSetHelper.Add(startPoint); for (int index = 0; index != moves; ++index) { var tempfieldSet = new HashSet <PositionI>(); foreach (var item in fieldSetHelper) { var surroundedTiles = LogicRules.GetSurroundedFields(item); foreach (var tile in surroundedTiles) { if (!fieldSet.Contains(tile)) { var region = World.Instance.RegionManager.GetRegion(tile.RegionPosition); var terrainDefinition = region.GetTerrain(tile.CellPosition); if (terrainDefinition.Walkable) { var unit = region.GetEntity(tile.CellPosition); if (unit == null) { fieldSet.Add(tile); tempfieldSet.Add(tile); } } } } } fieldSetHelper = tempfieldSet; } return(fieldSet); }
/// <summary> /// Gets the distance between two points. /// </summary> /// <returns>The traversal cost.</returns> /// <param name="location">Current PositionI</param> /// <param name="otherLocation">Other PositionI.</param> internal static double GetTraversalCost(PositionI location, PositionI otherLocation) { return(location.Distance(otherLocation)); }
/// <summary> /// Gets the adjacent regions, which can be affected. /// </summary> /// <returns>The adjacent regions.</returns> /// <param name="regionManagerC">Region manager c.</param> /// <param name="position">Current Position od the selected building.</param> /// <param name="buildpoint">PositionI from the new unit.</param> private ConcurrentBag <RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint) { var list = new ConcurrentBag <RegionPosition>(); var surlist = LogicRules.SurroundRegions; var regionSizeX = Constants.REGION_SIZE_X; var regionSizeY = Constants.REGION_SIZE_Y; if (buildpoint.CellPosition.CellX <= m_drawArea) { var tempReg = position + surlist[LogicRules.SurroundRegions.Length - 1]; if (regionManagerC.GetRegion(tempReg).Exist) { list.Add(tempReg); } for (int index = 0; index < 4; ++index) { tempReg = position + surlist[index]; if (regionManagerC.GetRegion(tempReg).Exist) { list.Add(tempReg); } } } else if (buildpoint.CellPosition.CellY <= m_drawArea) { for (int index = 5; index < LogicRules.SurroundRegions.Length; ++index) { var tempReg = position + surlist[index]; if (regionManagerC.GetRegion(tempReg).Exist) { list.Add(tempReg); } } var reg = position + surlist[0]; if (regionManagerC.GetRegion(reg).Exist) { list.Add(reg); } reg = position + surlist[1]; if (regionManagerC.GetRegion(reg).Exist) { list.Add(reg); } } else if (buildpoint.CellPosition.CellX >= regionSizeX - m_drawArea) { for (int index = 1; index < 6; ++index) { var tempReg = position + surlist[index]; if (regionManagerC.GetRegion(tempReg).Exist) { list.Add(tempReg); } } } else if (buildpoint.CellPosition.CellY >= regionSizeY - m_drawArea) { for (int index = 3; index < LogicRules.SurroundRegions.Length; ++index) { var tempReg = position + surlist[index]; if (regionManagerC.GetRegion(tempReg).Exist) { list.Add(tempReg); } } } return(list); }
/// <summary> /// Gets the adjacent regions, which can be affected. /// </summary> /// <returns>The adjacent regions.</returns> /// <param name="regionManagerC">Region manager c.</param> /// <param name="position">Current Position od the selected building.</param> /// <param name="buildpoint">PositionI from the new unit.</param> private ConcurrentBag <RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint) { var list = new ConcurrentBag <RegionPosition>(); var surlist = LogicRules.SurroundRegions; var regionSizeX = Constants.REGION_SIZE_X; var regionSizeY = Constants.REGION_SIZE_Y; var currentpos = LogicRules.GetSurroundedFields(buildpoint); var currentregion = regionManagerC.RegionManager.GetRegion(buildpoint.RegionPosition); foreach (var checkingpos in currentpos) { if (regionManagerC.GetRegion(checkingpos.RegionPosition) != currentregion) { list.Add(regionManagerC.RegionManager.GetRegion(checkingpos.RegionPosition).RegionPosition); } } return(list); }
/// <summary> /// Initializes a new instance of the <see cref="Core.Controllers.AStar.SearchParameters"/> class. /// Set start and end point for the AStar algorithm. /// </summary> /// <param name="startLocation">PositionI from the start for the algorithm.</param> /// <param name="endLocation">PositionI from the end for the algorithm.</param> /// <param name="accountID">Account ID.</param> public SearchParameters(PositionI startLocation, PositionI endLocation, int accountID) { this.StartLocation = startLocation; this.EndLocation = endLocation; this.AccountID = accountID; }