Exemple #1
0
        public Paths PathsFrom(BoardLocation location, int forPlayer)
        {
            var paths     = new Paths();
            var playerIdx = (Colours)forPlayer;

            foreach (var dest in new[]
            {
                location.MoveForward(playerIdx),
                location.MoveForward(playerIdx)?.MoveRight(playerIdx),
                location.MoveRight(playerIdx),
                location.MoveBack(playerIdx)?.MoveRight(playerIdx),
                location.MoveBack(playerIdx),
                location.MoveBack(playerIdx)?.MoveLeft(playerIdx),
                location.MoveLeft(playerIdx),
                location.MoveLeft(playerIdx)?.MoveForward(playerIdx)
            })
            {
                if (dest != null)
                {
                    paths.Add(new Path {
                        BoardMove.Create(location, dest, (int)ChessMoveTypes.KingMove)
                    });
                }
            }

            return(paths);
        }
Exemple #2
0
        public Paths PathsFrom(BoardLocation location, int forPlayer)
        {
            var playerIdx = (Colours)forPlayer;

            Guard.ArgumentException(
                () => location.Y == (forPlayer == 0 ? 8 : 1),
                $"{ChessPieceName.Pawn} is invalid at {location}.");

            var paths = new Paths();

            var takeTypes = new List <int> {
                (int)DefaultActions.TakeOnly
            };

            if (location.Y == Pieces.Pawn.EnPassantRankFor(playerIdx))
            {
                takeTypes.Add((int)ChessMoveTypes.TakeEnPassant);
            }


            for (int i = 0; i < 2; i++)
            {
                var takeLocation = i == 0
                    ? location.MoveForward(playerIdx).MoveLeft(playerIdx)
                    : location.MoveForward(playerIdx).MoveRight(playerIdx);

                if (takeLocation == null)
                {
                    continue;
                }

                if (takeLocation.Y != ChessGame.EndRankFor(playerIdx))
                {
                    foreach (var takeType in takeTypes)
                    {
                        var move = BoardMove.Create(location, takeLocation, takeType);
                        paths.Add(new Path {
                            move
                        });
                    }
                }
                else
                {
                    foreach (var promotionPieces in new[] { ChessPieceName.Queen, ChessPieceName.Rook, ChessPieceName.Bishop, ChessPieceName.Knight })
                    {
                        var move = new BoardMove(location, takeLocation,
                                                 (int)DefaultActions.UpdatePieceWithTake, new ChessPieceEntityFactory.ChessPieceEntityFactoryTypeExtraData
                        {
                            Owner     = playerIdx,
                            PieceName = promotionPieces
                        });
                        paths.Add(new Path {
                            move
                        });
                    }
                }
            }
            return(paths);
        }
        public Paths PathsFrom(BoardLocation location, int forPlayer)
        {
            var paths = new Paths();

            var playerIdx        = (Colours)forPlayer;
            var oneSquareForward = location.MoveForward(playerIdx);

            if (oneSquareForward.Y != ChessGame.EndRankFor(playerIdx))
            {
                var move = new BoardMove(location, oneSquareForward, (int)DefaultActions.MoveOnly);

                var path = new Path {
                    move
                };
                if (location.Y == Pieces.Pawn.StartRankFor(playerIdx))
                {
                    BoardLocation to = location.MoveForward(playerIdx, 2);
                    path.Add(new BoardMove(location, to, (int)ChessMoveTypes.PawnTwoStep));
                }
                paths.Add(path);
            }
            else
            {
                foreach (var promotionPieces in new[] { ChessPieceName.Queen, ChessPieceName.Rook, ChessPieceName.Bishop, ChessPieceName.Knight })
                {
                    var move = new BoardMove(location, oneSquareForward, (int)DefaultActions.UpdatePiece, new ChessPieceEntityFactory.ChessPieceEntityFactoryTypeExtraData
                    {
                        Owner     = playerIdx,
                        PieceName = promotionPieces
                    });
                    paths.Add(new Path {
                        move
                    });
                }
            }


            return(paths);
        }
 public static BoardLocation KnightVerticalMove(this BoardLocation location, Colours colour, bool forward, bool right)
 => location.MoveForward(colour, forward ? 2 : -2)?.MoveRight(colour, right ? 1 : -1);