public ChessMove(PieceRank rank, PiecePlayer player, int horizontalLocationFrom, int verticalLocationFrom, int horizontalLocationTo, int verticalLocationTo, ChessSpecialMove specialMove) { Rank = rank; Player = player; From = new ChessBoardLocation(horizontalLocationFrom, verticalLocationFrom); To = new ChessBoardLocation(horizontalLocationTo, verticalLocationTo); SpecialMove = specialMove; }
private void GetPawnMoves(PiecePlayer player, List <ChessMove> moves, int column, int row) { ChessSpecialMove specialMove = ChessSpecialMove.None; if (player == PiecePlayer.White) { if (row == 1) { specialMove = ChessSpecialMove.Promotion; } if (IsOccupiedByOpponent(player, column, row - 1) == false) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column, row - 1, specialMove)); } if (row == 6 && IsEmpty(column, row - 1) == true && IsEmpty(column, row - 2) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column, row - 2)); } // Move only available for pawn if there is opponent piece: if (IsOccupiedByOpponent(player, column + 1, row - 1) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column + 1, row - 1, specialMove)); } if (IsOccupiedByOpponent(player, column - 1, row - 1) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column - 1, row - 1, specialMove)); } GetPawnMovesEnPassant(player, moves, column, row, -1, -1); GetPawnMovesEnPassant(player, moves, column, row, 1, -1); } else { if (row == 6) { specialMove = ChessSpecialMove.Promotion; } if (IsOccupiedByOpponent(player, column, row + 1) == false) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column, row + 1, specialMove)); } if (row == 1 && IsEmpty(column, row + 1) == true && IsEmpty(column, row + 2) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column, row + 2)); } // Move only available for pawn if there is opponent piece: if (IsOccupiedByOpponent(player, column + 1, row + 1) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column + 1, row + 1, specialMove)); } if (IsOccupiedByOpponent(player, column - 1, row + 1) == true) { moves.Add(new ChessMove(PieceRank.Pawn, player, column, row, column - 1, row + 1, specialMove)); } GetPawnMovesEnPassant(player, moves, column, row, -1, 1); GetPawnMovesEnPassant(player, moves, column, row, 1, 1); } }