当前位置: 首页>>代码示例>>C#>>正文


C# IBoard类代码示例

本文整理汇总了C#中IBoard的典型用法代码示例。如果您正苦于以下问题:C# IBoard类的具体用法?C# IBoard怎么用?C# IBoard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IBoard类属于命名空间,在下文中一共展示了IBoard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VlidateMove

        // TODO: Castling checking
        public void VlidateMove(IFigure figure, IBoard board, Move move)
        {
            Position from = move.From;
            Position to = move.To;

            bool condition = (
                ((from.Col + 1) == to.Col) ||
                ((from.Col - 1) == to.Col) ||
                ((from.Row + 1) == to.Row) ||
                ((from.Row - 1) == to.Row) ||
                (((from.Row + 1) == to.Row) && ((from.Col + 1) == to.Col)) ||
                (((from.Row - 1) == to.Row) && ((from.Col + 1) == to.Col)) ||
                (((from.Row - 1) == to.Row) && ((from.Col - 1) == to.Col)) ||
                (((from.Row + 1) == to.Row) && ((from.Col - 1) == to.Col))
                );

            if (condition)
            {
                return;
            }
            else
            {
                throw new InvalidOperationException("King cannot move this way!");
            }
        }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:26,代码来源:NormalKingMovement.cs

示例2: KingSurvivalEngine

 public KingSurvivalEngine(IRenderer renderer, IInputProvider inputProvider,IBoard board, IWinningConditions winningConditions)
 {
     this.renderer = renderer;
     this.provider = inputProvider;
     this.winningConditions = winningConditions;
     this.board = board;
 }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:7,代码来源:KingSurvivalEngine.cs

示例3: GetNextFigureMove

 public Move GetNextFigureMove(IPlayer player,IBoard board)
 {
     Console.Write("{0} is next ", player.Name);
     var command = Console.ReadLine();
     Move move = player.Move(command,board);
     return move;
 }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:7,代码来源:ConsoleInputProvider.cs

示例4: AddBoardToOutput

        protected void AddBoardToOutput(IBoard board, TagHelperOutput output, bool editable = false) {
            if (board == null) { throw new ArgumentNullException(nameof(board)); }
            if (output == null) { throw new ArgumentNullException(nameof(output)); }

            int counter = 0;
            output.Content.AppendEncoded($"{NewLine}{Indent}<table>{NewLine}");
            for (int row = 0; row < board.Size; row++) {

                output.Content.AppendEncoded($"{Indent}{Indent}<tr>{NewLine}");
                output.Content.AppendEncoded($"{Indent}{Indent}{Indent}");
                for (int col = 0; col < board.Size; col++) {
                    output.Content.AppendEncoded($"<td>");
                    if (!editable) {
                        output.Content.AppendEncoded($"{board[row, col]}");
                    }
                    else {
                        output.Content.AppendEncoded($"<input type=\"text\" value=\"{board[row,col]}\" name=\"board[{counter}]\" style=\"width:100%;\" maxlength=\"1\" />");
                    }
                    output.Content.AppendEncoded($"</td>");

                    counter++;
                }
                output.Content.AppendEncoded($"{NewLine}{Indent}{Indent}</tr>{NewLine}");
            }
            output.Content.AppendEncoded($"{Indent}</table>{NewLine}");
        }
开发者ID:sayedihashimi,项目名称:sudoku,代码行数:26,代码来源:SudokuBaseTagHelper.cs

示例5: Move

        public override Move Move(string command,IBoard board)
        {
            int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL

            int[] deltaColona = { +1, +1, -1, -1 };
            int indexOfChange = -1;

            if (command.Length != 3)
            {
                //TODO:Change the exception to custom exception
                throw new ArgumentOutOfRangeException("The command should contain three symbols");
            }

            switch (command)
            {
                case "adr":
                case "bdr":
                case "cdr":
                case "ddr":
                    { indexOfChange = 1; }
                    break;
                case "adl":
                case "bdl":
                case "cdl":
                case "ddl":
                    { indexOfChange = 2; }
                    break;
                default:
                    //TODO:change the exception to custom exception
                    throw new ArgumentOutOfRangeException("The command is not correct");
            }
            int pawnIndex = -1;
            switch (command[0])
            {
                case 'a':
                case 'A':
                    { pawnIndex = 0; }
                    break;
                case 'b':
                case 'B':
                    { pawnIndex = 1; }
                    break;
                case 'c':
                case 'C':
                    { pawnIndex = 2; }
                    break;
                case 'd':
                case 'D':
                    { pawnIndex = 3; }
                    break;
            }
            var fig = this.Figures;
            var oldPosition = board.GetFigurePosition(this.Figures[pawnIndex]);
            int pawnNewRow = oldPosition.Row + deltaRed[indexOfChange];
            int pawnNewColum = oldPosition.Col + deltaColona[indexOfChange];
            var newPosition = new Position(pawnNewRow, pawnNewColum);
            //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage);
               // this.Figures[pawnIndex].Position = newPosition;
            return new Move(oldPosition, newPosition);
        }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:60,代码来源:PawnPlayer.cs

示例6: PrintBoardBorder

        private void PrintBoardBorder(int startRow, int startCol, IBoard board)
        {
            Console.BackgroundColor = ConsoleColor.DarkBlue;

            int horizontalBoardSymbolTopRow = (Console.BufferWidth / 2) - ((board.Size / 2) * BoardCellSymbolsCount) - 2;
            int totalBoardCols = board.Size * Renderer.BoardCellSymbolsCount;
            var totalCols = totalBoardCols + (2 * Renderer.BorderSize);
            int startBoardCol = ((Console.BufferHeight / 2) - totalCols / 2) + (BoardCellSymbolsCount / 2) + Renderer.BorderSize;
            this.PrintBoardSide(startRow, startRow + Renderer.BorderSize, startCol, startCol + totalCols);
            this.PrintHorizontalSymbols(startBoardCol, totalBoardCols, horizontalBoardSymbolTopRow, board, Renderer.HorizontalBoardFirstSymbol);

            int horizontalBoardSymbolBottomRow = (Console.BufferWidth / 2) + ((board.Size / 2) * BoardCellSymbolsCount) + 1;
            var bottomStartRow = (Console.BufferHeight / 2) + (board.Size / 2 * Renderer.BoardCellSymbolsCount);
            this.PrintBoardSide(bottomStartRow, bottomStartRow + Renderer.BorderSize, startCol, startCol + totalCols);
            this.PrintHorizontalSymbols(startBoardCol, totalBoardCols, horizontalBoardSymbolBottomRow, board, Renderer.HorizontalBoardFirstSymbol);

            int totalBoardRows = board.Size * BoardCellSymbolsCount;
            int varticalBoardSymbolLeftCol = (Console.BufferHeight / 2) - ((board.Size / 2) * BoardCellSymbolsCount) - 2;
            var totalRows = (board.Size * Renderer.BoardCellSymbolsCount) + Renderer.BorderSize;
            int startBoardRow = ((Console.BufferHeight / 2) - totalCols / 2) + (BoardCellSymbolsCount / 2) + Renderer.BorderSize;
            this.PrintBoardSide(startRow, startRow + totalRows, startCol, startCol + Renderer.BorderSize);
            this.PrintVerticalSymbols(startBoardRow, totalBoardRows, varticalBoardSymbolLeftCol, board, Renderer.VerticalBoardFirstSymbol);

            var rigthBorderStartCol = Console.BufferWidth / 2 + (board.Size * Renderer.BoardCellSymbolsCount / 2);
            int varticalBoardSymbolRigthCol = (Console.BufferHeight / 2) + ((board.Size / 2) * BoardCellSymbolsCount) + 1;
            this.PrintBoardSide(startRow, startRow + totalRows, rigthBorderStartCol, rigthBorderStartCol + Renderer.BorderSize);
            this.PrintVerticalSymbols(startBoardRow, totalBoardRows, varticalBoardSymbolRigthCol, board, Renderer.VerticalBoardFirstSymbol);
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:28,代码来源:Renderer.cs

示例7: DrawBoard

        public void DrawBoard(IBoard board)
        {
            StringBuilder result = new StringBuilder();

            // Append the numbers row first
            for (int i = 0; i < board.NumbersRow.Length; i++)
            {
                result.AppendFormat("{0, -2}", board.NumbersRow[i]);
            }

            result.AppendLine();

            // Append the rest of the rows
            for (int row = 0; row < board.Gamefield.GetLength(0); row++)
            {
                for (int col = 0; col < board.Gamefield.GetLength(1); col++)
                {
                    result.AppendFormat("{0, -2}", board.Gamefield[row, col]);
                }

                result.AppendLine();
            }

            Console.WriteLine(result.ToString());
        }
开发者ID:dimipan,项目名称:BattleshipsGame,代码行数:25,代码来源:ConsoleRenderer.cs

示例8: Move

        public override Move Move(string command,IBoard board)
        {
            int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL

            int[] deltaColona = { +1, +1, -1, -1 };
            int indexOfChange = -1;

            if (command.Length != 3)
            {
                //TODO:change the exception to custom exception
                throw new ArgumentOutOfRangeException("The command should contain three symbols");
            }

            var oldPosition = board.GetFigurePosition(this.Figures[0]);

            switch (command)
            {
                case "kur": { indexOfChange = 0; } break;
                case "kdr": { indexOfChange = 1; } break;
                case "kdl": { indexOfChange = 2; } break;
                case "kul": { indexOfChange = 3; } break;
                default:
                    //TODO:change the exception to custom exception
                    throw new ArgumentOutOfRangeException("The command is not correct");

            }
            int newRow = oldPosition.Row + deltaRed[indexOfChange];
            int newColumn = oldPosition.Col + deltaColona[indexOfChange];
            var newPosition = new Position(newRow, newColumn);
            //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage);
              //  this.Figures[0].Position = newPosition;
            return new Move(oldPosition, newPosition);
        }
开发者ID:havaliova,项目名称:King-Survival-4,代码行数:33,代码来源:KingPlayer.cs

示例9: Move

 public void Move(char player, IBoard board)
 {
     var freeSpaces = board.GetFreeSpaces();
     Random rnd = new Random();
     int r = rnd.Next(freeSpaces.Length);
     board.SetSpace(player, (int)Char.GetNumericValue(freeSpaces[r]));
 }
开发者ID:gaterichard,项目名称:TicTacToe,代码行数:7,代码来源:RandomMoveStrategy.cs

示例10: CheckIfCheck

        private bool CheckIfCheck(IBoard gameBoard, Position kingPosition, IDictionary<Position, IFigure> defenderFigures)
        {
            var defenderFiguresPositions = defenderFigures.Keys;
            var counter = 0;

            foreach (var position in defenderFiguresPositions)
            {
                var figure = defenderFigures[position];
                var availableMovements = figure.Move(this.strategy);

                try
                {
                    var tryMove = new Move(position, kingPosition);
                    this.CheckValidMove(figure, availableMovements, tryMove);
                }
                catch (Exception ex)
                {
                    counter++;
                }
            }
            if (counter == defenderFigures.Count)
            {
                return false;
            }

            return true;
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:27,代码来源:ChessStandardGame.cs

示例11: ShapeI

        /// <summary>
        /// Initializes a new instance of the <see cref="ShapeI"/> class.
        /// </summary>
        /// <param name="board">The board being used.</param>
        public ShapeI(IBoard board)
            : base(board)
        {
            // Initialize blocks
            blocks = new Block[] {
                new Block (board, Color.Cyan),
                new Block (board, Color.Cyan),
                new Block (board, Color.Cyan),
                new Block (board, Color.Cyan)
            };

            // Set block positions
            setBlockPositions();

            // Set rotations
            rotationOffset = new Point[][]
            {
                new Point[] { new Point(-2, -2), new Point(2, 2) },
                new Point[] { new Point(-1, -1), new Point(1, 1) },
                new Point[] { new Point(0, 0), new Point(0, 0) },
                new Point[] { new Point(1, 1), new Point(-1, -1) }
            };

            // 0 = no rotation
            // 1 = 90 degree rotation counterclockwise
            currentRotation = 0;

            length = blocks.Length;
        }
开发者ID:jeegnathebug,项目名称:Tetris,代码行数:33,代码来源:ShapeI.cs

示例12: VlidateMove

        public void VlidateMove(IFigure figure, IBoard board, Move move)
        {
            Position from = move.From;
            Position to = move.To;

            if (from.Row != to.Row && from.Col != to.Col)
            {
                throw new InvalidOperationException("Rook cannot move this way!");
            }

            if (to.Col > from.Col)
            {
                this.RightChecker(board, from, to);
                return;
            }
            else if (to.Col < from.Col)
            {
                this.LeftChecker(board, from, to);
                return;
            }
            else if (to.Row > from.Row)
            {
                this.TopChecker(board, from, to);
                return;
            }
            else if (to.Row < from.Row)
            {
                this.DownChecker(board, from, to);
                return;
            }
            else
            {
                throw new InvalidOperationException("Rook cannot move this way!");
            }
        }
开发者ID:totkov,项目名称:ChessGameEngine,代码行数:35,代码来源:NormalRookMovement.cs

示例13: ClearEmptyCells

        /// <summary>
        /// Clears all empty cells and moves all balloons on the column to rows greater than their current one if there are vacant indexes.
        /// </summary>
        /// <param name="board">The board object of the game.</param>
        private void ClearEmptyCells(IBoard board)
        {
            int row;
            int col;

            Queue<IBalloon> baloonsToPop = new Queue<IBalloon>();
            for (col = board.Cols - 1; col >= 0; col--)
            {
                for (row = board.Rows - 1; row >= 0; row--)
                {
                    if (board[row, col] != Balloon.Default)
                    {
                        baloonsToPop.Enqueue(board[row, col]);
                        board[row, col] = Balloon.Default;
                    }
                }

                row = board.Rows - 1;
                while (baloonsToPop.Count > 0)
                {
                    board[row, col] = baloonsToPop.Dequeue();
                    row--;
                }

                baloonsToPop.Clear();
            }
        }
开发者ID:Baloons-Pop-2,项目名称:Balloons-Pop-2,代码行数:31,代码来源:TraversalEffect.cs

示例14: ValidateMove

        public void ValidateMove(IFigure figure, IBoard board, Move move)
        {
            var rowDistance = Math.Abs(move.From.Row - move.To.Row);
            var colDistance = Math.Abs(move.From.Col - move.To.Col);

            if (rowDistance != colDistance)
            {
                throw new InvalidOperationException(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
            }

            int rowDirection = move.From.Row > move.To.Row ? -1 : 1;
            int colDirection = move.From.Col > move.To.Col ? -1 : 1;

            var row = move.From.Row;
            var col = move.From.Col;

            var endRow = move.To.Row + (rowDirection * (-1));
            var endCol = move.To.Col + (colDirection * (-1));

            while (row != endRow && col != endCol)
            {
                row += rowDirection;
                col += colDirection;

                if (board.SeeFigureOnPosition(row, col) != null)
                {
                    throw new InvalidOperationException(string.Format(GlobalConstants.ExceptionMessege, figure.Type));
                }
            }

            base.ValidateMove(figure, board, move);
        }
开发者ID:zhenyaracheva,项目名称:Chess,代码行数:32,代码来源:BishopMovement.cs

示例15: AddFigureToBoard

        public void AddFigureToBoard(IPlayer firstPlayser, IPlayer secondPlayer, IBoard board, string fen)
        {
            var splitedFen = fen.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var index = 0;

            for (int row = splitedFen.Length - 1; row >= 0; row--)
            {
                var currentRow = this.MakeRow(splitedFen[row]);

                for (int col = 0; col < currentRow.Length; col++)
                {
                    if (currentRow[col] == Pown)
                    {
                        var pawn = new Pawn(secondPlayer.Color);
                        secondPlayer.AddFigure(pawn);
                        var position = new Position(index + 1, (char)(col + 'a'));
                        board.AddFigure(pawn, position);
                    }
                    else if (currentRow[col] == King)
                    {
                        var figureInstance = new King(firstPlayser.Color);
                        firstPlayser.AddFigure(figureInstance);
                        var position = new Position(index + 1, (char)(col + 'a'));
                        board.AddFigure(figureInstance, position);
                    }
                }

                index++;
            }
        }
开发者ID:King-Survival-3,项目名称:HQC-Teamwork-2015,代码行数:30,代码来源:KingSurvivalGameWebInitializationStrategy.cs


注:本文中的IBoard类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。