Пример #1
0
        public void MakeMove(Move move)
        {
            if (IsValidMove(move))
            {
                _board.RemovePiece(move.Piece);
                int newRow = move.Piece.Row;
                int newCol = move.Piece.Col;
                foreach (MoveDirection direction in move.Direction)
                {
                    newRow += MoveUtil.GetRowMoveAmountByColor(move.Piece.Owner, direction);
                    newCol += MoveUtil.GetColMoveAmount(direction);

                    CheckerPiece pieceInPosition = _board.GetPiece(newRow, newCol);
                    if (pieceInPosition != null)
                    {
                        _board.RemovePiece(pieceInPosition);
                        newRow += MoveUtil.GetRowMoveAmountByColor(move.Piece.Owner, direction);
                        newCol += MoveUtil.GetColMoveAmount(direction);
                    }
                }

                var pieceAfterMove = new CheckerPiece(move.Piece);
                pieceAfterMove.Row = newRow;
                pieceAfterMove.Col = newCol;
                _board.AddPiece(pieceAfterMove);
            }
            else
            {
                throw new ArgumentException("Invalid Move");
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a deep copy
        /// of the current board
        /// flipped about the the x-axis.
        /// </summary>
        /// <returns></returns>
        public CheckerBoard FlipBoard()
        {
            var reversedBoard = new CheckerBoard();

            for (int i = 0; i < SIZE; i++)
            {
                int row = SIZE - i - 1;
                for (int j = 0; j < SIZE; j++)
                {
                    CheckerPiece pieceToCopy = boardState[row, j];
                    if (pieceToCopy != null)
                    {
                        reversedBoard.AddPiece(pieceToCopy.Owner, i, j);
                    }
                }
            }

            return(reversedBoard);
        }