public static Vector3 GetScreenBorderPoint(this Camera camera, DiagonalDirection direction) { Vector3 position = Vector3.zero; Vector3 center = camera.GetWorldCenter(); float width = camera.GetWidth(); float height = camera.GetHeight(); switch (direction) { case DiagonalDirection.Topleft: position = new Vector3(center.x - width / 2, center.y + height / 2, camera.nearClipPlane); break; case DiagonalDirection.Topright: position = new Vector3(center.x + width / 2, center.y + height / 2, camera.nearClipPlane); break; case DiagonalDirection.Bottomleft: position = new Vector3(center.x - width / 2, center.y - height / 2, camera.nearClipPlane); break; case DiagonalDirection.Bottomright: position = new Vector3(center.x + width / 2, center.y - height / 2, camera.nearClipPlane); break; } return(position); }
/// <summary> /// Gets the direction where a step between the two tiles is heading /// </summary> /// <param name="startTile">Tile from where the step is heading</param> /// <param name="targetTile">target tile where the step is heading</param> /// <returns>the direction of the step</returns> public static DiagonalDirection GetStepDirection(TileCoordinate startTile, TileCoordinate targetTile) { DiagonalDirection direction = 0; direction = (startTile.Y < targetTile.Y) ? DiagonalDirection.North : DiagonalDirection.South; direction |= (startTile.X < targetTile.X) ? DiagonalDirection.East : DiagonalDirection.West; return(direction); }
private int GetNextColumnDiagonalIndex(DiagonalDirection diagonalDirection, int currentIndex) { if (diagonalDirection == DiagonalDirection.LeftTopToRightBottom) { return(currentIndex + 1); } else { return(currentIndex - 1); } }
static IList <Point> MakeDiagonal(DiagonalDirection direction) { List <Point> list = new List <Point> (3); int offset = (int)direction; for (int i = 0; i < 3; ++i) { int x = Math.Abs(offset - i); int y = i; list.Add(Point.Make(x, y)); } return(list); }
private static int getIteratorByDirectionEnum(DiagonalDirection direction) { switch (direction) { case DiagonalDirection.UpLeft: return(7); case DiagonalDirection.UpRight: return(9); case DiagonalDirection.DownLeft: return(-9); case DiagonalDirection.DownRight: return(-7); } throw new Exception($"getIteratorByDirectionEnum(): Invalid Direction { direction }"); }
public Diagonal(int columnIndex, int rowIndex, DiagonalDirection direction, IReadOnlyList <ICell> cells) : base(cells) { if (columnIndex < 0) { throw new ArgumentException("Column index cannot be less than zero.", "columnIndex"); } if (rowIndex < 0) { throw new ArgumentException("Row index cannot be less than zero.", "rowIndex"); } ColumnIndex = columnIndex; RowIndex = rowIndex; Direction = direction; }
public bool IsDiagonalSequenceCompletedOfSameShapeByDirection(DiagonalDirection diagonalDirection, Cell.TypeShape typeShape) { var columnIndex = (diagonalDirection == DiagonalDirection.LeftTopToRightBottom) ? 0 : (ColumnsLength - 1); for (int rowIndex = 0; rowIndex < RowsLength; rowIndex++) { var cell = GetCellByPosition(rowIndex, columnIndex); if (!cell.IsValidMarked(typeShape)) return false; columnIndex = GetNextColumnDiagonalIndex(diagonalDirection, columnIndex); } return true; }
public bool IsDiagonalSequenceCompletedOfSameShapeByDirection(DiagonalDirection diagonalDirection, Cell.TypeShape typeShape) { var columnIndex = (diagonalDirection == DiagonalDirection.LeftTopToRightBottom) ? 0 : (ColumnsLength - 1); for (int rowIndex = 0; rowIndex < RowsLength; rowIndex++) { var cell = GetCellByPosition(rowIndex, columnIndex); if (!cell.IsValidMarked(typeShape)) { return(false); } columnIndex = GetNextColumnDiagonalIndex(diagonalDirection, columnIndex); } return(true); }
public static IEnumerable <T> Diagonal <T>(this T[,] array, DiagonalDirection direction) { var rowLower = array.GetLowerBound(0); var rowUpper = array.GetUpperBound(0); var columnLower = array.GetLowerBound(1); var columnUpper = array.GetUpperBound(1); for (int row = rowLower, column = columnLower; row <= rowUpper && column <= columnUpper; row++, column++) { int realColumn = column; if (direction == DiagonalDirection.DownLeft) { realColumn = columnUpper - columnLower - column; } yield return(array[row, realColumn]); } }
public static Point[] GetDiagonalMovementArray(int distance, DiagonalDirection direction) { Point[] attack = new Point[distance]; int xPostion = 0; int yPosition = 0; for (int i = 0; i < distance; i++) { switch (direction) { case DiagonalDirection.FORWARD_LEFT: xPostion--; yPosition++; break; case DiagonalDirection.FORWARD_RIGHT: xPostion++; yPosition++; break; case DiagonalDirection.BACKWARD_LEFT: xPostion--; yPosition--; break; case DiagonalDirection.BACKWARD_RIGHT: xPostion++; yPosition--; break; default: break; } attack[i] = new Point(xPostion, yPosition); } return(attack); }
public static List <int> DiagonalList(List <List <int> > numberMatrix, DiagonalDirection diagonalDirection) { const int zeroIndexAdjustment = -1; const int zeroStartIndex = 0; int maxColumnIndex = numberMatrix.Count() + zeroIndexAdjustment; var listDiagonalValues = new List <int>(); for (int coordinate = zeroStartIndex; coordinate.IsLessThanOrEqual(maxColumnIndex); Increment(ref coordinate, 1)) { if (diagonalDirection == DiagonalDirection.TopToBottom) { listDiagonalValues.Add(numberMatrix[coordinate][coordinate]); } else { listDiagonalValues.Add(numberMatrix[maxColumnIndex - coordinate][coordinate]); } } return(listDiagonalValues); }
public static int CalculateSumOfDiagonal(DiagonalDirection direction) { int sumOfDiagonal = 0; if (matrixArray.GetLength(0) == matrixArray.GetLength(1)) { switch (direction) { case DiagonalDirection.Forwards: { //if these dimensions are equal, we know the matrix is square. Proceed with finding the sum of the diagonal //we can also use either dimenstion to loop through the array diagonal for (int i = 0; i < matrixArray.GetLength(0); i++) { sumOfDiagonal += matrixArray[i, i]; } break; } case DiagonalDirection.Backwards: { //if these dimensions are equal, we know the matrix is square. Proceed with finding the sum of the diagonal //we can also use either dimenstion to loop through the array diagonal for (int i = matrixArray.GetLength(0) - 1; i >= 0; i--) { sumOfDiagonal += matrixArray[i, i]; } break; } } } else { Console.WriteLine("Matrix not square, you're on your own. "); } return(sumOfDiagonal); }
public static void AddGlider(Map map, int x, int y, DiagonalDirection direction) { switch (direction) { case DiagonalDirection.UpLeft: map.AddLiveCell(x, y); map.AddLiveCell(x - 1, y - 1); map.AddLiveCell(x - 2, y - 1); map.AddLiveCell(x - 0, y - 2); map.AddLiveCell(x - 1, y - 2); break; case DiagonalDirection.UpRight: map.AddLiveCell(x, y); map.AddLiveCell(x + 1, y - 1); map.AddLiveCell(x + 2, y - 1); map.AddLiveCell(x + 0, y - 2); map.AddLiveCell(x + 1, y - 2); break; case DiagonalDirection.DownLeft: map.AddLiveCell(x, y); map.AddLiveCell(x - 1, y + 1); map.AddLiveCell(x - 2, y + 1); map.AddLiveCell(x - 0, y + 2); map.AddLiveCell(x - 1, y + 2); break; case DiagonalDirection.DownRight: map.AddLiveCell(x, y); map.AddLiveCell(x + 1, y + 1); map.AddLiveCell(x + 2, y + 1); map.AddLiveCell(x + 0, y + 2); map.AddLiveCell(x + 1, y + 2); break; } }
/// <summary> /// Returns a List of diagonal cell values in a designated diagonal /// </summary> /// <param name="row"></param> /// <returns></returns> public List <string> GetDiagonalValues(DiagonalDirection diagonal) { List <string> diagonalValues = new List <string>(); int count = 0; int row = 0; int column = 0; const int MAX_COUNT = 3; // Traverse diagonal and add values to list switch (diagonal) { case DiagonalDirection.UP: row = 2; do { diagonalValues.Add(_GRID[row, column]); row--; column++; count++; } while (count < MAX_COUNT); break; case DiagonalDirection.DOWN: row = 0; do { diagonalValues.Add(_GRID[row, column]); row++; column++; count++; } while (count < MAX_COUNT); break; } return(diagonalValues); }
public LittleSandwich(DiagonalDirection direction, int offset, int clue, int digit1 = 1, int digit2 = 9, bool opposite = false, DiagonalDisplay display = DiagonalDisplay.Default) : base(direction, offset, clue, opposite, display) { Digit1 = digit1; Digit2 = digit2; }
private int GetNextColumnDiagonalIndex(DiagonalDirection diagonalDirection, int currentIndex) { if (diagonalDirection == DiagonalDirection.LeftTopToRightBottom) return currentIndex + 1; else return currentIndex - 1; }
public static Vector3 GetWorldBorderPoint(this Camera camera, DiagonalDirection direction) { return(camera.GetScreenBorderPoint(direction)); }
/// <summary> /// calculates all possible locations to end after doing an attackmove. this is always 1 tile after for a normal checker, but for a king it checks for a blocking checker in the row and returns all coordinates 'til that point. /// </summary> /// <param name="checker">The checker which makes the move</param> /// <param name="enemyCheckerCoordinate">Coordinate of the enemy checker</param> /// <param name="direction">Direction the attackmove was heading</param> /// <returns>list of possible ending locations</returns> private IEnumerable <TileCoordinate> GetPossibleMovesInDirectionAfterAttack(IChecker checker, TileCoordinate enemyCheckerCoordinate, DiagonalDirection direction) { var moves = new List <TileCoordinate>(); if (checker.Type == CheckerType.King) { TileCoordinate lastCheckedTile = new TileCoordinate(enemyCheckerCoordinate.X, enemyCheckerCoordinate.Y); TileCoordinate nextCoordinate = TileCoordinate.CalculateLocationAfterSteps(lastCheckedTile, direction); while (nextCoordinate.IsValid()) //continues as long as the code hasnt reached a corner of the board, of until a attackmove is detected { var nextTile = this.First(t => t.Coordinate == nextCoordinate); if (nextTile.Checker != null) //theres a checker here, so check for a possibility of a attackmove. { break; //stop checking moves in this direction, since we found a checker. no need to check the further moves now. } else { moves.Add(nextCoordinate); } //update the nextcoordinate, which is needed for the next direction nextCoordinate = TileCoordinate.CalculateLocationAfterSteps(nextCoordinate, direction); } } else { moves.Add(TileCoordinate.CalculateLocationAfterSteps(enemyCheckerCoordinate, direction)); } return(moves); }
private bool CheckOriginPieces(List <BoardPosition> originPieces, List <BoardPosition> boardPositions, DiagonalDirection direction) { for (int i = 0; i < originPieces.Count; i++) { AddPossibleWinningPiece(originPieces[i]); bool winFound = true; for (int j = 1; j < 4; j++) { int newX = originPieces[i].XIndex + j; int newY = originPieces[i].YIndex; if (direction == DiagonalDirection.LeftToRight) { newY += j; } else { newY -= j; } BoardPosition piece = boardPositions.FirstOrDefault(x => x.XIndex == newX && x.YIndex == newY); if (piece == null) { winFound = false; } else { AddPossibleWinningPiece(piece); } } if (winFound) { return(true); } if (originPieces.Count > 0) { ResetWinningPositions(originPieces[i]); } } return(false); }
/// <summary> /// Gets the diagonal coord. /// </summary> /// <returns>The neighbor.</returns> /// <param name="direction">Direction to get.</param> public Coord Diagonal(DiagonalDirection direction) { return(this + DiagonalDirections[direction]); }
/// <summary> /// Checks each diagonal on board for a winning or losing diagonal, based on selected team (human / AI) /// </summary> /// <param name="diagonalDirection"></param> /// <param name="board"></param> /// <param name="team"></param> /// <returns></returns> public bool CheckDiagonal(DiagonalDirection diagonalDirection, Board board, string team) { // Variables bool isWin = false; int countWinCells = 0; const int START_ROW_UP = 2; // For UP diagonal const int FINISH_ROW_UP = 0; // For UP diagonal // Get list of diagonal values List <string> cellLineValues = board.GetDiagonalValues(diagonalDirection); // If the line contains one empty value if (cellLineValues.Contains("-")) { switch (diagonalDirection) { case DiagonalDirection.DOWN: // Check if remaining values match selected team for (int index = 0; index < cellLineValues.Count; index++) { if (cellLineValues[index] == team) { countWinCells++; } // Assign possible playable cell if (cellLineValues[index] == "-") { _PlayCell = string.Format("{0}{1}", index, index); } } break; case DiagonalDirection.UP: // Check if remaining values match AI player's team for (int index = 0; index < cellLineValues.Count; index++) { if (cellLineValues[index] == team) { countWinCells++; } // Assign possible playable cell if (cellLineValues[index] == "-") { if (index == 0) { _PlayCell = string.Format("{0}{1}", START_ROW_UP, index); } else if (index == 1) { _PlayCell = string.Format("{0}{1}", index, index); } else { _PlayCell = string.Format("{0}{1}", FINISH_ROW_UP, index); } } } break; } // Check if win / loss if (countWinCells == 2) { isWin = true; } } return(isWin); }
/// <summary> /// Gets the corner coordinate for a king to move /// </summary> /// <param name="coordinate"></param> /// <param name="direction"></param> /// <returns></returns> public static TileCoordinate GetNearestDiagonalEdgeCoordinate(TileCoordinate currentCoordinate, DiagonalDirection direction) { //north= y+ south= y- east = x+ west = x- int x = (direction.HasFlag(DiagonalDirection.East)) ? MAX_X - currentCoordinate.X : MAX_X - (MAX_X - currentCoordinate.X); int y = (direction.HasFlag(DiagonalDirection.North)) ? MAX_Y - currentCoordinate.X : MAX_Y - (MAX_Y - currentCoordinate.Y); int steps = Math.Min(x, y); int newx = (direction.HasFlag(DiagonalDirection.East)) ? currentCoordinate.X + steps : currentCoordinate.X - steps; int newy = (direction.HasFlag(DiagonalDirection.North)) ? currentCoordinate.Y + steps : currentCoordinate.Y - steps; return(new TileCoordinate(newx, newy)); }
/// <summary> /// /// </summary> /// <param name="startingCoordinate">The coordinate where you want to calculate steps from</param> /// <param name="direction">direction where the step is heading</param> /// <param name="tiles">amount of steps to take. defaults on 1</param> /// <returns>the ending coordinate</returns> public static TileCoordinate CalculateLocationAfterSteps(TileCoordinate startingCoordinate, DiagonalDirection direction, int tiles = 1) { var newX = startingCoordinate.X; var newY = startingCoordinate.Y; newX += direction.HasFlag(DiagonalDirection.East) ? tiles : -tiles; newY += direction.HasFlag(DiagonalDirection.North) ? tiles : -tiles; return(new TileCoordinate(newX, newY)); }
private static List <int> getEntireDiagonalLine(DiagonalDirection direction, int position) { var list = new List <int> { position }; var increment = 0; var currentPosition = position; switch (direction) { case DiagonalDirection.UpLeft: if (position % 8 == 0) { return(list); } if (position > 56) { return(list); } increment = 7; while (currentPosition <= 63) { currentPosition = currentPosition + increment; if (currentPosition <= 63) { list.Add(currentPosition); } if (currentPosition % 8 == 0) { break; } } break; case DiagonalDirection.UpRight: if (File.Contains(position)) { return(list); } if (position > 56) { return(list); } increment = 9; while (currentPosition <= 63) { currentPosition = currentPosition + increment; if (currentPosition <= 63) { list.Add(currentPosition); } if (File.Contains(currentPosition)) { break; } } break; case DiagonalDirection.DownLeft: if (position % 8 == 0) { return(list); } if (position < 7) { return(list); } increment = -9; while (currentPosition >= 0) { currentPosition = currentPosition + increment; if (currentPosition >= 0) { list.Add(currentPosition); } if (currentPosition % 8 == 0) { break; } } break; case DiagonalDirection.DownRight: if (File.Contains(position)) { return(list); } if (position < 7) { return(list); } increment = -7; while (currentPosition >= 0) { currentPosition = currentPosition + increment; if (currentPosition >= 0) { list.Add(currentPosition); } if (File.Contains(currentPosition)) { break; } } break; case DiagonalDirection.Invalid: default: break; } return(list); }
public static List <AttackedSquare> GetDiagonalLine(GameState gameState, Square square, Piece attackingPiece, DiagonalDirection direction) { var attacks = new List <AttackedSquare>(); var diagonalLine = getIteratorByDirectionEnum(direction); var position = square.Index; var attackPosition = square.Index; do { if (!canDoDiagonalsFromStartPosition(position, diagonalLine)) { break; } attackPosition = attackPosition + diagonalLine; var moveViability = GeneralEngine.DetermineMoveViability(gameState, attackingPiece, attackPosition); //I don't think either of these conditions should occur. if (!moveViability.IsValidCoordinate || moveViability.SquareToAdd == null) { continue; } var attack = new AttackedSquare(square, moveViability.SquareToAdd, isProtecting: moveViability.IsTeamPiece); attacks.Add(attack); if (moveViability.SquareToAdd.Occupied) { break; } } while (isValidDiagonalCoordinate(attackPosition)); return(attacks); }