Exemplo n.º 1
0
        private ValidBoardMove DetermineAllCellsOnPath(Cell fromCell, Cell toCell, ValidBoardMove.MovePath path)
        {
            var move = new ValidBoardMove(fromCell.Coordinates, toCell.Coordinates, path, isWhite);

            move.MoveProperties.IsValid = true;
            return(move);
        }
Exemplo n.º 2
0
 private void FilterMoves(ValidBoardMove checkingMove)
 {
     if (checkingMove != null)
     {
         this.FilterMovesIfChecked(checkingMove);
     }
     if (this.PinnedMoves.Count > 0)
     {
         this.FilterMovesIfPinned();
     }
 }
Exemplo n.º 3
0
 public override void DetermineValidMoves(string coords, ValidBoardMove checkingMove)
 {
     if (!this.ValidMovesSet)
     {
         ValidMoves         = new List <ValidBoardMove>();
         PiecePressure      = new List <ValidBoardMove>();
         this.ValidMovesSet = true;
         this.AddToValidMoves(coords);
         this.FilterMoves(checkingMove);
     }
     else
     {
         this.FilterMoves(checkingMove);
     }
 }
Exemplo n.º 4
0
        public List <ValidBoardMove> FindPiecesBetween(ValidBoardMove move)
        {
            var cell  = this.getCell(move.CoordinatesFrom);
            var moves = new List <ValidBoardMove>();

            switch (move.Path)
            {
            case ValidBoardMove.MovePath.Down:
                moves = ExecuteFunctionOnCellsDown(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.Up:
                moves = ExecuteFunctionOnCellsUp(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.Right:
                moves = ExecuteFunctionOnCellsToRight(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.Left:
                moves = ExecuteFunctionOnCellsToLeft(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.DownLeft:
                moves = ExecuteFunctionOnCellsDownLeft(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.DownRight:
                moves = ExecuteFunctionOnCellsDownRight(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.UpLeft:
                moves = ExecuteFunctionOnCellsUpLeft(cell, DetermineAllCellsOnPath);
                break;

            case ValidBoardMove.MovePath.UpRight:
                moves = ExecuteFunctionOnCellsUpRight(cell, DetermineAllCellsOnPath);
                break;

            default:
                break;
            }

            moves.Add(move);

            return(moves);
        }
Exemplo n.º 5
0
        public ValidBoardMove DetermineIfCellValid(Cell fromCell, Cell toCell, ValidBoardMove.MovePath path)
        {
            ValidNotationProperties validMoveProps = this.CellIsValid(fromCell, toCell);
            var move = new ValidBoardMove(fromCell.Coordinates, toCell.Coordinates, path, this.isWhite);

            if (validMoveProps.IsValid || validMoveProps.IsProtected)
            {
                this.PiecePressure.Add(move);
            }
            if (validMoveProps.IsPotentiallyPinned)
            {
                this.startingCell = fromCell;
                this.PinnedCell   = toCell;
                DetermineIfAbsolutePinned(toCell, path);
            }
            move.MoveProperties = validMoveProps;
            return(move);
        }
Exemplo n.º 6
0
        public List <ValidBoardMove> FindAttackPath(ValidBoardMove boardPath)
        {
            var returnList = new List <ValidBoardMove>();

            switch (boardPath.Path)
            {
            case ValidBoardMove.MovePath.Down:
                returnList = GetValidCellsUp(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.Up:
                returnList = GetValidCellsDown(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.Left:
                returnList = GetValidCellsDownRight(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.Right:
                returnList = GetValidCellsLeft(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.UpLeft:
                returnList = GetValidCellsDownRight(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.UpRight:
                returnList = GetValidCellsDownLeft(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.DownLeft:
                returnList = GetValidCellsUpRight(boardPath.CoordinatesTo);
                break;

            case ValidBoardMove.MovePath.DownRight:
                returnList = GetValidCellsUpLeft(boardPath.CoordinatesTo);
                break;

            default:
                break;
            }
            return(returnList.Where(move => MovesAreBetweenCheckMovePath(move, boardPath)).ToList());
        }
Exemplo n.º 7
0
        public void FilterMovesIfChecked(ValidBoardMove checkingMove)
        {
            if (checkingMove != null)
            {
                this.AllowedCellsAfterCheck = FindAttackPath(checkingMove);
            }
            else
            {
                this.AllowedCellsAfterCheck = new List <ValidBoardMove>();
            }

            if (this.AllowedCellsAfterCheck.Count > 0 &&
                checkingMove.IsWhite != this.isWhite)
            {
                var filteredCoordinateList = this.ValidMoves.Select(GeneralUtilities.SelectCoordinates)
                                             .Intersect(this.AllowedCellsAfterCheck.Select(GeneralUtilities.SelectCoordinates)).ToList();

                this.ValidMoves = this.ValidMoves.Where(x => filteredCoordinateList.IndexOf(x.CoordinatesTo) > -1).ToList();
            }
        }
Exemplo n.º 8
0
        private bool MovesAreBetweenCheckMovePath(ValidBoardMove move, ValidBoardMove checkMove)
        {
            var checkCoordsTo             = checkMove.CoordinatesTo;
            var checkCoordsToColumnLetter = checkCoordsTo.GetColumnLetter();
            var checkCoordsToRowNumber    = checkCoordsTo.GetRowNumber();

            var checkCoordsFrom             = checkMove.CoordinatesFrom;
            var checkCoordsFromColumnLetter = checkCoordsFrom.GetColumnLetter();
            var checkCoordsFromRowNumber    = checkCoordsFrom.GetRowNumber();

            var moveCoordsTo     = move.CoordinatesTo;
            var moveColumnLetter = moveCoordsTo.GetColumnLetter();
            var moveRowNumber    = moveCoordsTo.GetRowNumber();

            if (moveColumnLetter.IsBetween <char?>(checkCoordsFromColumnLetter, checkCoordsToColumnLetter) &&
                moveRowNumber.IsBetween <char?>(checkCoordsFromRowNumber, checkCoordsToRowNumber))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public override void AddToValidMoves(string coords)
        {
            var currentCell = this.getCell(coords);

            var twoColumnsLeft  = GetColumnLetter(currentCell, -2);
            var oneColumnLeft   = GetColumnLetter(currentCell, -1);
            var oneColumnRight  = GetColumnLetter(currentCell, 1);
            var twoColumnsRight = GetColumnLetter(currentCell, 2);

            //8 moves knight can make
            var twoUpOneLeftCell    = this.getCell(oneColumnLeft.ToString() + (currentCell.Row + 2));
            var twoUpOneRightCell   = this.getCell(oneColumnRight.ToString() + (currentCell.Row + 2));
            var oneUpTwoRightCell   = this.getCell(twoColumnsRight.ToString() + (currentCell.Row + 1));
            var oneDownTwoRightCell = this.getCell(twoColumnsRight.ToString() + (currentCell.Row - 1));
            var twoDownOneRightCell = this.getCell(oneColumnRight.ToString() + (currentCell.Row - 2));
            var twoDownOneLeftCell  = this.getCell(oneColumnLeft.ToString() + (currentCell.Row - 2));
            var oneDownTwoLeftCell  = this.getCell(twoColumnsLeft.ToString() + (currentCell.Row - 1));
            var oneUpTwoLeftCell    = this.getCell(twoColumnsLeft.ToString() + (currentCell.Row + 1));


            if (CellIsValid(currentCell, twoUpOneLeftCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, twoUpOneLeftCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, twoUpOneRightCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, twoUpOneRightCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, oneUpTwoRightCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, oneUpTwoRightCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, oneDownTwoRightCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, oneDownTwoRightCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, twoDownOneRightCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, twoDownOneRightCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, twoDownOneLeftCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, twoDownOneLeftCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, oneDownTwoLeftCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, oneDownTwoLeftCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
            if (CellIsValid(currentCell, oneUpTwoLeftCell).IsValid)
            {
                var moveProperty = new ValidBoardMove(coords, oneUpTwoLeftCell.Coordinates, ValidBoardMove.MovePath.KnightMove, this.isWhite);
                this.ValidMoves.Add(moveProperty);
            }
        }
Exemplo n.º 10
0
 public static string SelectCoordinates(ValidBoardMove arg)
 {
     return(arg.CoordinatesTo);
 }
Exemplo n.º 11
0
 public abstract void DetermineValidMoves(string coords, ValidBoardMove checkingMove);
Exemplo n.º 12
0
        public override void AddToValidMoves(string coords)
        {
            var kingCell = getCell(coords);

            var oneLeftCell  = getCell(GetColumnLetter(kingCell, -1) + kingCell.Row.ToString());
            var oneRightCell = getCell(GetColumnLetter(kingCell, +1) + kingCell.Row.ToString());

            var twoLeftCell  = getCell(GetColumnLetter(kingCell, -2) + kingCell.Row.ToString());
            var twoRightCell = getCell(GetColumnLetter(kingCell, +2) + kingCell.Row.ToString());

            var oneUpCell   = getCell(kingCell.ColumnLetter + (kingCell.Row + 1).ToString());
            var oneDownCell = getCell(kingCell.ColumnLetter + (kingCell.Row - 1).ToString());

            var oneUoneLCell = getCell(GetColumnLetter(kingCell, -1) + (kingCell.Row + 1).ToString());
            var oneUoneRCell = getCell(GetColumnLetter(kingCell, 1) + (kingCell.Row + 1).ToString());
            var oneDoneLCell = getCell(GetColumnLetter(kingCell, -1) + (kingCell.Row - 1).ToString());
            var oneDoneRCell = getCell(GetColumnLetter(kingCell, 1) + (kingCell.Row - 1).ToString());

            //castling moves, maybe break out into their own function?
            if (CellIsValidForKing(kingCell, oneLeftCell, enemyPressure) &&
                CellIsValidForKing(kingCell, twoLeftCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, twoLeftCell.Coordinates, ValidBoardMove.MovePath.Castle, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(twoLeftCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }

            if (CellIsValidForKing(kingCell, oneRightCell, enemyPressure) &&
                CellIsValidForKing(kingCell, twoRightCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, twoRightCell.Coordinates, ValidBoardMove.MovePath.Castle, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(twoRightCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }


            if (CellIsValidForKing(kingCell, oneLeftCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneLeftCell.Coordinates, ValidBoardMove.MovePath.Left, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneLeftCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneRightCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneRightCell.Coordinates, ValidBoardMove.MovePath.Right, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneRightCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneUpCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneUpCell.Coordinates, ValidBoardMove.MovePath.Up, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneUpCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneDownCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneDownCell.Coordinates, ValidBoardMove.MovePath.Down, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneDownCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneUoneLCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneUoneLCell.Coordinates, ValidBoardMove.MovePath.UpLeft, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneUoneLCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneUoneRCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneUoneRCell.Coordinates, ValidBoardMove.MovePath.UpRight, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneUoneRCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneDoneLCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneDoneLCell.Coordinates, ValidBoardMove.MovePath.DownLeft, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneDoneLCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }
            if (CellIsValidForKing(kingCell, oneDoneRCell, enemyPressure))
            {
                var moveProperty = new ValidBoardMove(coords, oneDoneRCell.Coordinates, ValidBoardMove.MovePath.DownRight, this.isWhite);
                this.ValidMoves.Add(moveProperty);
                if (samePressure.Select(GeneralUtilities.SelectCoordinates).ToList().IndexOf(oneDoneRCell.Coordinates) == -1)
                {
                    samePressure.Add(moveProperty);
                }
            }

            this.CheckForCastleCells();
        }
Exemplo n.º 13
0
        public List <ValidBoardMove> DetermineValidMoves(string coords, List <ValidBoardMove> enemyPressure, List <ValidBoardMove> samePressure, ValidBoardMove checkingMove)
        {
            this.ValidMoves    = new List <ValidBoardMove>();
            PiecePressure      = new List <ValidBoardMove>();
            this.enemyPressure = enemyPressure;
            this.samePressure  = samePressure;

            this.AddToValidMoves(coords);
            this.FilterMovesIfChecked(checkingMove);
            return(samePressure);
        }
Exemplo n.º 14
0
 public override void DetermineValidMoves(string coords, ValidBoardMove checkingMove)
 {
     return;
 }