Exemplo n.º 1
0
 public ValidBoardMove(string coordinatesFrom, string coordinatesTo, MovePath movepath, bool isWhite) : this(coordinatesFrom, coordinatesTo, movepath)
 {
     this.IsWhite         = isWhite;
     this.CoordinatesTo   = coordinatesTo;
     this.CoordinatesFrom = coordinatesFrom;
     this.Path            = movepath;
     this.IsPinningMove   = false;
     this.MoveProperties  = new ValidNotationProperties();
 }
            public void CheckPawnCaptureMoves()
            {
                var columnFrom       = this.potentialMove.AlgebraicCoord[captureIndex - 1];
                var columnDifference = Math.Abs(lastTwoLetters[0] - columnFrom);

                if (columnDifference != 1)
                {
                    return;
                }
                if (int.TryParse(lastTwoLetters[1].ToString(), out int rowTo))
                {
                    Cell potentialCellFrom;
                    if (this.potentialMove.IsWhitesTurn)
                    {
                        potentialCellFrom = this.board.GetCell(columnFrom.ToString() + (rowTo - 1).ToString());
                    }
                    else
                    {
                        potentialCellFrom = this.board.GetCell(columnFrom.ToString() + (rowTo + 1).ToString());
                    }

                    this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(potentialCellFrom, this.potentialMove.CellTo);
                    if (this.validMoveProperties.IsValid)
                    {
                        var           piece           = Cell.GetPiece(potentialCellFrom);
                        List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                        if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                        {
                            this.potentialMove.CellFrom = potentialCellFrom;
                            this.potentialMove.IsValid  = true;
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }
            public void CheckForNonCapturePawnMoves()
            {
                if (this.potentialMove.IsWhitesTurn)
                {
                    if (lastTwoLetters[1] == '4')
                    {
                        var whiteInitialCell = this.board.GetCell(lastTwoLetters[0] + '2'.ToString());

                        this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(whiteInitialCell, this.potentialMove.CellTo);

                        if (this.validMoveProperties.IsValid)
                        {
                            var piece = Cell.GetPiece(whiteInitialCell);
                            if (piece != null)
                            {
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = whiteInitialCell;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }

                        var whiteOneRow = this.board.GetCell(lastTwoLetters[0] + '3'.ToString());
                        this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(whiteOneRow, this.potentialMove.CellTo);
                        if (this.validMoveProperties.IsValid)
                        {
                            var piece = Cell.GetPiece(whiteOneRow);
                            if (piece != null)
                            {
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = whiteOneRow;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (int.TryParse(lastTwoLetters[1].ToString(), out int rowNum))
                        {
                            var potentialCellFrom = this.board.GetCell(lastTwoLetters[0] + (rowNum - 1).ToString());
                            this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(potentialCellFrom, this.potentialMove.CellTo);
                            if (this.validMoveProperties.IsValid)
                            {
                                var           piece           = Cell.GetPiece(potentialCellFrom);
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = potentialCellFrom;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            this.potentialMove.IsValid = false;
                            return;
                        }
                    }
                }
                else
                {
                    if (lastTwoLetters[1] == '5')
                    {
                        var blackInitialCell = this.board.GetCell(lastTwoLetters[0] + '7'.ToString());

                        this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(blackInitialCell, this.potentialMove.CellTo);
                        if (this.validMoveProperties.IsValid)
                        {
                            var piece = Cell.GetPiece(blackInitialCell);
                            if (piece != null)
                            {
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = blackInitialCell;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }

                        var blackOneRow = this.board.GetCell(lastTwoLetters[0] + '6'.ToString());
                        this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(blackOneRow, this.potentialMove.CellTo);
                        if (this.validMoveProperties.IsValid)
                        {
                            var piece = Cell.GetPiece(blackOneRow);
                            if (piece != null)
                            {
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = blackOneRow;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (int.TryParse(lastTwoLetters[1].ToString(), out int rowNum))
                        {
                            var potentialCellFrom = this.board.GetCell(lastTwoLetters[0] + (rowNum + 1).ToString());
                            this.validMoveProperties = this.validMoveProperties.DetermineMovePropertiesForPawn(potentialCellFrom, this.potentialMove.CellTo);
                            if (this.validMoveProperties.IsValid)
                            {
                                var           piece           = Cell.GetPiece(potentialCellFrom);
                                List <string> validMoveCoords = piece.ValidMoves.Select(GeneralUtilities.SelectCoordinates).ToList();
                                if (validMoveCoords.IndexOf(this.potentialMove.CellTo.Coordinates) > -1)
                                {
                                    this.potentialMove.CellFrom = potentialCellFrom;
                                    this.potentialMove.IsValid  = true;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            this.potentialMove.IsValid = false;
                            return;
                        }
                    }
                }
            }
 public AlgebraicNotationParser(ChessBoard b)
 {
     this.board = b;
     this.validMoveProperties = new ValidNotationProperties();
 }
Exemplo n.º 5
0
 public ValidBoardMove(string coordinatesFrom, string coordinatesTo, MovePath movepath, bool isWhite, bool pinningMove) : this(coordinatesFrom, coordinatesTo, movepath, isWhite)
 {
     //TODO : add to Valid
     this.IsPinningMove  = pinningMove;
     this.MoveProperties = new ValidNotationProperties(true);
 }