コード例 #1
0
        public Paths PathsFrom(BoardLocation location, int forPlayer)
        {
            var paths = new Paths();

            var playerIdx = (Colours)forPlayer;

            foreach (var dest in new[]
            {
                location.KnightVerticalMove(playerIdx, true, true),
                location.KnightVerticalMove(playerIdx, true, false),
                location.KnightVerticalMove(playerIdx, false, true),
                location.KnightVerticalMove(playerIdx, false, false),

                location.KnightHorizontalMove(playerIdx, true, true),
                location.KnightHorizontalMove(playerIdx, true, false),
                location.KnightHorizontalMove(playerIdx, false, true),
                location.KnightHorizontalMove(playerIdx, false, false),
            })
            {
                if (dest != null)
                {
                    paths.Add(new Path {
                        BoardMove.Create(location, dest, (int)DefaultActions.MoveOrTake)
                    });
                }
            }

            return(paths);
        }
コード例 #2
0
        public void ShouldParseFromBoardMove(string @from, string to, DefaultActions moveType, string expectedSan)
        {
            var game = ChessFactory.NewChessGame();
            var move = BoardMove.Create(from.ToBoardLocation(), to.ToBoardLocation(), (int)moveType);

            Assert.That(StandardAlgebraicNotation.ParseFromGameMove(game.BoardState, move).ToNotation(), Is.EqualTo(expectedSan));
        }
コード例 #3
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);
        }
コード例 #4
0
        public Paths PathsFrom(BoardLocation location, int forPlayer)
        {
            var paths = new Paths();

            var playerIdx = (Colours)forPlayer;

            foreach (var dest in new[]
            {
                location.MoveRight(playerIdx, 2),
                location.MoveLeft(playerIdx, 2),
            })
            {
                if (dest != null)
                {
                    var side = dest.X > location.X
                            ? ChessMoveTypes.CastleKingSide
                            : ChessMoveTypes.CastleQueenSide;

                    paths.Add(new Path {
                        BoardMove.Create(location, dest, (int)side)
                    });
                }
            }

            return(paths);
        }
コード例 #5
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 void Should_return_false_for_move_to_own_piece()
        {
            var move = BoardMove.Create(BoardLocation.At(1, 1), BoardLocation.At(5, 1), (int)DefaultActions.MoveOnly);

            SetupFromEntity(move, new TestBoardEntity());
            SetupToEntity(move, new TestBoardEntity());
            _validator.ValidateMove(move, RoBoardStateMock.Object).ShouldBeFalse();
        }
        public void Should_return_true_for_move_to_enemy_piece()
        {
            var move = BoardMove.Create(BoardLocation.At(1, 1), BoardLocation.At(1, 8), (int)DefaultActions.MoveOrTake);

            SetupFromEntity(move, new TestBoardEntity());
            SetupToEntity(move, new TestBoardEntity(Enemy));
            _validator.ValidateMove(move, RoBoardStateMock.Object).ShouldBeTrue();
        }
コード例 #8
0
        public void Should_return_true_for_move_to_empty_space()
        {
            var move = BoardMove.Create(BoardLocation.At(5, 1), BoardLocation.At(5, 2), (int)ChessMoveTypes.CastleKingSide);

            SetupToEntity(move);

            _validator.ValidateMove(move, RoBoardStateMock.Object).ShouldBeTrue();
        }
コード例 #9
0
        public void Should_return_true_for_square_under_no_attack()
        {
            var move = BoardMove.Create(BoardLocation.At(5, 1), BoardLocation.At(5, 2), (int)DefaultActions.MoveOrTake);

            SetupFromEntity(move, new TestBoardEntity());
            SetupGetNonOwnerEntitiesReturnsNone();

            _validator.ValidateMove(move, RoBoardStateMock.Object).ShouldBeTrue();
        }
コード例 #10
0
        public void Should_return_false_when_destination_is_empty()
        {
            var move = BoardMove.Create(BoardLocation.At(5, 8), BoardLocation.At(7, 8),
                                        (int)DefaultActions.MoveOrTake);

            SetupFromEntity(move, new TestBoardEntity());
            SetupToEntity(move);

            _validator.ValidateMove(move, RoBoardStateMock.Object).ShouldBeFalse();
        }
コード例 #11
0
        public void Regression_Kings_cant_move_next_to_each_other_black()
        {
            var board = new ChessBoardBuilder()
                        .Board("  K k   " +
                               "        " +
                               "        " +
                               "        " +
                               "        " +
                               "        " +
                               "        " +
                               "        "
                               );

            var boardState = ChessFactory.CustomChessGame(board.ToGameSetup(), Colours.Black).BoardState;

            var from = "e8".ToBoardLocation();
            var to   = "d8".ToBoardLocation();
            var move = BoardMove.Create(from, to, (int)ChessMoveTypes.KingMove);
            var item = boardState.GetItem(from);

            Assert.False(item.Paths.ContainsMoveTo(to), "kings cannot move next to each other");
        }