Beispiel #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");
            }
        }
Beispiel #2
0
        public bool TileInDirectionIsFree(int row, int col, MoveDirection direction)
        {
            int newRow = row + MoveUtil.GetRowMoveAmountByColor(Piece.Owner, direction);
            int newCol = col + MoveUtil.GetColMoveAmount(direction);

            return(CheckerBoard.TileIsInBounds(newRow, newCol) &&
                   Board.GetPiece(newRow, newCol) == null
                   );
        }
Beispiel #3
0
        public bool TileCanBeJumpedInDirection(int row, int col, MoveDirection direction)
        {
            int jumpRow = row + MoveUtil.GetRowMoveAmountByColor(Piece.Owner, direction);
            int jumpCol = col + MoveUtil.GetColMoveAmount(direction);

            return(CheckerBoard.TileIsInBounds(jumpRow, jumpCol) &&
                   TileInDirectionIsFree(jumpRow, jumpCol, direction) &&
                   Board.TileIsOpposingColor(jumpRow, jumpCol, OpposingColor)
                   );
        }
Beispiel #4
0
        private void GenerateJumpsForDirection(int row, int col, HashSet <Tile> capturedTiles, List <MoveDirection> directions, List <Move> moves, MoveDirection direction)
        {
            var forwardLeftTile   = GetTileFromDirection(row, col, direction);
            var tempCapturedTiles = new HashSet <Tile>(capturedTiles);

            tempCapturedTiles.Add(forwardLeftTile);
            var moveDirections = new List <MoveDirection>(directions);

            moveDirections.Add(direction);

            // Get the movement amount and then multiply by two since a jump moves
            // twice as far.
            int newRow = row + 2 * MoveUtil.GetRowMoveAmountByColor(Piece.Owner, direction);
            int newCol = col + 2 * MoveUtil.GetColMoveAmount(direction);

            if (PieceCanJump(newRow, newCol))
            {
                GenerateJumps(newRow, newCol, tempCapturedTiles, moveDirections, moves);
            }
            else
            {
                moves.Add(new Move(Piece, moveDirections));
            }
        }
Beispiel #5
0
 private Tile GetTileFromDirection(int row, int col, MoveDirection direction)
 {
     return(Tile.FromRowCol(
                row + MoveUtil.GetRowMoveAmountByColor(Piece.Owner, MoveDirection.ForwardLeft),
                col + MoveUtil.GetColMoveAmount(MoveDirection.ForwardLeft)));
 }