public override List <Move> calculateKingCastles(List <Move> playerLegalMoves, List <Move> opponentLegalMoves) { List <Move> kingCastles = new List <Move>(); if (this.playerKing.isFirstMove() && this.isInCheck() == false) { //Check for black king side castle if (!this.board.getCell(5).isCellOccupied() && !this.board.getCell(6).isCellOccupied()) { Cell rookCell = this.board.getCell(7); if (rookCell.isCellOccupied() && rookCell.getPiece().isFirstMove()) { if (Player.calculateAttacksCells(5, opponentLegalMoves).Any() == false && Player.calculateAttacksCells(6, opponentLegalMoves).Any() == false && rookCell.getPiece().isRook()) { kingCastles.Add(new KingSideCastleMove(this.board, this.playerKing, 6, (Rook)rookCell.getPiece(), rookCell.getCellCoordinate(), 5)); } } } //Check for white queen side castle if (!this.board.getCell(1).isCellOccupied() && !this.board.getCell(2).isCellOccupied() && !this.board.getCell(3).isCellOccupied()) { Cell rookCell = this.board.getCell(0); if (rookCell.isCellOccupied() && rookCell.getPiece().isFirstMove()) { if (Player.calculateAttacksCells(3, opponentLegalMoves).Any() == false && Player.calculateAttacksCells(2, opponentLegalMoves).Any() == false && rookCell.getPiece().isRook()) { kingCastles.Add(new QueenSideCastleMove(this.board, this.playerKing, 2, (Rook)rookCell.getPiece(), rookCell.getCellCoordinate(), 3)); } } } } return(kingCastles); }
public override List <Move> getLegalMoves(Board board) { List <Move> legalMoves = new List <Move>(); foreach (int argument in Knight.legalMoveArguments) { int unCheckedPosition = this.piecePosition + argument; if (!BoardUtils.checkedForLegalPosition(unCheckedPosition) || Knight.firstColumnViolation(this.piecePosition, argument) || Knight.secondColumnViolation(this.piecePosition, argument) || Knight.seventhColumnViolation(this.piecePosition, argument) || Knight.eightColumnViolation(this.piecePosition, argument)) { continue; } else { Cell currentCell = board.getCell(unCheckedPosition); if (!currentCell.isCellOccupied()) { legalMoves.Add(new NormalMove(board, this, unCheckedPosition)); } else { if (this.pieceSide != currentCell.getPiece().getSide()) { legalMoves.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece())); } } } } return(legalMoves); }
public override List <Move> getLegalMoves(Board board) { List <Move> legalMove = new List <Move>(); foreach (int argument in King.legalMoveArguments) { int unCheckedPosition = this.piecePosition + argument; if (!BoardUtils.checkedForLegalPosition(unCheckedPosition) || King.firstColumnViolation(this.piecePosition, argument) || King.eightColumnViolation(this.piecePosition, argument)) { continue; } else { Cell currentCell = board.getCell(unCheckedPosition); if (!currentCell.isCellOccupied()) { legalMove.Add(new NormalMove(board, this, unCheckedPosition)); } else { if (this.pieceSide != currentCell.getPiece().getSide()) { legalMove.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece())); } } } } if (board.CurrentPlayer != null) { List <Move> currentPlayerMove = board.CurrentPlayer.getLegalMoves(); List <Move> opponentPlayerMove = board.CurrentPlayer.getOpponent().getLegalMoves(); legalMove.AddRange(board.CurrentPlayer.calculateKingCastles(currentPlayerMove, opponentPlayerMove)); } return(legalMove); }
public override List <Move> getLegalMoves(Board board) { List <Move> legalMoves = new List <Move>(); foreach (int argument in Bishop.legalMovesArguments) { int unCheckedPosition = this.piecePosition; while (BoardUtils.checkedForLegalPosition(unCheckedPosition)) { if (firstColumnViolation(unCheckedPosition, argument) || eightColumnViolation(unCheckedPosition, argument)) { break; } unCheckedPosition += argument; if (BoardUtils.checkedForLegalPosition(unCheckedPosition)) { Cell currentCell = board.getCell(unCheckedPosition); if (!currentCell.isCellOccupied()) { legalMoves.Add(new NormalMove(board, this, unCheckedPosition)); } else { if (this.pieceSide != currentCell.getPiece().getSide()) { legalMoves.Add(new AttackMove(board, this, unCheckedPosition, currentCell.getPiece())); } break; } } } } return(legalMoves); }