public static bool AddIfCoordinateIsEmpty(this List <GameMove> list, Chessboard chessboard, Coordinate from, int i, int j)
        {
            if (!chessboard.IsCoordinateEmpty(i, j))
            {
                return(false);
            }

            list.Add(new GameMove {
                From = from, To = Chessboard.GetCoordinate(i, j)
            });
            return(true);
        }
예제 #2
0
        public List <GameMove> GetPawnForwardMoves(Chessboard chessboard, Coordinate fromCoordinate, ChessColor pawnColor)
        {
            var pawnForwardMoves = new List <GameMove>();

            fromCoordinate.ToArrayIndexes(out var fromI, out var fromJ);
            var direction = pawnColor == ChessColor.White ? MoveDirection.Upwards : MoveDirection.Down;

            var toI = fromI;
            var toJ = fromJ;

            MoveValidatorExtensions.Move(direction, ref toI, ref toJ);

            var forwardMove = new GameMove
            {
                From = fromCoordinate,
                To   = Chessboard.GetCoordinate(toI, toJ)
            };

            switch (fromI)
            {
            case 1 when pawnColor == ChessColor.White:
            case 6 when pawnColor == ChessColor.Black:
            {
                if (!pawnForwardMoves.AddIfCoordinateIsEmpty(chessboard, forwardMove))
                {
                    return(pawnForwardMoves);
                }

                MoveValidatorExtensions.Move(direction, ref toI, ref toJ);
                pawnForwardMoves.AddIfCoordinateIsEmpty(chessboard, fromCoordinate, toI, toJ);

                return(pawnForwardMoves);
            }

            case 6 when pawnColor == ChessColor.White:
            case 1 when pawnColor == ChessColor.Black:
                pawnForwardMoves.AddMovesWithAllCastToOptions(forwardMove);

                return(pawnForwardMoves);

            default:
                pawnForwardMoves.Add(forwardMove);

                return(pawnForwardMoves);
            }
        }
        public static bool AddIfCoordinateIsValid(
            this List <GameMove> list,
            Chessboard chessboard,
            Coordinate from,
            ChessColor chessPieceColor,
            int i,
            int j)
        {
            if (!chessboard.IsCoordinateValid(chessPieceColor, i, j))
            {
                return(false);
            }

            list.Add(new GameMove {
                From = @from, To = Chessboard.GetCoordinate(i, j)
            });
            return(true);
        }
        public static void AddIfPawnKills(
            this List <GameMove> list,
            Chessboard chessboard,
            GameMove?previousMove,
            Coordinate from,
            ChessColor chessPieceColor,
            MoveDirection direction)
        {
            from.ToArrayIndexes(out var i, out var j);

            Move(direction, ref i, ref j);
            if (!Chessboard.IsCoordinateValid(i, j))
            {
                return;
            }

            if (!IsPawnKilling(chessboard, previousMove, chessPieceColor, i, j))
            {
                return;
            }

            var toCoordinate = Chessboard.GetCoordinate(i, j);

            if (chessPieceColor == ChessColor.White && toCoordinate.Number == 8 ||
                chessPieceColor == ChessColor.White && toCoordinate.Number == 1)
            {
                list.AddMovesWithAllCastToOptions(new GameMove {
                    From = from, To = toCoordinate
                });
            }
            else
            {
                list.Add(new GameMove {
                    From = from, To = toCoordinate
                });
            }
        }