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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 private int GetNextColumnDiagonalIndex(DiagonalDirection diagonalDirection, int currentIndex)
 {
     if (diagonalDirection == DiagonalDirection.LeftTopToRightBottom)
     {
         return(currentIndex + 1);
     }
     else
     {
         return(currentIndex - 1);
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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 }");
        }
Пример #6
0
        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;
        }
Пример #7
0
        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;
        }
Пример #8
0
        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);
        }
Пример #9
0
    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]);
        }
    }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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;
            }
        }
Пример #14
0
        /// <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);
        }
Пример #15
0
 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;
 }
Пример #16
0
 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));
 }
Пример #18
0
        /// <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);
        }
Пример #19
0
        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);
        }
Пример #20
0
 /// <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]);
 }
Пример #21
0
        /// <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);
        }
Пример #22
0
        /// <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));
        }
Пример #23
0
        /// <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));
        }
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }