Exemplo n.º 1
0
        private static int SwitchTouchFunctionNoTouchAllowed(ETouchingEdge cellPosition, ECellState[,] board, int i, int j)
        {
            switch (cellPosition)
            {
            case ETouchingEdge.UpperLeft:
                return(CountTouches(new[] { board[i, j + 1], board[i + 1, j], board[i + 1, j + 1] }));

            case ETouchingEdge.Upper:
                return(CountTouches(new[]
                                    { board[i, j - 1], board[i, j + 1], board[i + 1, j - 1], board[i, j + 1], board[i + 1, j + 1] }));

            case ETouchingEdge.UpperRight:
                return(CountTouches(new[] { board[i, j - 1], board[i + 1, j - 1], board[i + 1, j] }));

            case ETouchingEdge.Left:
                return(CountTouches(new[]
                                    { board[i - 1, j], board[i - 1, j + 1], board[i, j + 1], board[i + 1, j], board[i + 1, j + 1] }));

            case ETouchingEdge.Right:
                return(CountTouches(new[]
                                    { board[i - 1, j], board[i - 1, j - 1], board[i, j - 1], board[i + 1, j - 1], board[i + 1, j] }));

            case ETouchingEdge.LowerLeft:
                return(CountTouches(new[] { board[i - 1, j], board[i - 1, j + 1], board[i, j + 1] }));

            case ETouchingEdge.LowerRight:
                return(CountTouches(new[] { board[i - 1, j], board[i - 1, j - 1], board[i, j - 1] }));

            case ETouchingEdge.Lower:
                return(CountTouches(new[]
                                    { board[i - 1, j - 1], board[i - 1, j], board[i - 1, j + 1], board[i, j - 1], board[i, j + 1] }));

            case ETouchingEdge.Middle:
                return(CountTouches(new[]
                {
                    board[i - 1, j - 1], board[i - 1, j], board[i - 1, j + 1], board[i, j - 1], board[i, j + 1],
                    board[i + 1, j - 1], board[i + 1, j], board[i + 1, j + 1]
                }));
            }

            return(5);
        }
Exemplo n.º 2
0
        private static int SwitchTouchFunctionCornersTouchAllowedFirstCell(ETouchingEdge cellPosition,
                                                                           ECellState[,] board, int i, int j)
        {
            switch (cellPosition)
            {
            // Check all touching sides besides corners> these all have to return zero for first cell! corners may touch
            case ETouchingEdge.UpperLeft:
                return(CountTouches(new[] { board[i, j + 1], board[i + 1, j] }));

            case ETouchingEdge.Upper:
                return(CountTouches(new[] { board[i, j - 1], board[i, j + 1], board[i + 1, j] }));

            case ETouchingEdge.UpperRight:
                return(CountTouches(new[] { board[i, j - 1], board[i + 1, j] }));

            case ETouchingEdge.Left:
                return(CountTouches(new[] { board[i - 1, j], board[i, j + 1], board[i + 1, j] }));

            case ETouchingEdge.Right:
                return(CountTouches(new[] { board[i - 1, j], board[i, j - 1], board[i + 1, j] }));

            case ETouchingEdge.LowerLeft:
                return(CountTouches(new[] { board[i - 1, j], board[i, j + 1] }));

            case ETouchingEdge.LowerRight:
                return(CountTouches(new[] { board[i - 1, j], board[i, j - 1] }));

            case ETouchingEdge.Lower:
                return(CountTouches(new[] { board[i - 1, j], board[i, j - 1], board[i, j + 1] }));

            case ETouchingEdge.Middle:
                return(CountTouches(new[]
                {
                    board[i - 1, j], board[i, j - 1], board[i, j + 1],
                    board[i + 1, j]
                }));
            }

            return(5);
        }