//this may not need to be void however i dont yet know if or what the output will be (currently just counts) public void SweepSearch(StishMiniMaxNode Sibling, BoardState Now, Coordinate UnitPos, Player Side) { Coordinate Upper = new Coordinate(); Coordinate Lower = new Coordinate(); Coordinate Look = new Coordinate(); //upper refers to the upper left corner (lower coordinate values) //assigns full values to the bounds and then changes them if they are inappropriate Upper.X = UnitPos.X - StishBoard.Instance.GameMP; Upper.Y = UnitPos.Y - StishBoard.Instance.GameMP; Lower.X = UnitPos.X + StishBoard.Instance.GameMP; Lower.Y = UnitPos.Y + StishBoard.Instance.GameMP; //checks if the unit is losing movement positions because it is too close to the edge of the board if (UnitPos.X < StishBoard.Instance.GameMP) { Upper.X = 0; } if (UnitPos.X > Now.BoardSizeX - StishBoard.Instance.GameMP) { Lower.X = Now.BoardSizeX; } if (UnitPos.Y < StishBoard.Instance.GameMP) { Upper.Y = 0; } if (UnitPos.Y > Now.BoardSizeY - StishBoard.Instance.GameMP) { Lower.Y = Now.BoardSizeY; } for (uint y = Upper.Y; y <= Lower.Y; y++) { for (uint x = Upper.X; x <= Lower.X; x++) { Look.X = x; Look.Y = y; //stishboard.instance is okay here as this variable is global and is not dependant on a particular state if (UnitPos.Get2DDistance(Look) <= StishBoard.Instance.GameMP) { //general squares around unit within range if ((Now.getSquare(Look) != null) && !((Now.getSquare(Look).Owner) == Side && ((Now.getSquare(Look).Dep.DepType == "Unit") || (Now.getSquare(Look).Dep.DepType == "Base")))) { //the unit can legally move to any of these positions however the events of this action are not distinguished //obstructions are not accounted for List <Coordinate> Path = FindPath(UnitPos, Look, Now); if (Path != null) { UnitBasedMovement(Sibling, Now, Path, Side); } } } } } }
public uint ClosestDistance(Coordinate UnitPos, Player OpPlayer) { uint BestDistance = uint.MaxValue; Coordinate SearchPos = new Coordinate(); for (uint y = 0; y < this.BoardSizeY; y++) { for (uint x = 0; x < this.BoardSizeX; x++) { SearchPos.Y = y; SearchPos.X = x; if ((this.getSquare(SearchPos).Dep.OwnedBy == OpPlayer) && ((this.getSquare(SearchPos).Dep.DepType == "Barracks") || this.getSquare(SearchPos).Dep.DepType == "Base")) { if (UnitPos.Get2DDistance(SearchPos) < BestDistance) { BestDistance = (uint)UnitPos.Get2DDistance(SearchPos); } } } } return(BestDistance); }
//not void! returns a list of Pathnodes public List <Coordinate> FindPath(Coordinate UnitPos, Coordinate To, BoardState board) { //lists as we dont want a limit that would be given by an array List <Coordinate> Path = new List <Coordinate>(); List <PathNode> ToCheck = new List <PathNode>(); List <PathNode> Checked = new List <PathNode>(); Coordinate Invest = new Coordinate(); Coordinate Twitch = new Coordinate(); uint MoveCost; uint MoveHealth = board.getSquare(UnitPos).Dep.Health; Player Cont = board.getSquare(UnitPos).Dep.OwnedBy; //MoveHealth must remain above 0 and MoveCost must remain below the maximum unit move distance //Start at To and end at UnitPos Invest.X = To.X; Invest.Y = To.Y; MoveCost = 0; //has to be cast here as the parent has to be given as null //adds this node to the list ToCheck CreatePathNode(ToCheck, null, MoveCost, MoveHealth, board, Invest); //Spreading from Invest while (ToCheck.Count != 0) { for (int dir = 0; dir < 4; dir++) { Invest = ToCheck[0].Position; MoveCost = ToCheck[0].Cost; MoveHealth = ToCheck[0].Health; Twitch.X = Invest.X; Twitch.Y = Invest.Y; if (dir == 0) { //up Twitch.MoveUp(); } else if (dir == 1) { //right Twitch.MoveRight(); } else if (dir == 2) { //down Twitch.MoveDown(); } else if (dir == 3) { //left Twitch.MoveLeft(); } if (board.getSquare(Twitch) != null) { //the 2d distance this way around makes a lot of sense and is nicely restricting if (UnitPos.Get2DDistance(Twitch) <= StishBoard.Instance.GameMP) { //tests to see if twitch is ontop of a friendly deployment but gives an exception for the destination which is the moving unit if (((Twitch.X == UnitPos.X) && (Twitch.Y == UnitPos.Y)) || !(board.getSquare(Twitch).Owner == board.getSquare(UnitPos).Owner&& board.getSquare(Twitch).Dep.DepType != "Empty")) { Coordinate SolidPos = new Coordinate(Twitch); //make changes to Movecost and MoveHealth here //trained equals true if this node is suitable and lands at the destination List <Coordinate> Trained = TrainPath(board, UnitPos, SolidPos, MoveCost, MoveHealth, Cont, ToCheck, Checked, Path); if (Trained != null) { return(Trained); } } } } } Checked.Add(ToCheck[0]); ToCheck.Remove(ToCheck[0]); } //there is no connection return(null); }