Exemple #1
0
        public List<CoordinateInterface> get2DAdjecentCoordinates(CoordinateInterface coordinate)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            int currentPosition = coordinate.getPosition();
            int row = getRow(currentPosition);
            stopwatch.Stop();
            long time = stopwatch.ElapsedMilliseconds;

            Stopwatch stopwatch2 = Stopwatch.StartNew();
            List<CoordinateInterface> adjecentCoordinates = new List<CoordinateInterface>();
            int[] possibleAdjacenciesOnRowAbove = {
                                         currentPosition - xSize,
                                         getMovementUp(),
                                         currentPosition - xSize};
            int[] possibleAdjacenciesOnSameRow = {
                                         currentPosition - 1,
                                         currentPosition + 1};
            int[] possibleAdjacenciesOnRowBelow = {
                                         currentPosition + xSize,
                                         currentPosition + xSize,
                                         currentPosition + xSize};
            stopwatch2.Stop();
            long time2 = stopwatch2.ElapsedMilliseconds;

            Stopwatch stopwatch3 = Stopwatch.StartNew();
            checkAndAddValidCoordinatesInSameColumn(row - 1, possibleAdjacenciesOnRowAbove, adjecentCoordinates);
            checkAndAddValidCoordinatesOnSameRow(row, possibleAdjacenciesOnSameRow, adjecentCoordinates);
            checkAndAddValidCoordinatesInSameColumn(row + 1, possibleAdjacenciesOnRowBelow, adjecentCoordinates);
            stopwatch3.Stop();
            long time3 = stopwatch3.ElapsedMilliseconds;

            if (time > 1 || time2 > 2 || time3 > 3)
            {
                long timex = time; //DUMMY
            }
            return adjecentCoordinates;
        }
Exemple #2
0
 private void get2DRepresentation(CoordinateInterface coordinate, int xSize, int ySize, out int xPos, out int yPos)
 {
     int pos = coordinate.getPosition();
     xPos = getColumn(pos, xSize);
     yPos = getRow(pos, xSize);
 }
Exemple #3
0
 private bool isPositionAdjecent(CoordinateInterface coordinate, int newCoordinatePos)
 {
     try
     {
         CoordinateInterface newCoordinate = getCoordinateAtPosition(newCoordinatePos);
         List<CoordinateInterface> coordinates = get2DAdjecentCoordinates(coordinate);
         return coordinates.Contains(newCoordinate);
     }
     catch (CoordinateNotInWorldException)
     {
         return false;
     }
 }
Exemple #4
0
 public bool isEqual(CoordinateInterface otherCoordinate)
 {
     return otherCoordinate.getPosition() == position;
 }